javascripts/right-src.js in right-rails-0.4.2 vs javascripts/right-src.js in right-rails-0.4.3
- old
+ new
@@ -10,11 +10,11 @@
* The framework description object
*
* Copyright (C) 2008-2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-ilc-om>
*/
var RightJS = {
- version: "1.5.1",
+ version: "1.5.2",
modules: ["core", "form", "cookie", "xhr", "fx"]
};
/**
* this object will contain info about the current browser
@@ -471,20 +471,20 @@
for (var i=0, length = this.length; i < length; i++)
callback.call(scope, this[i], i, this);
};
var filter = A_proto.filter || function(callback, scope) {
- for (var result=[], i=0, length = this.length; i < length; i++) {
+ for (var result=[], i=0, j=0, length = this.length; i < length; i++) {
if (callback.call(scope, this[i], i, this))
- result.push(this[i]);
+ result[j++] = this[i];
}
return result;
};
var map = A_proto.map || function(callback, scope) {
for (var result=[], i=0, length = this.length; i < length; i++) {
- result.push(callback.call(scope, this[i], i, this));
+ result[i] = callback.call(scope, this[i], i, this);
}
return result;
};
var some = A_proto.some || function(callback, scope) {
@@ -1688,12 +1688,12 @@
event.pageX = event.clientX + scrolls.x;
event.pageY = event.clientY + scrolls.y;
- // faking the relatedElement
- event.relatedElement = event.type == 'mouseover' ? event.fromEvent :
+ // faking the relatedTarget
+ event.relatedTarget = event.type == 'mouseover' ? event.fromEvent :
event.type == 'mouseout' ? event.toEvent : null;
// faking the target property
event.target = event.srcElement;
}
@@ -2189,11 +2189,15 @@
var c_key;
for (var key in hash) {
c_key = key.indexOf('-') != -1 ? key.camelize() : key;
if (key === 'opacity') {
- this.setOpacity(hash[key]);
+ if (Browser.IE) {
+ this.style.filter = 'alpha(opacity='+ value * 100 +')';
+ } else {
+ this.style.opacity = value;
+ }
} else if (key === 'float') {
c_key = Browser.IE ? 'styleFloat' : 'cssFloat';
}
this.style[c_key] = hash[key];
@@ -2201,24 +2205,10 @@
return this;
},
/**
- * handles the opacity setting
- *
- * @param Float opacity value between 0 and 1
- * @return Element self
- */
- setOpacity: Browser.IE ? function(value) {
- this.style.filter = 'alpha(opacity='+ value * 100 +')';
- return this;
- } : function(value) {
- this.style.opacity = value;
- return this;
- },
-
- /**
* returns style of the element
*
* NOTE: will include the CSS level definitions
*
* @param String style key
@@ -3677,11 +3667,11 @@
'long': 800
},
// default options
Options: {
- fps: Browser.IE || Browser.Opera ? 35 : 60,
+ fps: Browser.IE ? 40 : 60,
duration: 'normal',
transition: 'Sin',
queue: true
},
@@ -3783,11 +3773,18 @@
// the periodically called method
// NOTE: called outside of the instance scope!
step: function(that) {
if (that.number > that.steps) that.finish();
- else that.render(that.transition(++ that.number / that.steps));
+ else {
+ if (!that.w) {
+ that.w = true;
+ that.render(that.transition(that.number / that.steps));
+ that.w = false;
+ }
+ that.number ++;
+ }
},
startTimer: function() {
this.timer = this.step.periodical((1000 / this.options.fps).round(), this);
return this;
@@ -3908,32 +3905,56 @@
*
* Copyright (C) 2008-2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-ilc-om>
*/
Fx.Morph = new Class(Fx, (function() {
// a list of common style names to compact the code a bit
- var Top = 'Top', Left = 'Left', Right = 'Right', Bottom = 'Bottom', Color = 'Color', Style = 'Style',
- Width = 'Width', Bg = 'background', Border = 'border', Pos = 'Position', BgColor = Bg + Color,
- BdStyle = Border + Style, BdColor = Border + Color, BdWidth = Border + Width;
+ var Color = 'Color', Style = 'Style', Width = 'Width', Bg = 'background',
+ Border = 'border', Pos = 'Position', BgColor = Bg + Color,
+ directions = $w('Top Left Right Bottom');
// adds variants to the style names list
var add_variants = function(keys, key, variants) {
for (var i=0; i < variants.length; i++)
keys.push(key + variants[i]);
};
+ // adjusts the border-styles
+ var check_border_styles = function(before, after) {
+ for (var i=0; i < 4; i++) {
+ var direction = directions[i],
+ bd_style = Border + direction + Style,
+ bd_width = Border + direction + Width,
+ bd_color = Border + direction + Color;
+
+ if (before[bd_style] != after[bd_style]) {
+ var style = this.element.style;
+
+ if (before[bd_style] == 'none') {
+ style[bd_width] = '0px';
+ }
+
+ style[bd_style] = after[bd_style];
+ if (this._transp(before[bd_color])) {
+ style[bd_color] = this.element.getStyle(Color);
+ }
+ }
+ }
+ };
+
// parses the style hash into a processable format
var parse_style = function(values) {
var result = {}, re = /[\d\.\-]+/g, m;
for (var key in values) {
m = values[key].match(re);
var value = m.map('toFloat');
value.t = values[key].split(re);
- if (/^\d/.test(values[key]) && value.t[0] !== '') value.t.unshift('');
+ value.r = value.t[0] === 'rgb(';
+ if (value.t[0] === '' || value.r) value.t.shift();
for (var i=0; i < value.length; i++) {
- value.t.splice(i*2+1, 0, value[i]);
+ value.t.splice(i*2, 0, value[i]);
}
result[key] = value;
}
return result;
@@ -3961,32 +3982,36 @@
before = this.before[key];
after = this.after[key];
for (var i=0; i < after.length; i++) {
value = before[i] + (after[i] - before[i]) * delta;
- if (after.t[0] === 'rgb(') value = Math.round(value);
- after.t[i*2+1] = ''+value;
+ if (after.r) value = Math.round(value);
+ after.t[i*2] = value;
}
- style[key] = after.t.join('');
+ value = after.t.join('');
+ if (after.r) value = 'rgb('+value;
+ style[key] = value;
}
},
/**
* Returns a hash of the end style
*
* @param Object style
* @return Object end style
*/
_endStyle: function(style, keys) {
- var parent = this.element.parentNode,
- dummy = $(this.element.cloneNode(true)).setStyle(style);
-
- // swapping the element with the dummy and getting the new styles
- if (parent) parent.replaceChild(dummy, this.element);
+ var dummy = $(this.element.cloneNode(true))
+ .setStyle('position:absolute;z-index:-1;visibility:hidden')
+ .insertTo(this.element, 'before')
+ .setWidth(this.element.sizes().x)
+ .setStyle(style);
+
var after = this._cloneStyle(dummy, keys);
- if (parent) parent.replaceChild(this.element, dummy);
+ dummy.remove();
+
return after;
},
/**
* Fast styles cloning
@@ -4007,11 +4032,11 @@
*
* @param Object the style hash
* @return Array of clean style keys list
*/
_styleKeys: function(style) {
- var keys = [], border_types = [Style, Color, Width], directions = [Top, Left, Right, Bottom];
+ var keys = [], border_types = [Style, Color, Width];
for (var key in style) {
if (key.startsWith(Border))
for (var i=0; i < border_types.length; i++)
for (var j=0; j < directions.length; j++)
@@ -4038,50 +4063,21 @@
*/
_cleanStyles: function(before, after) {
var remove = [];
for (var key in after) {
- // getting directional options together so they were processed faster
- if (key.includes(Top)) {
- var top = key,
- left = key.replace(Top, Left),
- right = key.replace(Top, Right),
- bottom = key.replace(Top, Bottom),
- common = key.replace(Top, '');
-
- if (after[top] == after[left] && after[top] == after[right] && after[top] == after[bottom] &&
- before[top] == before[left] && before[top] == before[right] && before[top] == before[bottom]
- ) {
- after[common] = after[top];
- before[common] = before[top];
-
- remove = remove.concat([top, left, right, bottom]);
- }
- }
-
// checking the height/width options
if ((key == 'width' || key == 'height') && before[key] == 'auto') {
before[key] = this.element['offset'+key.capitalize()] + 'px';
}
}
// IE opacity filter fix
if (after.filter && !before.filter) before.filter = 'alpha(opacity=100)';
// adjusting the border style
- if (before[BdStyle] != after[BdStyle]) {
- var style = this.element.style;
-
- if (before[BdStyle] == 'none') {
- style[BdWidth] = '0px';
- }
-
- style[BdStyle] = after[BdStyle];
- if (this._transp(before[BdColor])) {
- style[BdColor] = this.element.getStyle(Color);
- }
- }
+ check_border_styles.call(this, before, after);
// cleaing up the list
for (var key in after) {
// proprocessing colors
if (after[key] !== before[key] && !remove.includes(key) && /color/i.test(key)) {
@@ -4280,10 +4276,10 @@
Fx.Fade = new Class(Fx.Twin, {
prepare: function(how) {
this.setHow(how);
if (this.how == 'in')
- this.element.setOpacity(0).show();
+ this.element.setStyle({opacity: 0}).show();
return this.$super({opacity: isNumber(how) ? how : this.how == 'in' ? 1 : 0});
}
});
\ No newline at end of file