Commit f0fcf61d authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Upstream MochiKit

parent 0ef693ef
......@@ -393,7 +393,7 @@ MochiKit.Base.update(MochiKit.Color.Color, {
var d = MochiKit.DOM;
var cls = MochiKit.Color.Color;
for (elem = d.getElement(elem); elem; elem = elem.parentNode) {
var actualColor = MochiKit.Style.computedStyle.apply(d, arguments);
var actualColor = MochiKit.Style.getStyle.apply(d, arguments);
if (!actualColor) {
continue;
}
......
......@@ -110,6 +110,7 @@ MochiKit.DOM.EXPORT = [
"emitHTML",
"scrapeText",
"isParent",
"getFirstParentByTagAndClassName",
"makeClipping",
"undoClipping",
"makePositioned",
......@@ -122,7 +123,7 @@ MochiKit.DOM.EXPORT_OK = [
];
MochiKit.DOM.DEPRECATED = [
['computedStyle', 'MochiKit.Style.computedStyle', '1.4'],
['computedStyle', 'MochiKit.Style.getStyle', '1.4'],
/** @id MochiKit.DOM.elementDimensions */
['elementDimensions', 'MochiKit.Style.getElementDimensions', '1.4'],
/** @id MochiKit.DOM.elementPosition */
......@@ -1038,6 +1039,43 @@ MochiKit.Base.update(MochiKit.DOM, {
}
},
/** @id MochiKit.DOM.getFirstParentByTagAndClassName */
getFirstParentByTagAndClassName: function (elem, tagName, className) {
var self = MochiKit.DOM;
elem = self.getElement(elem);
if (typeof(tagName) == 'undefined' || tagName === null) {
tagName = '*';
} else {
tagName = tagName.toUpperCase();
}
if (typeof(className) == 'undefined' || className === null) {
className = null;
}
var classList = '';
var curTagName = '';
while (elem && elem.tagName) {
elem = elem.parentNode;
if (tagName == '*' && className === null) {
return elem;
}
classList = elem.className.split(' ');
curTagName = elem.tagName.toUpperCase();
if (className === null && tagName == curTagName) {
return elem;
} else if (className !== null) {
for (var i = 0; i < classList.length; i++) {
if (tagName == '*' && classList[i] == className) {
return elem;
} else if (tagName == curTagName && classList[i] == className) {
return elem;
}
}
}
}
return elem;
},
/** @id MochiKit.DOM.isParent */
isParent: function (child, element) {
if (!child.parentNode || child == element) {
......
......@@ -415,7 +415,7 @@ MochiKit.DragAndDrop.Draggable.prototype = {
/** @id MochiKit.DragAndDrop.starteffect */
starteffect: function (innerelement) {
this._savedOpacity = MochiKit.Style.getOpacity(innerelement) || 1.0;
this._savedOpacity = MochiKit.Style.getStyle(innerelement, 'opacity') || 1.0;
new v.Opacity(innerelement, {duration:0.2, from:this._savedOpacity, to:0.7});
},
/** @id MochiKit.DragAndDrop.reverteffect */
......
......@@ -66,12 +66,19 @@ MochiKit.Base.update(MochiKit.Signal.Event.prototype, {
var str = '{event(): ' + repr(this.event()) +
', src(): ' + repr(this.src()) +
', type(): ' + repr(this.type()) +
', target(): ' + repr(this.target()) +
', modifier(): ' + '{alt: ' + repr(this.modifier().alt) +
', target(): ' + repr(this.target());
if (this.type() &&
this.type().indexOf('key') === 0 ||
this.type().indexOf('mouse') === 0 ||
this.type().indexOf('click') != -1 ||
this.type() == 'contextmenu') {
str += ', modifier(): ' + '{alt: ' + repr(this.modifier().alt) +
', ctrl: ' + repr(this.modifier().ctrl) +
', meta: ' + repr(this.modifier().meta) +
', shift: ' + repr(this.modifier().shift) +
', any: ' + repr(this.modifier().any) + '}';
}
if (this.type() && this.type().indexOf('key') === 0) {
str += ', key(): {code: ' + repr(this.key().code) +
......@@ -344,7 +351,7 @@ MochiKit.Base.update(MochiKit.Signal.Event.prototype, {
- Safari doesn't fire any click events on a right
click:
http://bugzilla.opendarwin.org/show_bug.cgi?id=6595
http://bugs.webkit.org/show_bug.cgi?id=6595
- Firefox fires the event, and sets ctrlKey = true
......
......@@ -50,11 +50,9 @@ MochiKit.Style.toString = function () {
MochiKit.Style.EXPORT_OK = [];
MochiKit.Style.EXPORT = [
'setOpacity',
'getOpacity',
'setStyle',
'getStyle', // temporary
'computedStyle',
'setOpacity',
'getStyle',
'getElementDimensions',
'elementDimensions', // deprecated
'setElementDimensions',
......@@ -115,62 +113,38 @@ MochiKit.Style.Coordinates.prototype.toString = function () {
MochiKit.Base.update(MochiKit.Style, {
/** @id MochiKit.Style.computedStyle */
computedStyle: function (elem, cssProperty) {
/** @id MochiKit.Style.getStyle */
getStyle: function (elem, style) {
var dom = MochiKit.DOM;
var d = dom._document;
elem = dom.getElement(elem);
cssProperty = MochiKit.Base.camelize(cssProperty);
style = MochiKit.Base.camelize(style);
if (!elem || elem == d) {
return undefined;
}
/* from YUI 0.10.0 */
if (cssProperty == 'opacity' && elem.filters) { // IE opacity
try {
return elem.filters.item('DXImageTransform.Microsoft.Alpha'
).opacity / 100;
} catch(e) {
try {
return elem.filters.item('alpha').opacity / 100;
} catch(e) {}
if (style == 'opacity' && elem.filters) {
var opacity;
if (opacity = (MochiKit.Style.getStyle(elem, 'filter') || '').match(/alpha\(opacity=(.*)\)/)) {
if (opacity[1]) {
return parseFloat(opacity[1]) / 100;
}
}
return 1.0;
}
if (elem.currentStyle) {
return elem.currentStyle[cssProperty];
}
if (typeof(d.defaultView) == 'undefined') {
return undefined;
}
if (d.defaultView === null) {
return undefined;
}
var style = d.defaultView.getComputedStyle(elem, null);
if (typeof(style) == 'undefined' || style === null) {
return undefined;
}
var selectorCase = cssProperty.replace(/([A-Z])/g, '-$1'
).toLowerCase(); // from dojo.style.toSelectorCase
return style.getPropertyValue(selectorCase);
},
/** @id MochiKit.Style.getStyle */
getStyle: function (elem, style) {
elem = MochiKit.DOM.getElement(elem);
var value = elem.style[MochiKit.Base.camelize(style)];
var value = elem.style[style];
if (!value) {
if (document.defaultView && document.defaultView.getComputedStyle) {
var css = document.defaultView.getComputedStyle(elem, null);
if (d.defaultView && d.defaultView.getComputedStyle) {
var css = d.defaultView.getComputedStyle(elem, null);
value = css ? css.getPropertyValue(style) : null;
} else if (elem.currentStyle) {
value = elem.currentStyle[MochiKit.Base.camelize(style)];
value = elem.currentStyle[style];
}
}
if (style == 'opacity') {
value = parseFloat(value);
}
if (/Opera/.test(navigator.userAgent) && (MochiKit.Base.find(['left', 'top', 'right', 'bottom'], style) != -1)) {
if (MochiKit.Style.getStyle(elem, 'position') == 'static') {
......@@ -185,42 +159,33 @@ MochiKit.Base.update(MochiKit.Style, {
setStyle: function (elem, style) {
elem = MochiKit.DOM.getElement(elem);
for (name in style) {
elem.style[MochiKit.Base.camelize(name)] = style[name];
}
},
/** @id MochiKit.Style.getOpacity */
getOpacity: function (elem) {
var opacity;
if (opacity = MochiKit.Style.getStyle(elem, 'opacity')) {
return parseFloat(opacity);
}
if (opacity = (MochiKit.Style.getStyle(elem, 'filter') || '').match(/alpha\(opacity=(.*)\)/)) {
if (opacity[1]) {
return parseFloat(opacity[1]) / 100;
if (name == 'opacity') {
MochiKit.Style.setOpacity(elem, style[name]);
} else {
elem.style[MochiKit.Base.camelize(name)] = style[name];
}
}
return 1.0;
},
/** @id MochiKit.Style.setOpacity */
setOpacity: function(elem, o) {
setOpacity: function (elem, o) {
elem = MochiKit.DOM.getElement(elem);
var self = MochiKit.Style;
if (o == 1) {
var toSet = /Gecko/.test(navigator.userAgent) && !(/Konqueror|Safari|KHTML/.test(navigator.userAgent));
self.setStyle(elem, {opacity: toSet ? 0.999999 : 1.0});
elem.style[name] = toSet ? 0.999999 : 1.0;
if (/MSIE/.test(navigator.userAgent)) {
self.setStyle(elem, {filter:
self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '')});
elem.style['filter'] =
self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '');
}
} else {
if (o < 0.00001) {
o = 0;
}
self.setStyle(elem, {opacity: o});
elem.style[name] = o;
if (/MSIE/.test(navigator.userAgent)) {
self.setStyle(elem,
{filter: self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + o * 100 + ')' });
elem.style['filter'] =
self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + o * 100 + ')';
}
}
},
......@@ -242,7 +207,7 @@ MochiKit.Base.update(MochiKit.Style, {
if (!elem ||
(!(elem.x && elem.y) &&
(!elem.parentNode == null ||
self.computedStyle(elem, 'display') == 'none'))) {
self.getStyle(elem, 'display') == 'none'))) {
return undefined;
}
......@@ -301,7 +266,7 @@ MochiKit.Base.update(MochiKit.Style, {
if ((typeof(opera) != 'undefined' &&
parseFloat(opera.version()) < 9) ||
(ua.indexOf('safari') != -1 &&
self.computedStyle(elem, 'position') == 'absolute')) {
self.getStyle(elem, 'position') == 'absolute')) {
c.x -= b.offsetLeft;
c.y -= b.offsetTop;
......@@ -368,7 +333,7 @@ MochiKit.Base.update(MochiKit.Style, {
if (!elem) {
return undefined;
}
var disp = self.computedStyle(elem, 'display');
var disp = self.getStyle(elem, 'display');
// display can be empty/undefined on WebKit/KHTML
if (disp != 'none' && disp != '' && typeof(disp) != 'undefined') {
return new self.Dimensions(elem.offsetWidth || 0,
......
......@@ -815,7 +815,7 @@ MochiKit.Base.update(MochiKit.Visual.Opacity.prototype, {
s.setStyle(this.element, {zoom: 1});
}
options = b.update({
from: s.getOpacity(this.element) || 0.0,
from: s.getStyle(this.element, 'opacity') || 0.0,
to: 1.0
}, options || {});
this.start(options);
......@@ -823,11 +823,11 @@ MochiKit.Base.update(MochiKit.Visual.Opacity.prototype, {
/** @id MochiKit.Visual.Opacity.prototype.update */
update: function (position) {
MochiKit.Style.setOpacity(this.element, position);
MochiKit.Style.setStyle(this.element, {'opacity': position});
}
});
/** @id MochiKit.Visual.Opacity.prototype.Move */
/** @id MochiKit.Visual.Move.prototype */
MochiKit.Visual.Move = function (element, options) {
var cls = arguments.callee;
if (!(this instanceof cls)) {
......@@ -1176,16 +1176,16 @@ MochiKit.Visual.fade = function (element, /* optional */ options) {
***/
var s = MochiKit.Style;
var oldOpacity = MochiKit.DOM.getElement(element).style.opacity || '';
var oldOpacity = s.getStyle(element, 'opacity');
options = MochiKit.Base.update({
from: s.getOpacity(element) || 1.0,
from: s.getStyle(element, 'opacity') || 1.0,
to: 0.0,
afterFinishInternal: function (effect) {
if (effect.options.to !== 0) {
return;
}
s.hideElement(effect.element);
s.setStyle(effect.element, {opacity: oldOpacity});
s.setStyle(effect.element, {'opacity': oldOpacity});
}
}, options || {});
return new MochiKit.Visual.Opacity(element, options);
......@@ -1204,14 +1204,14 @@ MochiKit.Visual.appear = function (element, /* optional */ options) {
var v = MochiKit.Visual;
options = MochiKit.Base.update({
from: (s.getStyle(element, 'display') == 'none' ? 0.0 :
s.getOpacity(element) || 0.0),
s.getStyle(element, 'opacity') || 0.0),
to: 1.0,
// force Safari to render floated elements properly
afterFinishInternal: function (effect) {
v.forceRerendering(effect.element);
},
beforeSetupInternal: function (effect) {
s.setOpacity(effect.element, effect.options.from);
s.setStyle(effect.element, {'opacity': effect.options.from});
s.showElement(effect.element);
}
}, options || {});
......@@ -1229,12 +1229,12 @@ MochiKit.Visual.puff = function (element, /* optional */ options) {
var v = MochiKit.Visual;
element = MochiKit.DOM.getElement(element);
var oldStyle = {
opacity: element.style.opacity || '',
position: s.getStyle(element, 'position'),
top: element.style.top,
left: element.style.left,
width: element.style.width,
height: element.style.height
height: element.style.height,
opacity: s.getStyle(element, 'opacity')
};
options = MochiKit.Base.update({
beforeSetupInternal: function (effect) {
......@@ -1316,7 +1316,7 @@ MochiKit.Visual.switchOff = function (element, /* optional */ options) {
***/
var d = MochiKit.DOM;
element = d.getElement(element);
var oldOpacity = element.style.opacity || '';
var oldOpacity = MochiKit.Style.getStyle(element, 'opacity');
var elemClip;
var options = MochiKit.Base.update({
duration: 0.3,
......@@ -1332,7 +1332,7 @@ MochiKit.Visual.switchOff = function (element, /* optional */ options) {
MochiKit.Style.hideElement(effect.element);
d.undoClipping(effect.element, elemClip);
d.undoPositioned(effect.element);
MochiKit.Style.setStyle(effect.element, {opacity: oldOpacity});
MochiKit.Style.setStyle(effect.element, {'opacity': oldOpacity});
}
}, options || {});
var v = MochiKit.Visual;
......@@ -1359,7 +1359,7 @@ MochiKit.Visual.dropOut = function (element, /* optional */ options) {
var oldStyle = {
top: s.getStyle(element, 'top'),
left: s.getStyle(element, 'left'),
opacity: element.style.opacity || ''
opacity: s.getStyle(element, 'opacity')
};
options = MochiKit.Base.update({
......@@ -1575,7 +1575,7 @@ MochiKit.Visual.grow = function (element, /* optional */ options) {
left: element.style.left,
height: element.style.height,
width: element.style.width,
opacity: element.style.opacity || ''
opacity: s.getStyle(element, 'opacity')
};
var dims = s.getElementDimensions(element);
......@@ -1677,7 +1677,7 @@ MochiKit.Visual.shrink = function (element, /* optional */ options) {
left: element.style.left,
height: element.style.height,
width: element.style.width,
opacity: element.style.opacity || ''
opacity: s.getStyle(element, 'opacity')
};
var dims = s.getElementDimensions(element);
......@@ -1745,12 +1745,12 @@ MochiKit.Visual.pulsate = function (element, /* optional */ options) {
var d = MochiKit.DOM;
var v = MochiKit.Visual;
var b = MochiKit.Base;
var oldOpacity = d.getElement(element).style.opacity || '';
var oldOpacity = MochiKit.Style.getStyle(element, 'opacity');
options = b.update({
duration: 3.0,
from: 0,
afterFinishInternal: function (effect) {
MochiKit.Style.setStyle(effect.element, {opacity: oldOpacity});
MochiKit.Style.setStyle(effect.element, {'opacity': oldOpacity});
}
}, options || {});
var transition = options.transition || v.Transitions.sinoidal;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment