Alien-GvaScript
view release on metacpan or search on metacpan
src/protoExtensions.js view on Meta::CPAN
var min = offset - (container.clientHeight * (100-percentage)/100);
var max = offset - (container.clientHeight * percentage/100);
if (container.scrollTop < min) container.scrollTop = min;
else if (container.scrollTop > max) container.scrollTop = max;
},
outerHTML: function(elem) {
var tag = elem.tagName;
if (!tag)
return elem; // not an element node
if (elem.outerHTML)
return elem.outerHTML; // has builtin implementation
else {
var attrs = elem.attributes;
var str = "<" + tag;
for (var i = 0; i < attrs.length; i++) {
var val = attrs[i].value;
var delim = val.indexOf('"') > -1 ? "'" : '"';
str += " " + attrs[i].name + "=" + delim + val + delim;
}
return str + ">" + elem.innerHTML + "</" + tag + ">";
}
}
});
Class.checkOptions = function(defaultOptions, ctorOptions) {
ctorOptions = ctorOptions || {}; // options passed to the class constructor
for (var property in ctorOptions) {
if (defaultOptions[property] === undefined)
throw new Error("unexpected option: " + property);
}
return Object.extend(Object.clone(defaultOptions), ctorOptions);
};
Object.extend(Event, {
detailedStop: function(event, toStop) {
if (toStop.preventDefault) {
if (event.preventDefault) event.preventDefault();
else event.returnValue = false;
}
if (toStop.stopPropagation) {
if (event.stopPropagation) event.stopPropagation();
else event.cancelBubble = true;
}
},
stopAll: {stopPropagation: true, preventDefault: true},
stopNone: {stopPropagation: false, preventDefault: false}
});
function ASSERT (cond, msg) {
if (!cond)
throw new Error("Violated assertion: " + msg);
}
// detects if a global CSS_PREFIX has been set
// if yes, use it to prefix the css classes
// default to gva
function CSSPREFIX () {
if(typeof CSS_PREFIX != 'undefined') {
return (CSS_PREFIX)? CSS_PREFIX : 'gva';
}
return 'gva';
}
/**
*
* Cross-Browser Split 1.0.1
* (c) Steven Levithan <stevenlevithan.com>; MIT License
* in order to fix a bug with String.prototype.split(RegExp) and Internet Explorer
* [http://blog.stevenlevithan.com/archives/cross-browser-split]
* An ECMA-compliant, uniform cross-browser split method
*
* */
var cbSplit;
// avoid running twice, which would break `cbSplit._nativeSplit`'s reference to the native `split`
if (!cbSplit) {
cbSplit = function (str, separator, limit) {
// if `separator` is not a regex, use the native `split`
if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
return cbSplit._nativeSplit.call(str, separator, limit);
}
var output = [],
lastLastIndex = 0,
flags = (separator.ignoreCase ? "i" : "") +
(separator.multiline ? "m" : "") +
(separator.sticky ? "y" : ""),
separator = RegExp(separator.source, flags + "g"), // make `global` and avoid `lastIndex` issues by working with a copy
separator2, match, lastIndex, lastLength;
str = str + ""; // type conversion
if (!cbSplit._compliantExecNpcg) {
separator2 = RegExp("^" + separator.source + "$(?!\\s)", flags); // doesn't need /g or /y, but they don't hurt
}
/* behavior for `limit`: if it's...
- `undefined`: no limit.
- `NaN` or zero: return an empty array.
- a positive number: use `Math.floor(limit)`.
- a negative number: no limit.
- other: type-convert, then use the above rules. */
if (limit === undefined || +limit < 0) {
limit = Infinity;
} else {
limit = Math.floor(+limit);
if (!limit) {
return [];
}
}
while (match = separator.exec(str)) {
lastIndex = match.index + match[0].length; // `separator.lastIndex` is not reliable cross-browser
if (lastIndex > lastLastIndex) {
output.push(str.slice(lastLastIndex, match.index));
// fix browsers whose `exec` methods don't consistently return `undefined` for nonparticipating capturing groups
if (!cbSplit._compliantExecNpcg && match.length > 1) {
match[0].replace(separator2, function () {
for (var i = 1; i < arguments.length - 2; i++) {
if (arguments[i] === undefined) {
match[i] = undefined;
}
}
});
}
if (match.length > 1 && match.index < str.length) {
Array.prototype.push.apply(output, match.slice(1));
}
lastLength = match[0].length;
lastLastIndex = lastIndex;
if (output.length >= limit) {
break;
}
}
if (separator.lastIndex === match.index) {
separator.lastIndex++; // avoid an infinite loop
}
}
if (lastLastIndex === str.length) {
if (lastLength || !separator.test("")) {
output.push("");
}
src/protoExtensions.js view on Meta::CPAN
var _selector = [ ], expr = selector.strip();
// instantiate Selector's
exprSplit(selector).each(function(s) { _selector.push(s) })
// store instantiated Selector for faster matching
if (!rules[observer_id][eventName][expr]) {
rules[observer_id][eventName][expr] = Object.extend([ ], { _selector: _selector });
}
// associate handler with expression
rules[observer_id][eventName][expr].push(handler);
}
// unregistering an event on an elemment
Event.unregister = function(elt, selector, eventName) {
var _id = (typeof elt == 'string')? elt :
(elt.identify)? elt.identify() : 'document';
// unregister event identified by name and selector
if (eventName) {
rules[_id][eventName][selector] = null;
delete rules[_id][eventName][selector];
}
else {
for (var eventName in rules[_id]) {
// unregister all events identified by selector
if(selector) {
rules[_id][eventName][selector] = null;
delete rules[_id][eventName][selector];
}
// unregister all events
else {
rules[_id][eventName] = null;
delete rules[_id][eventName];
}
}
}
},
// unregister *all* events registered using
// the Event.register method
Event.unregisterAll = function() {
for(var _id in rules) {
Event.unregister(_id);
delete rules[_id];
}
}
Event.observe(window, 'unload', Event.unregisterAll);
document.register = Event.register.curry(document);
Element.addMethods({register: Event.register, unregister: Event.unregister});
})();
// based on:
// getJSON function by Juriy Zaytsev
// http://github.com/kangax/protolicious/tree/master/get_json.js
(function(){
var id = 0, head = $$('head')[0];
Prototype.getJSON = function(url, callback) {
var script = document.createElement('script'), token = '__jsonp' + id;
// callback should be a global function
window[token] = callback;
// url should have "?2" parameter which is to be replaced with a global callback name
script.src = url.replace(/\?(&|$)/, '__jsonp' + id + '$1');
// clean up on load: remove script tag, null script variable and delete global callback function
script.onload = function() {
script.remove();
script = null;
delete window[token];
};
head.appendChild(script);
// callback name should be unique
id++;
}
})();
( run in 0.701 second using v1.01-cache-2.11-cpan-efa8479b9fe )