[Jifty-commit] r1632 - in jifty/branches/moose: . lib/Jifty/Script
lib/Jifty/Web/Form share/web/static/css share/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Jul 20 21:37:08 EDT 2006
Author: audreyt
Date: Thu Jul 20 21:32:45 2006
New Revision: 1632
Added:
jifty/branches/moose/lib/Jifty/Script/Deps.pm
jifty/branches/moose/share/web/static/js/css_browser_selector.js (contents, props changed)
Modified:
jifty/branches/moose/ (props changed)
jifty/branches/moose/Makefile.PL
jifty/branches/moose/lib/Jifty/Web.pm
jifty/branches/moose/lib/Jifty/Web/Form/Field.pm
jifty/branches/moose/share/web/static/css/forms.css
jifty/branches/moose/share/web/static/js/jifty.js
Log:
r16396 at T (orig r1612): audreyt | 2006-07-19 00:05:21 -0400
* 0th sketch at "jifty deps"
r16397 at T (orig r1613): audreyt | 2006-07-19 00:07:56 -0400
* Deps: yay it work snow
r16398 at T (orig r1614): audreyt | 2006-07-19 00:08:49 -0400
* be a bit lessnoisy
r16399 at T (orig r1615): audreyt | 2006-07-19 00:14:01 -0400
* try recurse=1
r16415 at T (orig r1616): jesse | 2006-07-19 00:17:03 -0400
r14175 at pinglin: jesse | 2006-07-19 00:16:44 -0400
* Auto-accept cpan's wisdom about prompts
r16418 at T (orig r1619): nelhage | 2006-07-19 16:57:34 -0400
Adding support for placeholders, grayed-out text in form fields that is written in with JS and vanishes on focus
r16419 at T (orig r1620): nelhage | 2006-07-19 16:58:34 -0400
textareas can have placeholders, too; Style them appropriately as well
r16420 at T (orig r1621): nelhage | 2006-07-19 17:07:58 -0400
Support multi-line placeholders
r16421 at T (orig r1622): nelhage | 2006-07-19 17:08:29 -0400
Add the class before we set the text, so that it appears grayed-out, rather than appearing and *then* graying out
r16422 at T (orig r1623): nelhage | 2006-07-19 17:10:01 -0400
I should get better at not checking in warnings.
r16423 at T (orig r1624): nelhage | 2006-07-19 17:41:51 -0400
Not submitting placeholder values when we submit forms or AJAX
r16439 at T (orig r1625): trs | 2006-07-20 13:08:32 -0400
r14590 at zot: tom | 2006-07-20 13:08:09 -0400
Don't fade autocomplete in and out, just show and hide it
r16440 at T (orig r1626): nelhage | 2006-07-20 13:21:48 -0400
Let's not blow up if we have placeholders on an input without a form
r16441 at T (orig r1627): trs | 2006-07-20 13:25:05 -0400
r14592 at zot: tom | 2006-07-20 13:24:52 -0400
Trailing commas are not good for JS in Safari
r16442 at T (orig r1628): trs | 2006-07-20 13:38:37 -0400
r14596 at zot: tom | 2006-07-20 13:38:27 -0400
Add a tooltip to the dismiss link and hide the dotted border
r16457 at T (orig r1629): nelhage | 2006-07-20 15:45:26 -0400
Upping JSON::Syck version dependency. 0.14 fixes escaping in single-quoted strings.
r16458 at T (orig r1630): nelhage | 2006-07-20 17:08:55 -0400
After autocomplete, trigger a validation.
r16459 at T (orig r1631): nelhage | 2006-07-20 20:45:32 -0400
Adding the CSS browser selector trick from http://rafael.adm.br/css_browser_selector/ to Jifty
Modified: jifty/branches/moose/Makefile.PL
==============================================================================
--- jifty/branches/moose/Makefile.PL (original)
+++ jifty/branches/moose/Makefile.PL Thu Jul 20 21:32:45 2006
@@ -66,11 +66,11 @@
if (can_cc()) {
# Always require the Syck bindings if a C compiler is available
requires('YAML::Syck' => 0.45);
- requires('JSON::Syck' => 0.13);
+ requires('JSON::Syck' => 0.14);
}
else {
requires('YAML' => 0.35) unless can_use('YAML::Syck' => 0.45);
- requires('JSON' => 0.01) unless can_use('JSON::Syck' => 0.13);
+ requires('JSON' => 0.01) unless can_use('JSON::Syck' => 0.14);
}
Added: jifty/branches/moose/lib/Jifty/Script/Deps.pm
==============================================================================
--- (empty file)
+++ jifty/branches/moose/lib/Jifty/Script/Deps.pm Thu Jul 20 21:32:45 2006
@@ -0,0 +1,119 @@
+use warnings;
+use strict;
+
+package Jifty::Script::Deps;
+use base qw/App::CLI::Command/;
+
+use Config;
+use File::Find::Rule;
+use Module::ScanDeps;
+use PAR::Dist::FromCPAN;
+use Pod::Usage;
+use version;
+use Jifty::Config;
+
+=head2 options
+
+Returns a hash of all the options this script takes. (See the usage message for details)
+
+=cut
+
+
+sub options {
+ return (
+ "setup" => "setup_deps",
+ "help|?" => "help",
+ );
+}
+
+=head2 run
+
+Prints a help message if the users want it. If not, goes about its
+business.
+
+Sets up the environment, checks current database state, creates or deletes
+a database as necessary and then creates or updates your models' schema.
+
+=cut
+
+sub run {
+ my $self = shift;
+ local $ENV{'PERL_MM_USE_DEFAULT'} = 1;
+ Jifty->new( no_handle => 1 );
+
+ my $root = Jifty::Util->app_root;
+ chdir $root;
+
+ # First let's find out our dependencies.
+ # I think we can cache the result in META.yml or something.
+
+ warn "Scanning for dependencies...\n";
+
+ my @files = _get_files_in(grep { -d } map { $_, "share/$_" } qw( lib html bin ));
+ my $map = scan_deps(
+ files => \@files,
+ recurse => 1,
+ );
+
+ my @mod;
+ foreach my $key (sort keys %$map) {
+ my $mod = $map->{$key};
+ next unless $mod->{type} eq 'module';
+ next if $mod->{file} eq "$Config::Config{privlib}/$key";
+ next if $mod->{file} eq "$Config::Config{archlib}/$key";
+ push @mod, _name($key);
+
+ warn "* $mod[-1]\n";
+ }
+
+ warn "Populating share/deps/...\n";
+
+ mkdir "share";
+ mkdir "share/deps";
+
+ my $pat = '/^(?:' . join('|', map { quotemeta($_) } @mod) . ')$/';
+
+ cpan_to_par(
+ pattern => $pat,
+ out => 'share/deps/',
+ follow => 1,
+ verbose => 0,
+ test => 0,
+ );
+}
+
+sub _name {
+ my $str = shift;
+ $str =~ s!/!::!g;
+ $str =~ s!.pm$!!i;
+ $str =~ s!^auto::(.+)::.*!$1!;
+ return $str;
+}
+
+sub _get_files_in {
+ my @dirs = @_;
+ my $rule = File::Find::Rule->new;
+ $rule->or($rule->new
+ ->directory
+ ->name('.svn')
+ ->prune
+ ->discard,
+ $rule->new
+ ->directory
+ ->name('CVS')
+ ->prune
+ ->discard,
+ $rule->new
+ ->name(qr/~$/)
+ ->discard,
+ $rule->new
+ ->name(qr/\.pod$/)
+ ->discard,
+ $rule->new
+ ->not($rule->new->file)
+ ->discard,
+ $rule->new);
+ return $rule->in(grep {-e $_} @dirs);
+}
+
+1;
Modified: jifty/branches/moose/lib/Jifty/Web.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web.pm Thu Jul 20 21:32:45 2006
@@ -66,6 +66,7 @@
yui/calendar.js
app.js
app_behaviour.js
+ css_browser_selector.js
)]);
=head1 METHODS
@@ -814,9 +815,14 @@
my $plural = $type . "s";
$self->out(qq{<div id="$plural">});
- $self->out(qq[<a id="dismiss_$plural" href="#"
- onclick="Effect.Fade(this.parentNode); return false;">]
- ._('Dismiss').qq[</a>]);
+
+ $self->out( qq[<a id="dismiss_$plural" href="#" title="]
+ . _('Dismiss')
+ .qq[" onmousedown="this.onfocus=this.blur;" onmouseup="this.onfocus=window.clientInformation?null:window.undefined" ]
+ .qq[ onclick="Effect.Fade(this.parentNode); return false;">]
+ . _('Dismiss')
+ .qq[</a>]);
+
foreach my $moniker ( keys %results ) {
if ( $results{$moniker}->$type() ) {
$self->out( qq{<div class="$type $moniker">}
Modified: jifty/branches/moose/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form/Field.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form/Field.pm Thu Jul 20 21:32:45 2006
@@ -27,6 +27,7 @@
has hints => qw( is rw isa Str );
has render_mode => qw( is rw isa Str default update );
has length => qw( is rw isa Str );
+has placeholder => qw( is rw isa Str );
has element_id => qw( is rw isa Str lazy 1 default ) => sub {
my $self = shift;
return $self->input_name."-".Jifty->web->serial;
@@ -266,6 +267,7 @@
if ($self->render_mode eq 'update') {
$self->render_widget();
$self->render_autocomplete();
+ $self->render_placeholder();
$self->render_key_binding();
$self->render_hints();
$self->render_errors();
@@ -461,6 +463,29 @@
}
+=head2 render_placeholder
+
+Renders the javascript necessary to insert a placeholder into this
+form field (greyed-out text that is written in using javascript, and
+vanishes when the user focuses the field). Returns an empty string.
+
+=cut
+
+sub render_placeholder {
+ my $self = shift;
+ return unless $self->placeholder;
+ my $placeholder = $self->placeholder;
+ $placeholder =~ s{(['\\])}{\\$1}g;
+ $placeholder =~ s{\n}{\\n}g;
+ $placeholder =~ s{\r}{\\r}g;
+ Jifty->web->out(
+qq!<script type="text/javascript">
+ new Jifty.Placeholder('@{[$self->element_id]}', '$placeholder');
+ </script>
+!
+ );
+}
+
=head2 render_hints
Renders any hints for using this input. Defaults to nothing, though
Modified: jifty/branches/moose/share/web/static/css/forms.css
==============================================================================
--- jifty/branches/moose/share/web/static/css/forms.css (original)
+++ jifty/branches/moose/share/web/static/css/forms.css Thu Jul 20 21:32:45 2006
@@ -139,3 +139,7 @@
.selected {
background: #dddddd;
}
+
+input.placeholder, textarea.placeholder {
+ color: #666;
+}
Added: jifty/branches/moose/share/web/static/js/css_browser_selector.js
==============================================================================
--- (empty file)
+++ jifty/branches/moose/share/web/static/js/css_browser_selector.js Thu Jul 20 21:32:45 2006
@@ -0,0 +1,15 @@
+// CSS Browser Selector v0.4
+// Documentation: http://rafael.adm.br/css_browser_selector
+// License: http://creativecommons.org/licenses/by/2.5/
+// Author: Rafael Lima (http://rafael.adm.br)
+// Contributors: http://rafael.adm.br/css_browser_selector#contributors
+function css_browser_selector() {
+ var ua = navigator.userAgent.toLowerCase();
+ var h = document.getElementsByTagName('html')[0];
+ if(ua.indexOf('msie') != -1 && !(ua.indexOf('opera') != -1) && (ua.indexOf('webtv') == -1) ) h.className='ie';
+ else if(ua.indexOf('gecko/') != -1) h.className='gecko';
+ else if(ua.indexOf('opera') != -1) h.className='opera';
+ else if(ua.indexOf('konqueror') != -1) h.className='konqueror';
+ else if(ua.indexOf('applewebkit/') != - 1) h.className='safari';
+}
+css_browser_selector();
\ No newline at end of file
Modified: jifty/branches/moose/share/web/static/js/jifty.js
==============================================================================
--- jifty/branches/moose/share/web/static/js/jifty.js (original)
+++ jifty/branches/moose/share/web/static/js/jifty.js Thu Jul 20 21:32:45 2006
@@ -114,7 +114,8 @@
var f = fields[i];
if ( (Form.Element.getType(f) != "registration")
- && (Form.Element.getValue(f) != null)) {
+ && (Form.Element.getValue(f) != null)
+ && (!Jifty.Placeholder.hasPlaceholder(f))) {
if (! a['fields'][Form.Element.getField(f)])
a['fields'][Form.Element.getField(f)] = {};
var field = Form.Element.getField(f);
@@ -235,6 +236,13 @@
}
return elements;
+ },
+
+ clearPlaceholders: function(element) {
+ var elements = Form.getElements(element);
+ for(var i = 0; i < elements.length; i++) {
+ Jifty.Placeholder.clearPlaceholder(elements[i]);
+ }
}
});
@@ -700,6 +708,8 @@
alert("Unable to connect to server.\n\nTry again in a few minutes.");
+ Jifty.failedRequest = transport;
+
var keys = request["actions"].keys();
for ( var i = 0; i < keys.length; i++ ) {
var a = new Action( request["actions"][ keys[i] ].moniker );
@@ -837,10 +847,25 @@
minChars: "0",
beforeShow: this.beforeShow,
beforeHide: this.beforeHide,
- frequency: 0.1
+ frequency: 0.1,
+ onShow: this.onShow,
+ onHide: this.onHide,
+ afterUpdateElement: this.afterUpdate
});
},
+ onShow: function(element, update) {
+ if(!update.style.position || update.style.position=='absolute') {
+ update.style.position = 'absolute';
+ Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight});
+ }
+ Element.show( update );
+ },
+
+ onHide: function(element, update) {
+ Element.hide( update );
+ },
+
beforeShow: function(obj) {
/* Prevents the race for canonicalization and updating
via autocomplete */
@@ -867,6 +892,10 @@
this.onObserverEvent();
},
+
+ afterUpdate: function(field, selection) {
+ Form.Element.validate(field);
+ },
getUpdatedChoices: function() {
var request = { path: this.url, actions: {} };
@@ -894,6 +923,55 @@
});
+Jifty.Placeholder = Class.create();
+Object.extend(Jifty.Placeholder.prototype, {
+ element: null,
+ text: null,
+
+ initialize: function(element, text) {
+ this.element = $(element);
+ this.text = text;
+ Event.observe(element, 'focus', this.onFocus.bind(this));
+ Event.observe(element, 'blur', this.onBlur.bind(this));
+ this.onBlur();
+
+ var form = Form.Element.getForm(element);
+
+ if(form && !form.hasPlaceholders) {
+ form.hasPlaceholders = true;
+ Event.observe(form, 'submit',
+ function () { Form.clearPlaceholders(form); } );
+ }
+ },
+
+ onBlur: function() {
+ if(this.element.value == '') {
+ Element.addClassName(this.element, 'placeholder');
+ this.element.value = this.text;
+ }
+ },
+
+ onFocus: function() {
+ Jifty.Placeholder.clearPlaceholder(this.element);
+ }
+
+});
+
+Object.extend(Jifty.Placeholder, {
+
+ hasPlaceholder: function(elt) {
+ return Element.hasClassName(elt, 'placeholder');
+ },
+
+ clearPlaceholder: function(elt) {
+ if(Jifty.Placeholder.hasPlaceholder(elt)) {
+ elt.value = '';
+ Element.removeClassName(elt, 'placeholder');
+ }
+ }
+
+});
+
// Define hasOwnProperty for Safari
if( !Object.prototype.hasOwnProperty ) {
More information about the Jifty-commit
mailing list