Skip to content

Instantly share code, notes, and snippets.

View RStankov's full-sized avatar
🤖
👨‍💻

Radoslav Stankov RStankov

🤖
👨‍💻
View GitHub Profile
(function(){
function delegateHandler(e){
((this.retrieve('prototype_delegates') || $H()).get(e.eventName || e.type) || []).each(function(pair){
if (element = e.findElement(pair.key)){
pair.value.invoke('call', element, e, element);
}
});
}
function delegate(element, selector, event, handler){
String.prototype.namespace = function(objects, scope){
scope = scope || window;
this.split('.').each(function(name){
if (Object.isUndefined(scope[name])) scope[name] = {};
scope = scope[name];
});
if (objects) Object.extent(scope, objects);
return scope;
}
// used for setting css styles
// example:
// setCssRule('tag-name', {display: none});
function setCssRule(selector, styles){
var i, x, sheet, rules;
for (x = document.styleSheets.length - 1; 0 <= x ; x--){
sheet = document.styleSheets[x];
rules = sheet.cssRules || sheet.rules;
Element.addMethods({
unsetStorage: function(element){
if (!(element = $(element))) return;
if (element === window){
delete(Element.Storage[0]);
} else if (typeof element._prototypeUID !== "undefined") {
var uid = element._prototypeUID[0];
if (uid in Element.Storage)
delete(Element.Storage[uid]);
// credits to YUI ( http://developer.yahoo.com/yui/ )
// credits to kangax ( Juriy Zaytsev http://thinkweb2.com/projects/prototype/ )
var fire = (function(){
var mouseEvent = /^(click|dblclick|mouseover|mouseout|mousedown|mouseup|mousemove|mouseenter|mouseleave|contextmenu)$/,
keyEvent = /^(keydown|keyup|keypress)$/;
var defaultOptions = {
event: {
bubbles: true,
cancelable: true,
/*
* Usage:
* Code:
* var Widget = Class.create({
* initialize: function(){
* this.overlay = new Element('div', {className: 'overlay'});
* this.frame = new Element('div', {className: 'frame'});
* this.header = new Element('header');
* this.title = new Element('h2');
* this.section = new Element('section');
<!DOCTYPE html>
<html>
<head>
<title>Github - participation graph</title>
</head>
<body>
<script src="http://www.prototypejs.org/assets/2009/6/16/prototype.js" type="text/javascript"></script>
<script>
var GHPG = Class.create({
initialize: function(data){
// Lazy loading function
Function.prototype.lazyLoad = function(){
var __method = this;
function loaded(){
loaded = __method();
delete(__method);
return loaded.apply(this, arguments);
};
return function(){
(function(){
function focusInHandler(e){
Event.findElement(e).fire("focus:in");
}
function focusOutHandler(e){
Event.findElement(e).fire("focus:out");
}
if (document.addEventListener){
document.addEventListener("focus", focusInHandler, true);
/*
* $(element).insert({ into: document.body });
*/
Element._insertionTranslations.into = function(element, node){
node.appendChild(element);
};
/*
* $(element).insert({ instead: element2 })