Skip to content

Commit

Permalink
Update to Prototype 1.5.2_rc0 r7048. Fixes a rendering issue with opa…
Browse files Browse the repository at this point in the history
…city-based effects and floating elements on Safari.

git-svn-id: http://svn.rubyonrails.org/rails/spinoffs/scriptaculous@7049 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
madrobby committed Jun 17, 2007
1 parent 58c1873 commit 86d62cf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Update to Prototype 1.5.2_rc0 r7048. Fixes a rendering issue with opacity-based effects and floating elements on Safari.

* Mild refactoring of sound.js to take advantage of new Prototype features.

* Add highlight element method as a shortcut to Effect.Highlight.
Expand Down
50 changes: 39 additions & 11 deletions lib/prototype.js
Expand Up @@ -24,8 +24,8 @@ var Prototype = {
document.createElement('form').__proto__)
},

ScriptFragment: '<script[^>]*>([\u0001-\uFFFF]*?)<\/script>',
JSONFilter: /^\/\*-secure-\s*(.*)\s*\*\/\s*$/,
ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,

emptyFunction: function() { },
K: function(x) { return x }
Expand Down Expand Up @@ -373,11 +373,15 @@ Object.extend(String.prototype, {
return this.sub(filter || Prototype.JSONFilter, '#{1}');
},

isJSON: function() {
var str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
},

evalJSON: function(sanitize) {
var json = this.unfilterJSON();
try {
if (!sanitize || (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(json)))
return eval('(' + json + ')');
if (!sanitize || json.isJSON()) return eval('(' + json + ')');
} catch (e) { }
throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
},
Expand Down Expand Up @@ -872,6 +876,13 @@ Object.extend(Hash.prototype, {
return this.pluck('value');
},

index: function(value) {
var match = this.detect(function(pair) {
return pair.value === value;
});
return match && match.key;
},

merge: function(hash) {
return $H(hash).inject(this, function(mergedHash, pair) {
mergedHash[pair.key] = pair.value;
Expand Down Expand Up @@ -2080,6 +2091,23 @@ else if (Prototype.Browser.Gecko) {
}

else if (Prototype.Browser.WebKit) {
Element.Methods.setOpacity = function(element, value) {
element = $(element);
element.style.opacity = (value == 1 || value === '') ? '' :
(value < 0.00001) ? 0 : value;

if (value == 1)
if(element.tagName == 'IMG' && element.width) {
element.width++; element.width--;
} else try {
var n = document.createTextNode(' ');
element.appendChild(n);
element.removeChild(n);
} catch (e) {}

return element;
}

// Safari returns margins on body which is incorrect if the child is absolutely
// positioned. For performance reasons, redefine Position.cumulativeOffset for
// KHTML/WebKit only.
Expand Down Expand Up @@ -2197,6 +2225,13 @@ Element.Methods.ByTag = {};

Object.extend(Element, Element.Methods);

if (!Prototype.BrowserFeatures.ElementExtensions &&
document.createElement('div').__proto__) {
window.HTMLElement = {};
window.HTMLElement.prototype = document.createElement('div').__proto__;
Prototype.BrowserFeatures.ElementExtensions = true;
}

Element.extend = (function() {
if (Prototype.BrowserFeatures.SpecificElementExtensions)
return Prototype.K;
Expand Down Expand Up @@ -2236,13 +2271,6 @@ Element.extend = (function() {
return extend;
})();

if (!Prototype.BrowserFeatures.ElementExtensions &&
document.createElement('div').__proto__) {
window.HTMLElement = {};
window.HTMLElement.prototype = document.createElement('div').__proto__;
Prototype.BrowserFeatures.ElementExtensions = true;
}

Element.hasAttribute = function(element, attribute) {
if (element.hasAttribute) return element.hasAttribute(attribute);
return Element.Methods.Simulated.hasAttribute(element, attribute);
Expand Down
12 changes: 10 additions & 2 deletions test/functional/effects_float_appear_test.html
Expand Up @@ -15,7 +15,11 @@ <h1>script.aculo.us functional test file</h1>
</p>

<a href="#" onclick="Effect.Appear('float_div_left'); return false;">float:left</a> |
<a href="#" onclick="Effect.Appear('float_div_right'); return false;">float:right</a>
<a href="#" onclick="Effect.Appear('float_div_right'); return false;">float:right</a> |
<a href="#" onclick="$('float_div_right').setOpacity(1)">float:right (setOpacity 1)</a> |
<a href="#" onclick="Effect.Appear('icon'); return false;">image (non-floating)</a> |
<a href="#" onclick="Effect.Appear('float_icon'); return false;">image (floating)</a> |
<a href="#" onclick="$('float_icon').setOpacity(1);">image (setOpacity 1)</a>

<hr/>

Expand All @@ -26,13 +30,17 @@ <h1>script.aculo.us functional test file</h1>
ut labore et dolore magna aliqua.
</div>

<div id="float_div_right" style="float:right;display:none">
<div id="float_div_right" style="float:right;opacity:0.4">
Lorem ipsum dolor sit amet,<br/>
consectetur adipisicing elit,<br/>
sed do eiusmod tempor incididunt<br/>
ut labore et dolore magna aliqua.
</div>

<img id="icon" src="icon.png" style="display:none" alt="" />

<img id="float_icon" src="icon.png" style="float:left;opacity:0.4" alt="" />


</body>
</html>

0 comments on commit 86d62cf

Please sign in to comment.