proto/public/js/effects.js in nitro-0.24.0 vs proto/public/js/effects.js in nitro-0.25.0
- old
+ new
@@ -2,12 +2,187 @@
// Contributors:
// Justin Palmer (http://encytemedia.com/)
// Mark Pilgrim (http://diveintomark.org/)
// Martin Bialasinki
//
-// See scriptaculous.js for full license.
+// See scriptaculous.js for full license.
+/* ------------- element ext -------------- */
+
+// converts rgb() and #xxx to #xxxxxx format,
+// returns self (or first argument) if not convertable
+String.prototype.parseColor = function() {
+ color = "#";
+ if(this.slice(0,4) == "rgb(") {
+ var cols = this.slice(4,this.length-1).split(',');
+ var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
+ } else {
+ if(this.slice(0,1) == '#') {
+ if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
+ if(this.length==7) color = this.toLowerCase();
+ }
+ }
+ return(color.length==7 ? color : (arguments[0] || this));
+}
+
+Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {
+ var children = $(element).childNodes;
+ var text = "";
+ var classtest = new RegExp("^([^ ]+ )*" + ignoreclass+ "( [^ ]+)*$","i");
+
+ for (var i = 0; i < children.length; i++) {
+ if(children[i].nodeType==3) {
+ text+=children[i].nodeValue;
+ } else {
+ if((!children[i].className.match(classtest)) && children[i].hasChildNodes())
+ text += Element.collectTextNodesIgnoreClass(children[i], ignoreclass);
+ }
+ }
+
+ return text;
+}
+
+Element.setContentZoom = function(element, percent) {
+ element = $(element);
+ element.style.fontSize = (percent/100) + "em";
+ if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
+}
+
+Element.getOpacity = function(element){
+ var opacity;
+ if (opacity = Element.getStyle(element, "opacity"))
+ return parseFloat(opacity);
+ if (opacity = (Element.getStyle(element, "filter") || '').match(/alpha\(opacity=(.*)\)/))
+ if(opacity[1]) return parseFloat(opacity[1]) / 100;
+ return 1.0;
+}
+
+Element.setOpacity = function(element, value){
+ element= $(element);
+ var els = element.style;
+ if (value == 1){
+ els.opacity = '0.999999';
+ if(/MSIE/.test(navigator.userAgent))
+ els.filter = Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'');
+ } else {
+ if(value < 0.00001) value = 0;
+ els.opacity = value;
+ if(/MSIE/.test(navigator.userAgent))
+ els.filter = Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') +
+ "alpha(opacity="+value*100+")";
+ }
+}
+
+Element.getInlineOpacity = function(element){
+ element= $(element);
+ var op;
+ op = element.style.opacity;
+ if (typeof op != "undefined" && op != "") return op;
+ return "";
+}
+
+Element.setInlineOpacity = function(element, value){
+ element= $(element);
+ var els = element.style;
+ els.opacity = value;
+}
+
+/*--------------------------------------------------------------------------*/
+
+Element.Class = {
+ // Element.toggleClass(element, className) toggles the class being on/off
+ // Element.toggleClass(element, className1, className2) toggles between both classes,
+ // defaulting to className1 if neither exist
+ toggle: function(element, className) {
+ if(Element.Class.has(element, className)) {
+ Element.Class.remove(element, className);
+ if(arguments.length == 3) Element.Class.add(element, arguments[2]);
+ } else {
+ Element.Class.add(element, className);
+ if(arguments.length == 3) Element.Class.remove(element, arguments[2]);
+ }
+ },
+
+ // gets space-delimited classnames of an element as an array
+ get: function(element) {
+ return $(element).className.split(' ');
+ },
+
+ // functions adapted from original functions by Gavin Kistner
+ remove: function(element) {
+ element = $(element);
+ var removeClasses = arguments;
+ $R(1,arguments.length-1).each( function(index) {
+ element.className =
+ element.className.split(' ').reject(
+ function(klass) { return (klass == removeClasses[index]) } ).join(' ');
+ });
+ },
+
+ add: function(element) {
+ element = $(element);
+ for(var i = 1; i < arguments.length; i++) {
+ Element.Class.remove(element, arguments[i]);
+ element.className += (element.className.length > 0 ? ' ' : '') + arguments[i];
+ }
+ },
+
+ // returns true if all given classes exist in said element
+ has: function(element) {
+ element = $(element);
+ if(!element || !element.className) return false;
+ var regEx;
+ for(var i = 1; i < arguments.length; i++) {
+ if((typeof arguments[i] == 'object') &&
+ (arguments[i].constructor == Array)) {
+ for(var j = 0; j < arguments[i].length; j++) {
+ regEx = new RegExp("(^|\\s)" + arguments[i][j] + "(\\s|$)");
+ if(!regEx.test(element.className)) return false;
+ }
+ } else {
+ regEx = new RegExp("(^|\\s)" + arguments[i] + "(\\s|$)");
+ if(!regEx.test(element.className)) return false;
+ }
+ }
+ return true;
+ },
+
+ // expects arrays of strings and/or strings as optional paramters
+ // Element.Class.has_any(element, ['classA','classB','classC'], 'classD')
+ has_any: function(element) {
+ element = $(element);
+ if(!element || !element.className) return false;
+ var regEx;
+ for(var i = 1; i < arguments.length; i++) {
+ if((typeof arguments[i] == 'object') &&
+ (arguments[i].constructor == Array)) {
+ for(var j = 0; j < arguments[i].length; j++) {
+ regEx = new RegExp("(^|\\s)" + arguments[i][j] + "(\\s|$)");
+ if(regEx.test(element.className)) return true;
+ }
+ } else {
+ regEx = new RegExp("(^|\\s)" + arguments[i] + "(\\s|$)");
+ if(regEx.test(element.className)) return true;
+ }
+ }
+ return false;
+ },
+
+ childrenWith: function(element, className) {
+ var children = $(element).getElementsByTagName('*');
+ var elements = new Array();
+
+ for (var i = 0; i < children.length; i++)
+ if (Element.Class.has(children[i], className))
+ elements.push(children[i]);
+
+ return elements;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
var Effect = {
tagifyText: function(element) {
var tagifyStyle = "position:relative";
if(/MSIE/.test(navigator.userAgent)) tagifyStyle += ";zoom:1";
element = $(element);
@@ -79,10 +254,13 @@
/* ------------- core effects ------------- */
Effect.Queue = {
effects: [],
+ _each: function(iterator) {
+ this.effects._each(iterator);
+ },
interval: null,
add: function(effect) {
var timestamp = new Date().getTime();
switch(effect.options.queue) {
@@ -115,10 +293,11 @@
loop: function() {
var timePos = new Date().getTime();
this.effects.invoke('loop', timePos);
}
}
+Object.extend(Effect.Queue, Enumerable);
Effect.Base = function() {};
Effect.Base.prototype = {
position: null,
setOptions: function(options) {
@@ -340,10 +519,12 @@
startcolor: "#ffff99"
}, arguments[1] || {});
this.start(options);
},
setup: function() {
+ // Prevent executing on elements not in the layout flow
+ if(this.element.style.display=='none') { this.cancel(); return; }
// Disable background image during the effect
this.oldBgImage = this.element.style.backgroundImage;
this.element.style.backgroundImage = "none";
if(!this.options.endcolor)
this.options.endcolor = Element.getStyle(this.element, 'background-color').parseColor('#ffffff');
@@ -570,11 +751,11 @@
element.style.height = '0';
Element.show(element);
},
afterUpdateInternal: function(effect) {
effect.element.firstChild.style.bottom =
- (effect.originalHeight - effect.element.clientHeight) + 'px'; },
+ (effect.dims[0] - effect.element.clientHeight) + 'px'; },
afterFinishInternal: function(effect) {
Element.undoClipping(effect.element);
Element.undoPositioned(effect.element.firstChild);
effect.element.firstChild.style.bottom = oldInnerBottom; }
}, arguments[1] || {})
@@ -597,11 +778,11 @@
Element.makeClipping(effect.element);
Element.show(element);
},
afterUpdateInternal: function(effect) {
effect.element.firstChild.style.bottom =
- (effect.originalHeight - effect.element.clientHeight) + 'px'; },
+ (effect.dims[0] - effect.element.clientHeight) + 'px'; },
afterFinishInternal: function(effect) {
Element.hide(effect.element);
Element.undoClipping(effect.element);
Element.undoPositioned(effect.element.firstChild);
effect.element.firstChild.style.bottom = oldInnerBottom; }
@@ -695,10 +876,10 @@
Element.undoClipping(el);
Element.undoPositioned(el);
els.top = oldTop;
els.left = oldLeft;
els.height = oldHeight;
- els.width = originalWidth;
+ els.width = originalWidth + 'px';
Element.setInlineOpacity(el, oldOpacity);
}
}, options)
)
}