Index: wp-includes/js/list-manipulation.js
===================================================================
--- wp-includes/js/list-manipulation.js (revision 4967)
+++ wp-includes/js/list-manipulation.js (working copy)
@@ -1,8 +1,25 @@
-
-addLoadEvent(function(){theList=new listMan();});
-function deleteSomething(what,id,message,obj){if(!obj)obj=theList;if(!message)message="";if(confirm(message))return obj.ajaxDelete(what,id);else return false;}
-function dimSomething(what,id,dimClass,obj){if(!obj)obj=theList;return obj.ajaxDimmer(what,id,dimClass);}
+addLoadEvent( function() {
+ if ( 'undefined' != typeof listManL10n )
+ Object.extend(listMan.prototype, listManL10n);
+ theList = new listMan();
+} );
+function deleteSomething( what, id, message, obj ) {
+ if ( !obj )
+ obj=theList;
+ if ( !message )
+ message = obj.delText.replace(/%/g, what);
+ if( confirm(message) )
+ return obj.ajaxDelete( what, id );
+ else return false;
+}
+
+function dimSomething( what, id, dimClass, obj ) {
+ if ( !obj )
+ obj = theList;
+ return obj.ajaxDimmer(what,id,dimClass);
+}
+
var listMan = Class.create();
Object.extend(listMan.prototype, {
ajaxRespEl: 'ajax-response',
@@ -19,6 +36,9 @@
dataStore: null,
formStore: null,
+ jumpText: 'Jump to new item',
+ delText: 'Are you sure you want to delete this %s?',
+
initialize: function(theListId) {
this.theList = $(theListId ? theListId : 'the-list');
if ( !this.theList )
@@ -53,7 +73,7 @@
if ( m )
showLinkMessage += m;
else
- showLinkMessage += "";
+ showLinkMessage += "" + tempObj.jumpText + "";
});
if ( tempObj.showLink && showLinkMessage )
Element.update(ajaxAdd.myResponseElement,"
");
@@ -127,7 +147,7 @@
Element.cleanWhitespace(this.theList);
var id = this.topAdder ? this.theList.firstChild.id : this.theList.lastChild.id;
if ( this.alt )
- if ( this.theList.childNodes.length % 2 )
+ if ( ( this.theList.childNodes.length + this.altOffset ) % 2 )
Element.addClassName($(id),this.alt);
Fat.fade_element(id);
},
Index: wp-includes/js/list-manipulation-js.php
===================================================================
--- wp-includes/js/list-manipulation-js.php (revision 4967)
+++ wp-includes/js/list-manipulation-js.php (working copy)
@@ -1,275 +0,0 @@
-
-addLoadEvent(function(){theList=new listMan();});
-function deleteSomething(what,id,message,obj){if(!obj)obj=theList;if(!message)message="";if(confirm(message))return obj.ajaxDelete(what,id);else return false;}
-function dimSomething(what,id,dimClass,obj){if(!obj)obj=theList;return obj.ajaxDimmer(what,id,dimClass);}
-
-var listMan = Class.create();
-Object.extend(listMan.prototype, {
- ajaxRespEl: 'ajax-response',
- ajaxHandler: false,
- inputData: '',
- clearInputs: [],
- showLink: true,
- topAdder: false,
- alt: 'alternate',
- altOffset: 0,
- addComplete: null,
- delComplete: null,
- dimComplete: null,
- dataStore: null,
- formStore: null,
-
- initialize: function(theListId) {
- this.theList = $(theListId ? theListId : 'the-list');
- if ( !this.theList )
- return false;
- Element.cleanWhitespace(this.theList);
- },
-
- // sends add-what and fields contained in where
- // recieves html with top element having an id like what-#
- ajaxAdder: function( what, where, update ) { // Do NOT wrap TR in TABLE TBODY
- var ajaxAdd = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
- if ( ajaxAdd.notInitialized() )
- return true;
- var action = ( update ? 'update-' : 'add-' ) + what;
- ajaxAdd.options.parameters = $H(ajaxAdd.options.parameters).merge({action: action}).merge(this.inputData.toQueryParams()).merge(this.grabInputs( where, ajaxAdd ).toQueryParams());
-
- var tempObj=this;
- ajaxAdd.addOnComplete( function(transport) {
- var newItems = $A(transport.responseXML.getElementsByTagName(what));
- if ( newItems ) {
- var showLinkMessage = '';
- var m = '';
- newItems.each( function(i) {
- var id = i.getAttribute('id');
- var exists = $(what+'-'+id);
- if ( exists )
- tempObj.replaceListItem( exists, getNodeValue(i,'response_data'), update );
- else
- tempObj.addListItem( getNodeValue(i, 'response_data') );
- m = getNodeValue(i, 'show-link');
- showLinkMessage += showLinkMessage ? "
\n" : '';
- if ( m )
- showLinkMessage += m;
- else
- showLinkMessage += "";
- });
- if ( tempObj.showLink && showLinkMessage )
- Element.update(ajaxAdd.myResponseElement,"");
- }
- if ( tempObj.addComplete && typeof tempObj.addComplete == 'function' )
- tempObj.addComplete( what, where, update, transport );
- tempObj.recolorList();
- ajaxAdd.restoreInputs = null;
- });
- if ( !update )
- ajaxAdd.addOnWPError( function(transport) { tempObj.restoreForm(ajaxAdd.restoreInputs); });
- ajaxAdd.request(ajaxAdd.url);
- if ( !update )
- this.clear();
- return false;
- },
-
- // sends update-what and fields contained in where
- // recieves html with top element having an id like what-#
- ajaxUpdater: function( what, where ) { return this.ajaxAdder( what, where, true ); },
-
- // sends delete-what and id#
- ajaxDelete: function( what, id ) {
- var ajaxDel = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
- if( ajaxDel.notInitialized() )
- return true;
- var tempObj = this;
- var action = 'delete-' + what;
- var actionId = action + '&id=' + id;
- var idName = what.replace('-as-spam','') + '-' + id;
- ajaxDel.addOnComplete( function(transport) {
- Element.update(ajaxDel.myResponseElement,'');
- tempObj.destore(actionId);
- if( tempObj.delComplete && typeof tempObj.delComplete == 'function' )
- tempObj.delComplete( what, id, transport );
- });
- ajaxDel.addOnWPError( function(transport) { tempObj.restore(actionId, true); });
- ajaxDel.options.parameters = $H(ajaxDel.options.parameters).merge({action: action, id: id}).merge(this.inputData.toQueryParams());
- ajaxDel.request(ajaxDel.url);
- this.store(actionId, idName);
- tempObj.removeListItem( idName );
- return false;
- },
-
- // Toggles class nomes
- // sends dim-what and id#
- ajaxDimmer: function( what, id, dimClass ) {
- ajaxDim = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
- if ( ajaxDim.notInitialized() )
- return true;
- var tempObj = this;
- var action = 'dim-' + what;
- var actionId = action + '&id=' + id;
- var idName = what + '-' + id;
- ajaxDim.addOnComplete( function(transport) {
- Element.update(ajaxDim.myResponseElement,'');
- tempObj.destore(actionId);
- if ( tempObj.dimComplete && typeof tempObj.dimComplete == 'function' )
- tempObj.dimComplete( what, id, dimClass, transport );
- });
- ajaxDim.addOnWPError( function(transport) { tempObj.restore(actionId, true); });
- ajaxDim.options.parameters = $H(ajaxDim.options.parameters).merge({action: action, id: id}).merge(this.inputData.toQueryParams());
- ajaxDim.request(ajaxDim.url);
- this.store(actionId, idName);
- this.dimItem( idName, dimClass );
- return false;
- },
-
- addListItem: function( h ) {
- new Insertion[this.topAdder ? 'Top' : 'Bottom'](this.theList,h);
- Element.cleanWhitespace(this.theList);
- var id = this.topAdder ? this.theList.firstChild.id : this.theList.lastChild.id;
- if ( this.alt )
- if ( this.theList.childNodes.length % 2 )
- Element.addClassName($(id),this.alt);
- Fat.fade_element(id);
- },
-
- // only hides the element sa it can be put back again if necessary
- removeListItem: function( id, noFade ) {
- id = $(id);
- if ( !noFade ) {
- Fat.fade_element(id.id,null,700,'#FF3333');
- var tempObj = this;
- var func = function() { id.hide(); tempObj.recolorList(); }
- setTimeout(func, 705);
- } else {
- id.hide();
- this.recolorList();
- }
- },
-
- replaceListItem: function( id, h, update ) {
- id = $(id);
- if ( !update ) {
- Element.remove(id);
- this.addListItem( h );
- return;
- }
- id.replace(h);
- Fat.fade_element(id.id);
- },
-
- // toggles class
- dimItem: function( id, dimClass, noFade ) {
- id = $(id);
- if ( Element.hasClassName(id,dimClass) ) {
- if ( !noFade )
- Fat.fade_element(id.id,null,700,null);
- Element.removeClassName(id,dimClass);
- } else {
- if ( !noFade )
- Fat.fade_element(id.id,null,700,'#FF3333');
- Element.addClassName(id,dimClass);
- }
- },
-
- // store an element in case we need it later
- store: function(action, id) {
- if ( !this.dataStore )
- this.dataStore = $H();
- this.dataStore[action] = $(id).cloneNode(true);
- },
-
- // delete from store
- destore: function(action) { delete(this.dataStore[action]); },
-
- // restore element from store into existing (possibly hidden) element of same id
- restore: function(action, error) {
- var id = this.dataStore[action].id;
- this.theList.replaceChild(this.dataStore[action], $(id));
- delete(this.dataStore[action]);
- if ( error ) {
- func = function() { Element.setStyle($(id),{backgroundColor:'#FF3333'}); }
- func(); setTimeout(func, 705); // Hit it twice in case it's still fading.
- }
- },
-
- // Like Form.serialize, but excludes action and sets up clearInputs
- grabInputs: function( where, ajaxObj ) {
- if ( ajaxObj )
- ajaxObj.restoreInputs = [];
- var elements = Form.getElements($(where));
- var queryComponents = new Array();
- for (var i = 0; i < elements.length; i++) {
- if ( 'action' == elements[i].name )
- continue;
- if ( 'hidden' != elements[i].type && 'submit' != elements[i].type && 'button' != elements[i].type ) {
- this.clearInputs.push(elements[i]);
- if ( ajaxObj )
- ajaxObj.restoreInputs.push([elements[i], elements[i].value]);
- }
- var queryComponent = Form.Element.serialize(elements[i]);
- if (queryComponent) {
- queryComponents.push(queryComponent);
- }
- }
- return queryComponents.join('&');
- },
-
- // form.reset() can only do whole forms. This can do subsections.
- clear: function() {
- this.clearInputs.each( function(i) {
- i = $(i);
- if ( 'textarea' == i.tagName.toLowerCase() )
- i.value = '';
- else
- switch ( i.type.toLowerCase() ) {
- case 'password': case 'text':
- i.value = '';
- break;
- case 'checkbox': case 'radio':
- i.checked = false;
- break;
- case 'select': case 'select-one':
- i.selectedIndex = null;
- break;
- case 'select-multiple':
- for (var o = 0; o < i.length; o++) i.options[o].selected = false;
- break;
- }
- });
- this.clearInputs = [];
- },
-
- restoreForm: function(elements) {
- elements.each( function(i) {
- i[0].value = i[1];
- });
- },
-
- recolorList: function() {
- if ( !this.alt )
- return;
- var alt = this.alt;
- var offset = this.altOffset;
- var listItems = $A(this.theList.childNodes).findAll( function(i) { return Element.visible(i) } );
- listItems.each( function(i,n) {
- if ( ( n + offset ) % 2 )
- Element.removeClassName(i,alt);
- else
- Element.addClassName(i,alt);
- });
- }
-});
-
-//No submit unless code returns true.
-function killSubmit ( code, e ) {
- e = e ? e : window.event;
- if ( !e ) return;
- var t = e.target ? e.target : e.srcElement;
- if ( ( 'text' == t.type && e.keyCode == 13 ) || ( 'submit' == t.type && 'click' == e.type ) ) {
- if ( ( 'string' == typeof code && !eval(code) ) || ( 'function' == typeof code && !code() ) ) {
- e.returnValue = false; e.cancelBubble = true; return false;
- }
- }
-}
-//Generic but lame JS closure
-function encloseFunc(f){var a=arguments[1];return function(){return f(a);}}
Index: wp-includes/script-loader.php
===================================================================
--- wp-includes/script-loader.php (revision 4967)
+++ wp-includes/script-loader.php (working copy)
@@ -21,7 +21,11 @@
$this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0-0');
$this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '20070116');
$this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '20070118');
- $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '20070118');
+ $this->add( 'listman', '/wp-includes/js/list-manipulation.js', array('wp-ajax', 'fat'), '20070305');
+ $this->localize( 'listman', 'listManL10n', array(
+ 'jumpText' => __('Jump to new item'),
+ 'delText' => __('Are you sure you want to delete this %s?')
+ ) );
$this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.7.0');
$this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.7.0');
$this->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.7.0');
@@ -83,13 +87,32 @@
$src = add_query_arg('ver', $ver, $src);
$src = apply_filters( 'script_loader_src', $src );
echo "\n";
+ $this->print_scripts_l10n( $handle );
}
$this->printed[] = $handle;
}
}
}
+ function print_scripts_l10n( $handle ) {
+ if ( empty($this->scripts[$handle]->l10n_object) || empty($this->scripts[$handle]->l10n) || !is_array($this->scripts[$handle]->l10n) )
+ return;
+ $object_name = $this->scripts[$handle]->l10n_object;
+
+ echo "\n";
+ }
+
/**
* Determines dependencies of scripts
*
@@ -140,6 +163,22 @@
return true;
}
+ /**
+ * Localizes a script
+ *
+ * Localizes only if script has already been added
+ *
+ * @param string handle Script name
+ * @param string object_name Name of JS object to hold l10n info
+ * @param array l10n Array of JS var name => localized string
+ * @return bool Successful localization
+ */
+ function localize( $handle, $object_name, $l10n ) {
+ if ( !isset($this->scripts[$handle]) )
+ return false;
+ return $this->scripts[$handle]->localize( $object_name, $l10n );
+ }
+
function remove( $handles ) {
foreach ( (array) $handles as $handle )
unset($this->scripts[$handle]);
@@ -182,7 +221,8 @@
var $src;
var $deps = array();
var $ver = false;
- var $args = false;
+ var $l10n_object = '';
+ var $l10n = array();
function _WP_Script() {
@list($this->handle, $this->src, $this->deps, $this->ver) = func_get_args();
@@ -191,6 +231,14 @@
if ( !$this->ver )
$this->ver = false;
}
+
+ function localize( $object_name, $l10n ) {
+ if ( !$object_name || !is_array($l10n) )
+ return false;
+ $this->l10n_object = $object_name;
+ $this->l10n = $l10n;
+ return true;
+ }
}
/**
@@ -227,6 +275,21 @@
$wp_scripts->add( $handle, $src, $deps, $ver );
}
+/**
+ * Localizes a script
+ *
+ * Localizes only if script has already been added
+ *
+ * @see WP_Script::localize()
+ */
+function wp_localize_script( $handle, $object_name, $l10n ) {
+ global $wp_scripts;
+ if ( !is_a($wp_scripts, 'WP_Scripts') )
+ return false;
+
+ return $wp_scripts->localize( $handle, $object_name, $l10n );
+}
+
function wp_deregister_script( $handle ) {
global $wp_scripts;
if ( !is_a($wp_scripts, 'WP_Scripts') )