App-Alice
view release on metacpan or search on metacpan
share/static/alice.js view on Meta::CPAN
for (var i = 0, length = elements.length; i < length; i++) {
var element = elements[i];
if (match(element, expression)) {
results.push(Element.extend(element));
}
}
return results;
},
findElement: function(elements, expression, index) {
index = index || 0;
var matchIndex = 0, element;
for (var i = 0, length = elements.length; i < length; i++) {
element = elements[i];
if (Prototype.Selector.match(element, expression) && index === matchIndex++) {
return Element.extend(element);
}
}
},
findChildElements: function(element, expressions) {
var selector = expressions.toArray().join(', ');
return Prototype.Selector.select(selector, element || document);
}
});
})();
String.prototype.parseColor = function() {
var color = '#';
if (this.slice(0,4) == 'rgb(') {
var cols = this.slice(4,this.length-1).split(',');
var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
} else {
if (this.slice(0,1) == '#') {
if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
if (this.length==7) color = this.toLowerCase();
}
}
return (color.length==7 ? color : (arguments[0] || this));
};
/*--------------------------------------------------------------------------*/
Element.collectTextNodes = function(element) {
return $A($(element).childNodes).collect( function(node) {
return (node.nodeType==3 ? node.nodeValue :
(node.hasChildNodes() ? Element.collectTextNodes(node) : ''));
}).flatten().join('');
};
Element.collectTextNodesIgnoreClass = function(element, className) {
return $A($(element).childNodes).collect( function(node) {
return (node.nodeType==3 ? node.nodeValue :
((node.hasChildNodes() && !Element.hasClassName(node,className)) ?
Element.collectTextNodesIgnoreClass(node, className) : ''));
}).flatten().join('');
};
Element.setContentZoom = function(element, percent) {
element = $(element);
element.setStyle({fontSize: (percent/100) + 'em'});
if (Prototype.Browser.WebKit) window.scrollBy(0,0);
return element;
};
Element.getInlineOpacity = function(element){
return $(element).style.opacity || '';
};
Element.forceRerendering = function(element) {
try {
element = $(element);
var n = document.createTextNode(' ');
element.appendChild(n);
element.removeChild(n);
} catch(e) { }
};
/*--------------------------------------------------------------------------*/
var Effect = {
_elementDoesNotExistError: {
name: 'ElementDoesNotExistError',
message: 'The specified DOM element does not exist, but is required for this effect to operate'
},
Transitions: {
linear: Prototype.K,
sinoidal: function(pos) {
return (-Math.cos(pos*Math.PI)/2) + .5;
},
reverse: function(pos) {
return 1-pos;
},
flicker: function(pos) {
var pos = ((-Math.cos(pos*Math.PI)/4) + .75) + Math.random()/4;
return pos > 1 ? 1 : pos;
},
wobble: function(pos) {
return (-Math.cos(pos*Math.PI*(9*pos))/2) + .5;
},
pulse: function(pos, pulses) {
return (-Math.cos((pos*((pulses||5)-.5)*2)*Math.PI)/2) + .5;
},
spring: function(pos) {
return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6));
},
none: function(pos) {
return 0;
},
full: function(pos) {
return 1;
}
},
DefaultOptions: {
duration: 1.0, // seconds
fps: 100, // 100= assume 66fps max.
sync: false, // true for combining
from: 0.0,
to: 1.0,
delay: 0.0,
queue: 'parallel'
share/static/alice.js view on Meta::CPAN
this.start(options);
},
update: function(position) {
this.element.setOpacity(position);
}
});
Effect.Move = Class.create(Effect.Base, {
initialize: function(element) {
this.element = $(element);
if (!this.element) throw(Effect._elementDoesNotExistError);
var options = Object.extend({
x: 0,
y: 0,
mode: 'relative'
}, arguments[1] || { });
this.start(options);
},
setup: function() {
this.element.makePositioned();
this.originalLeft = parseFloat(this.element.getStyle('left') || '0');
this.originalTop = parseFloat(this.element.getStyle('top') || '0');
if (this.options.mode == 'absolute') {
this.options.x = this.options.x - this.originalLeft;
this.options.y = this.options.y - this.originalTop;
}
},
update: function(position) {
this.element.setStyle({
left: (this.options.x * position + this.originalLeft).round() + 'px',
top: (this.options.y * position + this.originalTop).round() + 'px'
});
}
});
Effect.MoveBy = function(element, toTop, toLeft) {
return new Effect.Move(element,
Object.extend({ x: toLeft, y: toTop }, arguments[3] || { }));
};
Effect.Scale = Class.create(Effect.Base, {
initialize: function(element, percent) {
this.element = $(element);
if (!this.element) throw(Effect._elementDoesNotExistError);
var options = Object.extend({
scaleX: true,
scaleY: true,
scaleContent: true,
scaleFromCenter: false,
scaleMode: 'box', // 'box' or 'contents' or { } with provided values
scaleFrom: 100.0,
scaleTo: percent
}, arguments[2] || { });
this.start(options);
},
setup: function() {
this.restoreAfterFinish = this.options.restoreAfterFinish || false;
this.elementPositioning = this.element.getStyle('position');
this.originalStyle = { };
['top','left','width','height','fontSize'].each( function(k) {
this.originalStyle[k] = this.element.style[k];
}.bind(this));
this.originalTop = this.element.offsetTop;
this.originalLeft = this.element.offsetLeft;
var fontSize = this.element.getStyle('font-size') || '100%';
['em','px','%','pt'].each( function(fontSizeType) {
if (fontSize.indexOf(fontSizeType)>0) {
this.fontSize = parseFloat(fontSize);
this.fontSizeType = fontSizeType;
}
}.bind(this));
this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
this.dims = null;
if (this.options.scaleMode=='box')
this.dims = [this.element.offsetHeight, this.element.offsetWidth];
if (/^content/.test(this.options.scaleMode))
this.dims = [this.element.scrollHeight, this.element.scrollWidth];
if (!this.dims)
this.dims = [this.options.scaleMode.originalHeight,
this.options.scaleMode.originalWidth];
},
update: function(position) {
var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
if (this.options.scaleContent && this.fontSize)
this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
},
finish: function(position) {
if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
},
setDimensions: function(height, width) {
var d = { };
if (this.options.scaleX) d.width = width.round() + 'px';
if (this.options.scaleY) d.height = height.round() + 'px';
if (this.options.scaleFromCenter) {
var topd = (height - this.dims[0])/2;
var leftd = (width - this.dims[1])/2;
if (this.elementPositioning == 'absolute') {
if (this.options.scaleY) d.top = this.originalTop-topd + 'px';
if (this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
} else {
if (this.options.scaleY) d.top = -topd + 'px';
if (this.options.scaleX) d.left = -leftd + 'px';
}
}
this.element.setStyle(d);
}
});
Effect.Highlight = Class.create(Effect.Base, {
initialize: function(element) {
this.element = $(element);
if (!this.element) throw(Effect._elementDoesNotExistError);
var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { });
this.start(options);
},
setup: function() {
if (this.element.getStyle('display')=='none') { this.cancel(); return; }
this.oldStyle = { };
if (!this.options.keepBackgroundImage) {
this.oldStyle.backgroundImage = this.element.getStyle('background-image');
this.element.setStyle({backgroundImage: 'none'});
}
if (!this.options.endcolor)
this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
if (!this.options.restorecolor)
this.options.restorecolor = this.element.getStyle('background-color');
this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
},
update: function(position) {
this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){
return m+((this._base[i]+(this._delta[i]*position)).round().toColorPart()); }.bind(this)) });
},
finish: function() {
this.element.setStyle(Object.extend(this.oldStyle, {
backgroundColor: this.options.restorecolor
}));
}
});
Effect.ScrollTo = function(element) {
var options = arguments[1] || { },
scrollOffsets = document.viewport.getScrollOffsets(),
elementOffsets = $(element).cumulativeOffset();
share/static/alice.js view on Meta::CPAN
(
transform.unit != 'color' &&
(isNaN(transform.originalValue) || isNaN(transform.targetValue))
)
);
});
},
update: function(position) {
var style = { }, transform, i = this.transforms.length;
while(i--)
style[(transform = this.transforms[i]).style] =
transform.unit=='color' ? '#'+
(Math.round(transform.originalValue[0]+
(transform.targetValue[0]-transform.originalValue[0])*position)).toColorPart() +
(Math.round(transform.originalValue[1]+
(transform.targetValue[1]-transform.originalValue[1])*position)).toColorPart() +
(Math.round(transform.originalValue[2]+
(transform.targetValue[2]-transform.originalValue[2])*position)).toColorPart() :
(transform.originalValue +
(transform.targetValue - transform.originalValue) * position).toFixed(3) +
(transform.unit === null ? '' : transform.unit);
this.element.setStyle(style, true);
}
});
Effect.Transform = Class.create({
initialize: function(tracks){
this.tracks = [];
this.options = arguments[1] || { };
this.addTracks(tracks);
},
addTracks: function(tracks){
tracks.each(function(track){
track = $H(track);
var data = track.values().first();
this.tracks.push($H({
ids: track.keys().first(),
effect: Effect.Morph,
options: { style: data }
}));
}.bind(this));
return this;
},
play: function(){
return new Effect.Parallel(
this.tracks.map(function(track){
var ids = track.get('ids'), effect = track.get('effect'), options = track.get('options');
var elements = [$(ids) || $$(ids)].flatten();
return elements.map(function(e){ return new effect(e, Object.extend({ sync:true }, options)) });
}).flatten(),
this.options
);
}
});
Element.CSS_PROPERTIES = $w(
'backgroundColor backgroundPosition borderBottomColor borderBottomStyle ' +
'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth ' +
'borderRightColor borderRightStyle borderRightWidth borderSpacing ' +
'borderTopColor borderTopStyle borderTopWidth bottom clip color ' +
'fontSize fontWeight height left letterSpacing lineHeight ' +
'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+
'maxWidth minHeight minWidth opacity outlineColor outlineOffset ' +
'outlineWidth paddingBottom paddingLeft paddingRight paddingTop ' +
'right textIndent top width wordSpacing zIndex');
Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/;
String.__parseStyleElement = document.createElement('div');
String.prototype.parseStyle = function(){
var style, styleRules = $H();
if (Prototype.Browser.WebKit)
style = new Element('div',{style:this}).style;
else {
String.__parseStyleElement.innerHTML = '<div style="' + this + '"></div>';
style = String.__parseStyleElement.childNodes[0].style;
}
Element.CSS_PROPERTIES.each(function(property){
if (style[property]) styleRules.set(property, style[property]);
});
if (Prototype.Browser.IE && this.include('opacity'))
styleRules.set('opacity', this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]);
return styleRules;
};
if (document.defaultView && document.defaultView.getComputedStyle) {
Element.getStyles = function(element) {
var css = document.defaultView.getComputedStyle($(element), null);
return Element.CSS_PROPERTIES.inject({ }, function(styles, property) {
styles[property] = css[property];
return styles;
});
};
} else {
Element.getStyles = function(element) {
element = $(element);
var css = element.currentStyle, styles;
styles = Element.CSS_PROPERTIES.inject({ }, function(results, property) {
results[property] = css[property];
return results;
});
if (!styles.opacity) styles.opacity = element.getOpacity();
return styles;
};
}
Effect.Methods = {
morph: function(element, style) {
element = $(element);
new Effect.Morph(element, Object.extend({ style: style }, arguments[2] || { }));
return element;
},
visualEffect: function(element, effect, options) {
element = $(element);
var s = effect.dasherize().camelize(), klass = s.charAt(0).toUpperCase() + s.substring(1);
new Effect[klass](element, options);
return element;
},
share/static/alice.js view on Meta::CPAN
function underlineSelection() {
this.execCommand('underline', false, null);
}
function underlineSelected() {
return this.queryCommandState('underline');
}
function italicSelection() {
this.execCommand('italic', false, null);
}
function italicSelected() {
return this.queryCommandState('italic');
}
function strikethroughSelection() {
this.execCommand('strikethrough', false, null);
}
function indentSelection() {
if (Prototype.Browser.Gecko) {
var selection, range, node, blockquote;
selection = window.getSelection();
range = selection.getRangeAt(0);
node = selection.getNode();
if (range.collapsed) {
range = document.createRange();
range.selectNodeContents(node);
selection.removeAllRanges();
selection.addRange(range);
}
blockquote = new Element('blockquote');
range = selection.getRangeAt(0);
range.surroundContents(blockquote);
} else {
this.execCommand('indent', false, null);
}
}
function outdentSelection() {
this.execCommand('outdent', false, null);
}
function toggleIndentation() {
if (this.indentSelected()) {
this.outdentSelection();
} else {
this.indentSelection();
}
}
function indentSelected() {
var node = window.getSelection().getNode();
return node.match("blockquote, blockquote *");
}
function fontSelection(font) {
this.execCommand('fontname', false, font);
}
function fontSizeSelection(fontSize) {
this.execCommand('fontsize', false, fontSize);
}
function colorSelection(color) {
this.execCommand('forecolor', false, color);
}
function backgroundColorSelection(color) {
if(Prototype.Browser.Gecko) {
this.execCommand('hilitecolor', false, color);
} else {
this.execCommand('backcolor', false, color);
}
}
function alignSelection(alignment) {
this.execCommand('justify' + alignment);
}
function alignSelected() {
var node = window.getSelection().getNode();
return Element.getStyle(node, 'textAlign');
}
function linkSelection(url) {
this.execCommand('createLink', false, url);
}
function unlinkSelection() {
var node = window.getSelection().getNode();
if (this.linkSelected())
window.getSelection().selectNode(node);
this.execCommand('unlink', false, null);
}
function linkSelected() {
var node = window.getSelection().getNode();
return node ? node.tagName.toUpperCase() == 'A' : false;
}
function formatblockSelection(element){
this.execCommand('formatblock', false, element);
}
function toggleOrderedList() {
var selection, node;
selection = window.getSelection();
node = selection.getNode();
if (this.orderedListSelected() && !node.match("ol li:last-child, ol li:last-child *")) {
selection.selectNode(node.up("ol"));
} else if (this.unorderedListSelected()) {
selection.selectNode(node.up("ul"));
}
this.execCommand('insertorderedlist', false, null);
}
function insertOrderedList() {
share/static/alice.js view on Meta::CPAN
this.execCommand('insertImage', false, url);
}
function insertHTML(html) {
if (Prototype.Browser.IE) {
var range = window.document.selection.createRange();
range.pasteHTML(html);
range.collapse(false);
range.select();
} else {
this.execCommand('insertHTML', false, html);
}
}
function execCommand(command, ui, value) {
var handler = this.commands.get(command);
if (handler) {
handler.bind(this)(value);
} else {
try {
window.document.execCommand(command, ui, value);
} catch(e) { return null; }
}
document.activeElement.fire("field:change");
}
function queryCommandState(state) {
var handler = this.queryCommands.get(state);
if (handler) {
return handler.bind(this)();
} else {
try {
return window.document.queryCommandState(state);
} catch(e) { return null; }
}
}
function getSelectedStyles() {
var styles = $H({});
var editor = this;
editor.styleSelectors.each(function(style){
var node = editor.selection.getNode();
styles.set(style.first(), Element.getStyle(node, style.last()));
});
return styles;
}
return {
boldSelection: boldSelection,
boldSelected: boldSelected,
underlineSelection: underlineSelection,
underlineSelected: underlineSelected,
italicSelection: italicSelection,
italicSelected: italicSelected,
strikethroughSelection: strikethroughSelection,
indentSelection: indentSelection,
outdentSelection: outdentSelection,
toggleIndentation: toggleIndentation,
indentSelected: indentSelected,
fontSelection: fontSelection,
fontSizeSelection: fontSizeSelection,
colorSelection: colorSelection,
backgroundColorSelection: backgroundColorSelection,
alignSelection: alignSelection,
alignSelected: alignSelected,
linkSelection: linkSelection,
unlinkSelection: unlinkSelection,
linkSelected: linkSelected,
formatblockSelection: formatblockSelection,
toggleOrderedList: toggleOrderedList,
insertOrderedList: insertOrderedList,
orderedListSelected: orderedListSelected,
toggleUnorderedList: toggleUnorderedList,
insertUnorderedList: insertUnorderedList,
unorderedListSelected: unorderedListSelected,
insertImage: insertImage,
insertHTML: insertHTML,
execCommand: execCommand,
queryCommandState: queryCommandState,
getSelectedStyles: getSelectedStyles,
commands: $H({}),
queryCommands: $H({
link: linkSelected,
orderedlist: orderedListSelected,
unorderedlist: unorderedListSelected
}),
styleSelectors: $H({
fontname: 'fontFamily',
fontsize: 'fontSize',
forecolor: 'color',
hilitecolor: 'backgroundColor',
backcolor: 'backgroundColor'
})
};
})(window);
if (Prototype.Browser.IE) {
Object.extend(Selection.prototype, (function() {
function setBookmark() {
var bookmark = $('bookmark');
if (bookmark) bookmark.remove();
bookmark = new Element('span', { 'id': 'bookmark' }).update(" ");
var parent = new Element('div');
parent.appendChild(bookmark);
var range = this._document.selection.createRange();
range.collapse();
range.pasteHTML(parent.innerHTML);
}
function moveToBookmark() {
var bookmark = $('bookmark');
if (!bookmark) return;
var range = this._document.selection.createRange();
range.moveToElementText(bookmark);
range.collapse();
range.select();
bookmark.remove();
}
return {
setBookmark: setBookmark,
moveToBookmark: moveToBookmark
}
})());
} else {
Object.extend(Selection.prototype, (function() {
function setBookmark() {
var bookmark = $('bookmark');
if (bookmark) bookmark.remove();
bookmark = new Element('span', { 'id': 'bookmark' }).update(" ");
this.getRangeAt(0).insertNode(bookmark);
}
function moveToBookmark() {
var bookmark = $('bookmark');
if (!bookmark) return;
var range = document.createRange();
range.setStartBefore(bookmark);
this.removeAllRanges();
this.addRange(range);
bookmark.remove();
share/static/alice.js view on Meta::CPAN
})();
document.on("dom:loaded", function() {
if ('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">' +
element.innerHTML + '</span>'
);
}
function convertStrongsToSpans() {
container.select("strong").each(function(element) {
spanify(element, "font-weight: bold");
});
}
function convertEmsToSpans() {
container.select("em").each(function(element) {
spanify(element, "font-style: italic");
});
}
function convertDivsToParagraphs() {
container.select("div").each(function(element) {
element.replace("<p>" + element.innerHTML + "</p>");
});
}
if (Prototype.Browser.WebKit || Prototype.Browser.Gecko) {
convertStrongsToSpans();
convertEmsToSpans();
} else if (Prototype.Browser.IE || Prototype.Browser.Opera) {
convertDivsToParagraphs();
}
return container.innerHTML;
},
getApplicationMarkupFrom: function(element) {
var mode = ACCUMULATING_LINE, result, container, line, lineContainer, previousAccumulation;
function walk(nodes) {
var length = nodes.length, node, tagName, i;
for (i = 0; i < length; i++) {
node = nodes[i];
if (node.nodeType == Node.ELEMENT_NODE) {
tagName = node.tagName.toLowerCase();
open(tagName, node);
walk(node.childNodes);
close(tagName);
} else if (node.nodeType == Node.TEXT_NODE) {
read(node.nodeValue);
}
}
}
function open(tagName, node) {
if (mode == ACCUMULATING_LINE) {
if (isBlockElement(tagName)) {
if (isEmptyParagraph(node)) {
accumulate(new Element("br"));
}
flush();
if (isListElement(tagName)) {
container = insertList(tagName);
mode = EXPECTING_LIST_ITEM;
}
} else if (isLineBreak(tagName)) {
if (isLineBreak(getPreviouslyAccumulatedTagName())) {
previousAccumulation.parentNode.removeChild(previousAccumulation);
flush();
}
share/static/alice.js view on Meta::CPAN
function close(tagName) {
if (mode == ACCUMULATING_LINE) {
if (isLineElement(tagName)) {
flush();
}
if (line != lineContainer) {
lineContainer = lineContainer.parentNode;
}
} else if (mode == EXPECTING_LIST_ITEM) {
if (isListElement(tagName)) {
container = result;
mode = ACCUMULATING_LINE;
}
} else if (mode == ACCUMULATING_LIST_ITEM) {
if (isListItemElement(tagName)) {
flush();
mode = EXPECTING_LIST_ITEM;
}
if (line != lineContainer) {
lineContainer = lineContainer.parentNode;
}
}
}
function isBlockElement(tagName) {
return isLineElement(tagName) || isListElement(tagName);
}
function isLineElement(tagName) {
return tagName == "p" || tagName == "div";
}
function isListElement(tagName) {
return tagName == "ol" || tagName == "ul";
}
function isListItemElement(tagName) {
return tagName == "li";
}
function isLineBreak(tagName) {
return tagName == "br";
}
function isEmptyParagraph(node) {
return node.tagName.toLowerCase() == "p" && node.childNodes.length == 0;
}
function read(value) {
accumulate(document.createTextNode(value));
}
function accumulateInlineElement(tagName, node) {
var element = node.cloneNode(false);
if (tagName == "span") {
if ($(node).getStyle("fontWeight") == "bold") {
element = new Element("strong");
} else if ($(node).getStyle("fontStyle") == "italic") {
element = new Element("em");
}
}
accumulate(element);
lineContainer = element;
}
function accumulate(node) {
if (mode != EXPECTING_LIST_ITEM) {
if (!line) line = lineContainer = createLine();
previousAccumulation = node;
lineContainer.appendChild(node);
}
}
function getPreviouslyAccumulatedTagName() {
if (previousAccumulation && previousAccumulation.nodeType == Node.ELEMENT_NODE) {
return previousAccumulation.tagName.toLowerCase();
}
}
function flush() {
if (line && line.childNodes.length) {
container.appendChild(line);
line = lineContainer = null;
}
}
function createLine() {
if (mode == ACCUMULATING_LINE) {
return new Element("div");
} else if (mode == ACCUMULATING_LIST_ITEM) {
return new Element("li");
}
}
function insertList(tagName) {
var list = new Element(tagName);
result.appendChild(list);
return list;
}
result = container = new Element("div");
walk(element.childNodes);
flush();
return result.innerHTML;
}
};
})();
WysiHat.Toolbar = Class.create((function() {
function initialize(editor) {
this.editor = editor;
this.element = this.createToolbarElement();
}
function createToolbarElement() {
var toolbar = new Element('div', { 'class': 'editor_toolbar' });
share/static/alice.js view on Meta::CPAN
if (this.editor) this.editor.update();
this.index = -1;
this.stash();
this.update();
this.focus(1);
},
completeNickname: function() {
if (this.disabled) return;
if (!this.completion) {
this.completion = new Alice.Completion(this.window.getNicknames());
}
this.completion.next();
},
stopCompletion: function() {
if (this.completion) {
this.completion.restore();
this.completion = false;
}
},
stash: function() {
this.buffer = this.getValue();
},
update: function() {
this.setValue(this.getCommand(this.index));
},
getCommand: function(index) {
if (index == -1) {
return this.buffer;
} else {
return this.history[index];
}
},
resize: function() {
if (this.editor) {
this.textarea.setValue(this.editor.innerHTML);
}
(function() {
if (!this.window.active) return;
var height = this.getContentHeight();
if (height == 0) {
this.element.setStyle({ height: null, top: 0 });
} else if (height <= 150) {
this.element.setStyle({ height: height + "px", top: "-1px" });
}
}).bind(this).defer();
},
getContentHeight: function() {
var element = new Element("div").setStyle({
position: "absolute",
visibility: "hidden",
left: "-" + this.element.getWidth() + "px",
width: this.element.getWidth() - 7 + "px",
fontFamily: this.element.getStyle("fontFamily"),
fontSize: this.element.getStyle("fontSize"),
lineHeight: this.element.getStyle("lineHeight"),
whiteSpace: "pre-wrap",
wordWrap: "break-word"
});
if (this.editor) element.addClassName("editor");
var value = this.getValue();
element.update(value.replace(/\n$/, "\n\n").replace("\n", "<br>"));
$(document.body).insert(element);
var height = element.getHeight();
element.remove();
return height;
},
canContentEditable: function() {
var element = new Element("div", {contentEditable: "true"});
return element.contentEditable != null && ! this.application.isMobile;
},
updateRange: function (e) {
var selection = window.getSelection();
if (selection.rangeCount > 0) {
var range = selection.getRangeAt(0);
this.range = range;
}
},
pasteHandler: function(e) {
var url = e.clipboardData.getData("URL");
if (url) {
e.preventDefault();
this.editor.insertHTML(url);
this.updateRange();
return;
}
var text = e.clipboardData.getData("Text");
if (text) {
e.preventDefault();
text = text.escapeHTML().replace(/\n+/g, "<br>");
this.editor.insertHTML(text);
this.updateRange();
return;
}
}
});
Alice.Keyboard = Class.create({
initialize: function(application) {
this.application = application;
this.isMac = navigator.platform.match(/mac/i);
this.enable();
this.shortcut("Cmd+C", { propagate: true });
this.shortcut("Ctrl+C", { propagate: true });
this.shortcut("Cmd+K");
this.shortcut("Cmd+B");
this.shortcut("Cmd+F");
this.shortcut("Opt+Up");
( run in 1.124 second using v1.01-cache-2.11-cpan-5735350b133 )