Alien-GvaScript
view release on metacpan or search on metacpan
lib/Alien/GvaScript/lib/GvaScript.js view on Meta::CPAN
/*-------------------------------------------------------------------------*
* GvaScript - Javascript framework born in Geneva.
*
* Authors: Laurent Dami <laurent.d...@etat.ge.ch>
* Mona Remlawi
* Jean-Christophe Durand
* Sebastien Cuendet
* LICENSE
* This library is free software, you can redistribute it and/or modify
* it under the same terms as Perl's artistic license.
*
*--------------------------------------------------------------------------*/
var GvaScript = {
Version: '1.45',
REQUIRED_PROTOTYPE: '1.7',
load: function() {
function convertVersionString(versionString) {
var v = versionString.replace(/_.*|\./g, '');
v = parseInt(v + '0'.times(4-v.length));
return versionString.indexOf('_') > -1 ? v-1 : v;
}
if((typeof Prototype=='undefined') ||
(typeof Element == 'undefined') ||
(typeof Element.Methods=='undefined') ||
(convertVersionString(Prototype.Version) <
convertVersionString(GvaScript.REQUIRED_PROTOTYPE)))
throw("GvaScript requires the Prototype JavaScript framework >= " +
GvaScript.REQUIRED_PROTOTYPE);
}
};
GvaScript.load();
//----------protoExtensions.js
//-----------------------------------------------------
// Some extensions to the prototype javascript framework
//-----------------------------------------------------
// fire value:change event when setValue method
// is used to change the value of a Form Element
Form.Element.Methods.setValue = Form.Element.Methods.setValue.wrap(
function($p, element, value) {
var oldvalue = $F(element);
var _return = $p(element, value);
element.fire('value:change', {oldvalue: oldvalue, newvalue: value});
return _return;
}
);
Element.addMethods();
// adds the method flash to SPAN, DIV, INPUT, BUTTON elements
// flashes an element by adding a classname for a brief moment of time
// options: {classname: // classname to add (default: flash)
// duration: // duration in ms to keep the classname (default: 100ms)}
var _element_list = ['DIV', 'INPUT',
'BUTTON', 'TEXTAREA', 'A',
'H1', 'H2', 'H3', 'H4', 'H5'];
// for the moment, SPAN not supported on WebKit (see prototype.js bug in
// https://prototype.lighthouseapp.com/projects/8886/tickets/976-elementaddmethodsspan-fails-on-webkit)
if (!Prototype.Browser.WebKit) _element_list.push('SPAN');
Element.addMethods(_element_list, {
flash: function(element, options) {
if (element._IS_FLASHING) return;
element = $(element);
options = options || {};
var duration = options.duration || 100;
var classname = options.classname || 'flash';
element._IS_FLASHING = true;
var endFlash = function() {
this.removeClassName(classname);
this._IS_FLASHING = false;
};
element.addClassName(classname);
setTimeout(endFlash.bind(element), duration);
}
});
// utilities for hash
// expands flat hash into a multi-level deep hash
// javascript version of Perl CGI::Expand::expand_hash
Hash.expand = function(flat_hash) {
var tree = {};
// iterate on keys in the flat hash
for (var k in flat_hash) {
var parts = k.split(/\./);
var loop = {tree: tree, key: "root"};
// iterate on path parts within the key
for (var i = 0 ; i < parts.length; i++) {
var part = parts[i];
lib/Alien/GvaScript/lib/GvaScript.js view on Meta::CPAN
this.container.addClassName(bcss+'-actionsbar');
this.options.actions.each(function(action_props, index) {
action_props.id = action_props.id || this.container.id + '_btn_' + index;
// renders a <button> element and appends it to container
new GvaScript.CustomButtons.Button(this.container, action_props);
}, this);
this.buttonNavigation = new GvaScript.CustomButtons.ButtonNavigation(this.container, {
selectFirstBtn: this.options.selectfirst,
className: bcss+'-btn-container'
});
this.container.store('widget', this);
this.container.addClassName(bcss+'-widget');
},
destroy: function() {
this.buttonNavigation.destroy();
}
});
document.register('.'+CSSPREFIX()+'-btn-container', 'mouseover', function(e) {
e._target.addClassName('btn-hover');
});
document.register('.'+CSSPREFIX()+'-btn-container', 'mouseout', function(e) {
e._target.removeClassName('btn-hover');
});
//----------paginator.js
GvaScript.Paginator = Class.create();
Object.extend(GvaScript.Paginator.prototype, function() {
var bcss = CSSPREFIX();
var paginator_css = bcss + '-paginatorbar';
var pagination_buttons = "<div class='last' title='Dernière page'></div>"
+ "<div class='forward' title='Page suivante'></div>"
+ "<div class='text'></div>"
+ "<div class='back' title='Page précédente'></div>"
+ "<div class='first' title='Première page'></div>";
function _toggleNavigatorsVisibility() {
if(this.hasPrevious()) {
this.back.removeClassName('inactive');
this.first.removeClassName('inactive');
}
else {
this.back.addClassName('inactive');
this.first.addClassName('inactive');
}
if(this.hasNext()) {
this.forward.removeClassName('inactive');
this.last.removeClassName('inactive');
}
else {
this.forward.addClassName('inactive');
this.last.addClassName('inactive');
}
this.links_container.show();
}
/* Create pagination controls and append them to the placeholder 'PG:frame' */
function _addPaginationElts() {
// append the pagination buttons
this.links_container.insert(pagination_buttons);
this.first = this.links_container.down('.first');
this.last = this.links_container.down('.last');
this.forward = this.links_container.down('.forward');
this.back = this.links_container.down('.back');
this.textElem = this.links_container.down('.text');
this.first.observe ('click', this.getFirstPage.bind(this));
this.last.observe ('click', this.getLastPage.bind(this));
this.back.observe ('click', this.getPrevPage.bind(this));
this.forward.observe('click', this.getNextPage.bind(this));
}
return {
destroy: function() {
this.first.stopObserving();
this.last.stopObserving();
this.back.stopObserving();
this.forward.stopObserving();
},
initialize: function(url, options) {
var defaults = {
reset : 'no', // if yes, first call sends RESET=yes,
// subsequent calls don't (useful for
// resetting cache upon first request)
step : 20,
method : 'post', // POST so we get dispatched to *_PROCESS_FORM
parameters : $H({}),
onSuccess : Prototype.emptyFunction,
lazy : false, // false: load first page with Paginator initialization
// true: donot load automatically, loadContent would
// have to be called explicity
timeoutAjax : 15,
errorMsg : "Problème de connexion. Réessayer et si le problème persiste, contacter un administrateur."
};
this.options = Object.extend(defaults, options || {});
this.options.errorMsg = "<h3 style='color: #183E6C'>" + this.options.errorMsg + "</h3>";
this.links_container = $(this.options.links_container);
this.list_container = $(this.options.list_container);
this.url = url;
// initialization of flags
this.index = 1;
this.end_index = 0;
this.total = 0;
this._executing = false; // loadContent one at a time
// set the css for the paginator container
this.links_container.addClassName(paginator_css);
// and hide it
this.links_container.hide();
// add the pagination elements (next/prev links + text)
( run in 0.940 second using v1.01-cache-2.11-cpan-df04353d9ac )