1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 06:38:00 +02:00

JS API - ajax fixes, e107Utils namespace for decorate js

This commit is contained in:
secretr
2008-11-11 13:17:18 +00:00
parent a9bf3ef163
commit b0e9dacb39
3 changed files with 41 additions and 39 deletions

View File

@@ -3,11 +3,11 @@
* Inspired by Magento' decorate JS functions (www.magentocommerce.com)
*/
var e107Decorate = {
e107Utils.Decorate = {
/**
* Decorate table rows and cells, tbody etc
* @see eDecorate()
* @see e107Utils.Decorate._decorate()
*/
table: function(table) {
var table = $(table);
@@ -16,31 +16,31 @@ var e107Decorate = {
//default options
this._options = {
'tbody': false,
'tbody tr': 'odd,even,first,last',
'thead tr': 'first,last',
'tfoot tr': 'first,last',
'tr td': 'last'
'tbody_tr': 'odd even first last',
'thead_tr': 'first last',
'tfoot_tr': 'first last',
'tr_td': false
};
// overload options
Object.extend(this._options, (arguments[1] || {}));
// decorate
if (this._options['tbody']) {
this._decorate(table.select('tbody'), this._options['tbody']);
}
if (this._options['tbody_tr']) {
this._decorate(table.select('tbody tr'), this._options['tbody tr']);
this._decorate(table.select('tbody tr'), this._options['tbody_tr']);
}
if (this._options['thead_tr']) {
this._decorate(table.select('thead tr'), this._options['thead tr']);
this._decorate(table.select('thead tr'), this._options['thead_tr']);
}
if (this._options['tfoot_tr']) {
this._decorate(table.select('tfoot tr'), this._options['tfoot tr']);
this._decorate(table.select('tfoot tr'), this._options['tfoot_tr']);
}
if (this._options['tr_td']) {
table.select('tr').each( function(tr) {
this._decorate(tr.select('td'), this._options['tr td']);
this._decorate(tr.select('td'), this._options['tr_td']);
}.bind(this));
}
},
@@ -50,22 +50,22 @@ var e107Decorate = {
* Default decorate CSS classes for list items are "odd", "even" and "last"
*
* Examples:
* eDecorateList('mylist'); //default decorate options over element with id 'mylist'
* eDecorateList('mylist', 'odd,even'); //decorate options odd and even only over element with id 'mylist'
* e107Utils.Decorate.list('mylist'); //default decorate options over element with id 'mylist'
* e107Utils.Decorate.list('mylist', 'odd even'); //decorate options odd and even only over element with id 'mylist'
*
* @param list - id/DOM object of list element (ul) to be decorated
* [@param options] - string|array decorate options - @see eDecorate()
* [@param options] - string|array decorate options - @see e107Utils.Decorate._decorate()
* [@param recursive] - boolean decorate all childs if present
*/
list: function(list) {
list = $(list);
if (list) {
if (typeof(arguments[2]) == 'undefined') {
var items = list.select('li')
if (!varset(arguments[2])) {
var items = list.select('li');
} else {
var items = list.childElements();
}
this._decorate(items, (arguments[1] || 'odd,even,last'));
this._decorate(items, (arguments[1] || 'odd even last'));
}
},
@@ -73,17 +73,17 @@ var e107Decorate = {
* Set "odd", "even" and "last" CSS classes for list items
*
* Examples:
* eDecorateDataList('mydatalist'); //default decorate options over element with id 'mydatalist'
* eDecorateDataList('mydatalist', 'odd,even'); //decorate options odd and even for dt elements, default for dd elements
* e107Utils.Decorate.dataList('mydatalist'); //default decorate options over element with id 'mydatalist'
* e107Utils.Decorate.dataList('mydatalist', 'odd even'); //decorate options odd and even for dt elements, default for dd elements
*
* [@param dt_options] - string|array dt element decorate options - @see eDecorate()
* [@param dd_options] - string|array dd element decorate options - @see eDecorate()
* [@param dt_options] - string|array dt element decorate options - @see e107Utils.Decorate._decorate()
* [@param dd_options] - string|array dd element decorate options - @see e107Utils.Decorate._decorate()
*/
dataList: function(list) {
list = $(list);
if (list) {
this._decorate(list.select('dt'), (arguments[1] || 'odd,even,last'));
this._decorate(list.select('dd'), (arguments[2] || 'odd,even,last'));
this._decorate(list.select('dt'), (arguments[1] || 'odd even last'));
this._decorate(list.select('dd'), (arguments[2] || 'odd even last'));
}
},
@@ -95,8 +95,8 @@ var e107Decorate = {
* [@param decorateParams] - array of classes to be set. If omitted or empty, all available will be used
*/
_decorate: function(elements) {
var decorateAllParams = ['odd', 'even', 'first', 'last'];
this.decorateParams = [];
var decorateAllParams = $w('odd even first last');
this.decorateParams = $A();
this.params = {};
if (!elements.length) return;
@@ -104,7 +104,7 @@ var e107Decorate = {
if(!varset(arguments[1])) {
this.decorateParams = decorateAllParams;
} else if(typeof(arguments[1]) == 'string') {
this.decorateParams = arguments[1].replace(/[\s]/, '').split(',');
this.decorateParams = $w(arguments[1]);
} else {
this.decorateParams = arguments[1];
}
@@ -112,7 +112,7 @@ var e107Decorate = {
decorateAllParams.each( function(v) {
this.params[v] = this.decorateParams.include(v);
}.bind(this));
console.log(elements[0]);
// decorate first
if(this.params.first) {
Element.addClassName(elements[0], 'first');
@@ -125,9 +125,9 @@ var e107Decorate = {
if(!this.params.even && !this.params.odd) {
return;
}
//elements.select(_eDecorateIsEven).invoke('addClassName', 'even');
var selections = elements.partition(this._isEven);
// decorate even
if(this.params.even) {
selections[0].invoke('addClassName', 'even');
}
@@ -139,7 +139,7 @@ var e107Decorate = {
/**
* Select/Reject/Partition callback function
*
* @see eDecorate()
* @see e107Utils.Decorate._decorate()
*/
_isEven: function(dummy, i) {
return ((i+1) % 2 == 0);

View File

@@ -2390,9 +2390,9 @@ e107Ajax.fillForm = Class.create(e107AjaxAbstract, {
Element.addMethods('FORM', {
submitForm: e107Ajax.submitForm,
submitForm: e107Ajax.submitForm.bind(e107Ajax),
submitFormSC: e107Ajax.submitFormSC,
submitFormSC: e107Ajax.submitFormSC.bind(e107Ajax),
fillForm: function(form, overlay_element, options) {
new e107Ajax.fillForm(form, overlay_element, options);

View File

@@ -8,11 +8,12 @@
* GNU General Public License (http://gnu.org).
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/jslib_handler.php,v $
* $Revision: 1.1 $
* $Date: 2008-11-09 20:31:10 $
* $Revision: 1.2 $
* $Date: 2008-11-11 13:17:18 $
* $Author: secretr $
*
*/
global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB;
class e_jslib
{
@@ -45,11 +46,12 @@ class e_jslib
$THEME_JSLIB = array();
//available values - admin,front,all,none
$core_jslib = array(
'jslib/prototype/prototype.js' => 'all' , //'jslib/scriptaculous/scriptaculous.js' => 'all',
'jslib/scriptaculous/effects.js' => 'all' , 'jslib/e107.js.php' => 'all'
//'jslib/core/decorate.js' => 'all',
//'jslib/core/window.js' => 'all'
$core_jslib = array( //FIXME - core jslib prefs, debug options
'jslib/prototype/prototype.js' => 'all' ,
'jslib/scriptaculous/scriptaculous.js' => 'all',
'jslib/scriptaculous/effects.js' => 'all',
'jslib/e107.js.php' => 'all'
//'jslib/core/decorate.js' => 'all'
);
$core_jslib = array_merge($core_jslib, $THEME_CORE_JSLIB, varsettrue($pref['e_jslib']['core'], array()));