Few micro changes and optimizations from various authors #2

Open
wants to merge 8 commits into
from
View
@@ -34,7 +34,9 @@ Protolicious is a set of javascript snippets based on prototype.js (and other ra
== Array extensions
* <tt>Array#sum</tt>
-* <tt>Array#namespace</tt>
+* <tt>Array#clone</tt>
+* <tt>Array#isUnique</tt>
+* <tt>Array#sliceNonUnique</tt>
== Field (Form.Element.Methods) extensions
@@ -69,4 +71,4 @@ Protolicious is a set of javascript snippets based on prototype.js (and other ra
= License
-protolicious is licensed under the terms of the MIT license
+protolicious is licensed under the terms of the MIT license
View
@@ -1,11 +1,7 @@
/*
-Modified version of Cookie module from Livepipe.net by Ryan Johnson
-(mostly "fix" few variables being declared globally + minor rearrangements)
-
-Original version:
-http://livepipe.net/downloads/prototype.tidbits.1.7.0.js
-
+Modified version of Cookie module
+by Victor Homyakov ( http://github.com/victor-homyakov )
*/
var Cookie = {
@@ -19,17 +15,11 @@ var Cookie = {
document.cookie = name + "=" + value + expiry + "; path=/";
},
get: function(name) {
- var nameEQ = name + "=", ca = document.cookie.split(';');
- for (var i=0, c; i < ca.length; i++) {
- c = ca[i];
- while (c.charAt(0) == ' ')
- c = c.substring(1, c.length);
- if (c.indexOf(nameEQ) == 0)
- return c.substring(nameEQ.length, c.length);
- }
- return null;
+ var cookies = document.cookie.split(/;\s*/);
+ var nameEQ = name + "=", c = cookies.find(function(s){return s.startsWith(nameEQ);});
+ return c? c.substr(nameEQ.length) : null;
},
unset: function(name) {
Cookie.set(name, '', -1);
}
-}
+}
View
@@ -410,4 +410,21 @@ Element.Methods.vToggle = function(element, options) {
}));
};
-Element.addMethods();
+/**
+*Element#centerInParent(@element) -> @element
+*Centers element in parent element. Element should be absoltely positioned
+*Parent should have defined dimentions and should be relatively positioned
+*
+**/
+Element.Methods.centerInParent = function(element){
+ element=$(element);
+ var parEleDim = Element.getDimensions(element.up(0));
+ var elDim = Element.getDimensions(element);
+ element.setStyle({
+ left: (parEleDim.width - elDim.width)/2 + 'px',
+ top: (parEleDim.height - elDim.height)/2 + 'px'
+ });
+ return element;
+}
+
+Element.addMethods();
View
@@ -2,12 +2,12 @@
// Fires hash:changed event when document.location.hash changes
// oldValue and newValue are passed as properties of event's memo
-(function(){
- var loc = document.location, hash = loc.hash;
- this.setInterval(function(){
- if (loc.hash != current) {
- document.fire('hash:changed', { oldValue: current, newValue: loc.hash })
- current = loc.hash;
- }
- }, 200)
-})().call(null)
+(function() {
+ var loc = document.location, current = loc.hash;
+ setInterval(function() {
+ if (loc.hash != current) {
+ document.fire('hash:changed', { oldValue: current, newValue: loc.hash })
+ current = loc.hash;
+ }
+ }, 200)
+})()