Alice
view release on metacpan or search on metacpan
share/static/alice.js view on Meta::CPAN
/* Prototype JavaScript framework, version 1.7
* (c) 2005-2010 Sam Stephenson
*
* Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://www.prototypejs.org/
*
*--------------------------------------------------------------------------*/
var Prototype = {
Version: '1.7',
Browser: (function(){
var ua = navigator.userAgent;
var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
return {
IE: !!window.attachEvent && !isOpera,
Opera: isOpera,
WebKit: ua.indexOf('AppleWebKit/') > -1,
Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
MobileSafari: /Apple.*Mobile/.test(ua)
}
})(),
BrowserFeatures: {
XPath: !!document.evaluate,
SelectorsAPI: !!document.querySelector,
ElementExtensions: (function() {
var constructor = window.Element || window.HTMLElement;
return !!(constructor && constructor.prototype);
})(),
SpecificElementExtensions: (function() {
if (typeof window.HTMLDivElement !== 'undefined')
return true;
var div = document.createElement('div'),
form = document.createElement('form'),
isSupported = false;
if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) {
isSupported = true;
}
div = form = null;
return isSupported;
})()
},
ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
emptyFunction: function() { },
K: function(x) { return x }
};
if (Prototype.Browser.MobileSafari)
Prototype.BrowserFeatures.SpecificElementExtensions = false;
share/static/alice.js view on Meta::CPAN
},
_getEv: (function(){
var el = document.createElement('div'), f;
el.onclick = Prototype.emptyFunction;
var value = el.getAttribute('onclick');
if (String(value).indexOf('{') > -1) {
f = function(element, attribute) {
attribute = element.getAttribute(attribute);
if (!attribute) return null;
attribute = attribute.toString();
attribute = attribute.split('{')[1];
attribute = attribute.split('}')[0];
return attribute.strip();
};
}
else if (value === '') {
f = function(element, attribute) {
attribute = element.getAttribute(attribute);
if (!attribute) return null;
return attribute.strip();
};
}
el = null;
return f;
})(),
_flag: function(element, attribute) {
return $(element).hasAttribute(attribute) ? attribute : null;
},
style: function(element) {
return element.style.cssText.toLowerCase();
},
title: function(element) {
return element.title;
}
}
}
}
})();
Element._attributeTranslations.write = {
names: Object.extend({
cellpadding: 'cellPadding',
cellspacing: 'cellSpacing'
}, Element._attributeTranslations.read.names),
values: {
checked: function(element, value) {
element.checked = !!value;
},
style: function(element, value) {
element.style.cssText = value ? value : '';
}
}
};
Element._attributeTranslations.has = {};
$w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
'encType maxLength readOnly longDesc frameBorder').each(function(attr) {
Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
Element._attributeTranslations.has[attr.toLowerCase()] = attr;
});
(function(v) {
Object.extend(v, {
href: v._getAttr2,
src: v._getAttr2,
type: v._getAttr,
action: v._getAttrNode,
disabled: v._flag,
checked: v._flag,
readonly: v._flag,
multiple: v._flag,
onload: v._getEv,
onunload: v._getEv,
onclick: v._getEv,
ondblclick: v._getEv,
onmousedown: v._getEv,
onmouseup: v._getEv,
onmouseover: v._getEv,
onmousemove: v._getEv,
onmouseout: v._getEv,
onfocus: v._getEv,
onblur: v._getEv,
onkeypress: v._getEv,
onkeydown: v._getEv,
onkeyup: v._getEv,
onsubmit: v._getEv,
onreset: v._getEv,
onselect: v._getEv,
onchange: v._getEv
});
})(Element._attributeTranslations.read.values);
if (Prototype.BrowserFeatures.ElementExtensions) {
(function() {
function _descendants(element) {
var nodes = element.getElementsByTagName('*'), results = [];
for (var i = 0, node; node = nodes[i]; i++)
if (node.tagName !== "!") // Filter out comment nodes.
results.push(node);
return results;
}
Element.Methods.down = function(element, expression, index) {
element = $(element);
if (arguments.length == 1) return element.firstDescendant();
return Object.isNumber(expression) ? _descendants(element)[expression] :
Element.select(element, expression)[index || 0];
}
})();
}
}
else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
Element.Methods.setOpacity = function(element, value) {
element = $(element);
element.style.opacity = (value == 1) ? 0.999999 :
share/static/alice.js view on Meta::CPAN
return this.instances.get(queueName) ||
this.instances.set(queueName, new Effect.ScopedQueue());
}
};
Effect.Queue = Effect.Queues.get('global');
Effect.Base = Class.create({
position: null,
start: function(options) {
if (options && options.transition === false) options.transition = Effect.Transitions.linear;
this.options = Object.extend(Object.extend({ },Effect.DefaultOptions), options || { });
this.currentFrame = 0;
this.state = 'idle';
this.startOn = this.options.delay*1000;
this.finishOn = this.startOn+(this.options.duration*1000);
this.fromToDelta = this.options.to-this.options.from;
this.totalTime = this.finishOn-this.startOn;
this.totalFrames = this.options.fps*this.options.duration;
this.render = (function() {
function dispatch(effect, eventName) {
if (effect.options[eventName + 'Internal'])
effect.options[eventName + 'Internal'](effect);
if (effect.options[eventName])
effect.options[eventName](effect);
}
return function(pos) {
if (this.state === "idle") {
this.state = "running";
dispatch(this, 'beforeSetup');
if (this.setup) this.setup();
dispatch(this, 'afterSetup');
}
if (this.state === "running") {
pos = (this.options.transition(pos) * this.fromToDelta) + this.options.from;
this.position = pos;
dispatch(this, 'beforeUpdate');
if (this.update) this.update(pos);
dispatch(this, 'afterUpdate');
}
};
})();
this.event('beforeStart');
if (!this.options.sync)
Effect.Queues.get(Object.isString(this.options.queue) ?
'global' : this.options.queue.scope).add(this);
},
loop: function(timePos) {
if (timePos >= this.startOn) {
if (timePos >= this.finishOn) {
this.render(1.0);
this.cancel();
this.event('beforeFinish');
if (this.finish) this.finish();
this.event('afterFinish');
return;
}
var pos = (timePos - this.startOn) / this.totalTime,
frame = (pos * this.totalFrames).round();
if (frame > this.currentFrame) {
this.render(pos);
this.currentFrame = frame;
}
}
},
cancel: function() {
if (!this.options.sync)
Effect.Queues.get(Object.isString(this.options.queue) ?
'global' : this.options.queue.scope).remove(this);
this.state = 'finished';
},
event: function(eventName) {
if (this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
if (this.options[eventName]) this.options[eventName](this);
},
inspect: function() {
var data = $H();
for(property in this)
if (!Object.isFunction(this[property])) data.set(property, this[property]);
return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';
}
});
Effect.Parallel = Class.create(Effect.Base, {
initialize: function(effects) {
this.effects = effects || [];
this.start(arguments[1]);
},
update: function(position) {
this.effects.invoke('render', position);
},
finish: function(position) {
this.effects.each( function(effect) {
effect.render(1.0);
effect.cancel();
effect.event('beforeFinish');
if (effect.finish) effect.finish(position);
effect.event('afterFinish');
});
}
});
Effect.Tween = Class.create(Effect.Base, {
initialize: function(object, from, to) {
object = Object.isString(object) ? $(object) : object;
var args = $A(arguments), method = args.last(),
options = args.length == 5 ? args[3] : null;
this.method = Object.isFunction(method) ? method.bind(object) :
Object.isFunction(object[method]) ? object[method].bind(object) :
function(value) { object[method] = value };
this.start(Object.extend({ from: from, to: to }, options || { }));
},
update: function(position) {
this.method(position);
}
});
Effect.Event = Class.create(Effect.Base, {
initialize: function() {
this.start(Object.extend({ duration: 0 }, arguments[0] || { }));
},
update: Prototype.emptyFunction
share/static/alice.js view on Meta::CPAN
shortcut_combination = shortcut_combination.toLowerCase();
var binding = this.all_shortcuts[shortcut_combination];
delete(this.all_shortcuts[shortcut_combination])
if(!binding) return;
var type = binding['event'];
var ele = binding['target'];
var callback = binding['callback'];
if(ele.detachEvent) ele.detachEvent('on'+type, callback);
else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
else ele['on'+type] = false;
}
};
function str_repeat(i, m) {
for (var o = []; m > 0; o[--m] = i);
return o.join('');
}
function sprintf() {
var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
while (f) {
if (m = /^[^\x25]+/.exec(f)) {
o.push(m[0]);
}
else if (m = /^\x25{2}/.exec(f)) {
o.push('%');
}
else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
throw('Too few arguments.');
}
if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
throw('Expecting number but found ' + typeof(a));
}
switch (m[7]) {
case 'b': a = a.toString(2); break;
case 'c': a = String.fromCharCode(a); break;
case 'd': a = parseInt(a); break;
case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
case 'o': a = a.toString(8); break;
case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
case 'u': a = Math.abs(a); break;
case 'x': a = a.toString(16); break;
case 'X': a = a.toString(16).toUpperCase(); break;
}
a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a);
c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
x = m[5] - String(a).length - s.length;
p = m[5] ? str_repeat(c, x) : '';
o.push(s + (m[4] ? a + p : p + a));
}
else {
throw('Huh ?!');
}
f = f.substring(m[0].length);
}
return o.join('');
}
/* WysiHat - WYSIWYG JavaScript framework, version 0.2.1
* (c) 2008-2010 Joshua Peek
*
* WysiHat is freely distributable under the terms of an MIT-style license.
*--------------------------------------------------------------------------*/
var WysiHat = {};
WysiHat.Editor = {
attach: function(textarea) {
var editArea;
textarea = $(textarea);
var id = textarea.id + '_editor';
if (editArea = $(id)) return editArea;
editArea = new Element('div', {
'id': id,
'class': 'editor',
'contentEditable': 'true'
});
editArea.update(WysiHat.Formatting.getBrowserMarkupFrom(textarea.value));
Object.extend(editArea, WysiHat.Commands);
textarea.insert({before: editArea});
textarea.hide();
return editArea;
}
};
WysiHat.BrowserFeatures = (function() {
function createTmpIframe(callback) {
var frame, frameDocument;
frame = new Element('iframe');
frame.setStyle({
position: 'absolute',
left: '-1000px'
});
frame.onFrameLoaded(function() {
if (typeof frame.contentDocument !== 'undefined') {
frameDocument = frame.contentDocument;
} else if (typeof frame.contentWindow !== 'undefined' && typeof frame.contentWindow.document !== 'undefined') {
frameDocument = frame.contentWindow.document;
}
frameDocument.designMode = 'on';
callback(frameDocument);
frame.remove();
});
$(document.body).insert(frame);
}
var features = {};
function detectParagraphType(document) {
document.body.innerHTML = '';
document.execCommand('insertparagraph', false, null);
var tagName;
element = document.body.childNodes[0];
if (element && element.tagName)
tagName = element.tagName.toLowerCase();
if (tagName == 'div')
features.paragraphType = "div";
else if (document.body.innerHTML == "<p><br></p>")
features.paragraphType = "br";
else
features.paragraphType = "p";
}
function detectIndentType(document) {
document.body.innerHTML = 'tab';
document.execCommand('indent', false, null);
var tagName;
element = document.body.childNodes[0];
if (element && element.tagName)
tagName = element.tagName.toLowerCase();
features.indentInsertsBlockquote = (tagName == 'blockquote');
}
features.run = function run() {
if (features.finished) return;
createTmpIframe(function(document) {
detectParagraphType(document);
detectIndentType(document);
features.finished = true;
});
}
return features;
})();
/* IE Selection and Range classes
*
* Original created by Tim Cameron Ryan
* http://github.com/timcameronryan/IERange
* Copyright (c) 2009 Tim Cameron Ryan
* Released under the MIT/X License
*
* Modified by Joshua Peek
*/
if (!window.getSelection) {
var DOMUtils = {
isDataNode: function(node) {
try {
return node && node.nodeValue !== null && node.data !== null;
} catch (e) {
return false;
}
},
isAncestorOf: function(parent, node) {
if (!parent) return false;
return !DOMUtils.isDataNode(parent) &&
(parent.contains(DOMUtils.isDataNode(node) ? node.parentNode : node) ||
node.parentNode == parent);
},
isAncestorOrSelf: function(root, node) {
return DOMUtils.isAncestorOf(root, node) || root == node;
},
findClosestAncestor: function(root, node) {
if (DOMUtils.isAncestorOf(root, node))
while (node && node.parentNode != root)
node = node.parentNode;
return node;
},
getNodeLength: function(node) {
return DOMUtils.isDataNode(node) ? node.length : node.childNodes.length;
},
splitDataNode: function(node, offset) {
if (!DOMUtils.isDataNode(node))
return false;
var newNode = node.cloneNode(false);
node.deleteData(offset, node.length);
newNode.deleteData(0, offset);
node.parentNode.insertBefore(newNode, node.nextSibling);
}
};
window.Range = (function() {
function Range(document) {
this._document = document;
this.startContainer = this.endContainer = document.body;
share/static/alice.js view on Meta::CPAN
case Node.COMMENT_NODE:
parentNode.removeChild(node);
}
}
Element.addMethods({
sanitizeContents: function(element, options) {
element = $(element);
var tagsToRemove = {};
(options.remove || "").split(",").each(function(tagName) {
tagsToRemove[tagName.strip()] = true;
});
var tagsToAllow = {};
(options.allow || "").split(",").each(function(selector) {
var parts = selector.strip().split(/[\[\]]/);
var tagName = parts[0], allowedAttributes = parts.slice(1).grep(/./);
tagsToAllow[tagName] = allowedAttributes;
});
var tagsToSkip = options.skip;
withEachChildNodeOf(element, function(childNode) {
sanitizeNode(childNode, tagsToRemove, tagsToAllow, tagsToSkip);
});
return element;
}
});
})();
(function() {
function onReadyStateComplete(document, callback) {
var handler;
function checkReadyState() {
if (document.readyState === 'complete') {
if (handler) handler.stop();
callback();
return true;
} else {
return false;
}
}
handler = Element.on(document, 'readystatechange', checkReadyState);
checkReadyState();
}
function observeFrameContentLoaded(element) {
element = $(element);
var loaded, contentLoadedHandler;
loaded = false;
function fireFrameLoaded() {
if (loaded) return;
loaded = true;
if (contentLoadedHandler) contentLoadedHandler.stop();
element.fire('frame:loaded');
}
if (window.addEventListener) {
contentLoadedHandler = document.on("DOMFrameContentLoaded", function(event) {
if (element == event.element())
fireFrameLoaded();
});
}
element.on('load', function() {
var frameDocument;
if (typeof element.contentDocument !== 'undefined') {
frameDocument = element.contentDocument;
} else if (typeof element.contentWindow !== 'undefined' && typeof element.contentWindow.document !== 'undefined') {
frameDocument = element.contentWindow.document;
}
onReadyStateComplete(frameDocument, fireFrameLoaded);
});
return element;
}
function onFrameLoaded(element, callback) {
element.on('frame:loaded', callback);
element.observeFrameContentLoaded();
}
Element.addMethods({
observeFrameContentLoaded: observeFrameContentLoaded,
onFrameLoaded: onFrameLoaded
});
})();
document.on("dom:loaded", function() {
if ('selection' in document && 'onselectionchange' in document) {
var selectionChangeHandler = function() {
var range = document.selection.createRange();
var element = range.parentElement();
$(element).fire("selection:change");
}
document.on("selectionchange", selectionChangeHandler);
} else {
var previousRange;
var selectionChangeHandler = function() {
var element = document.activeElement;
var elementTagName = element.tagName.toLowerCase();
if (elementTagName == "textarea" || elementTagName == "input") {
previousRange = null;
$(element).fire("selection:change");
} else {
var selection = window.getSelection();
if (selection.rangeCount < 1) return;
var range = selection.getRangeAt(0);
if (range && range.equalRange(previousRange)) return;
previousRange = range;
element = range.commonAncestorContainer;
while (element.nodeType == Node.TEXT_NODE)
element = element.parentNode;
$(element).fire("selection:change");
}
};
document.on("mouseup", selectionChangeHandler);
document.on("keyup", selectionChangeHandler);
}
});
WysiHat.Formatting = (function() {
var ACCUMULATING_LINE = {};
var EXPECTING_LIST_ITEM = {};
var ACCUMULATING_LIST_ITEM = {};
return {
getBrowserMarkupFrom: function(applicationMarkup) {
var container = new Element("div").update(applicationMarkup);
function spanify(element, style) {
element.replace(
'<span style="' + style +
'" class="Apple-style-span">' +
( run in 0.946 second using v1.01-cache-2.11-cpan-df04353d9ac )