mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-18 10:49:54 +09:00
17223554 : xquared upgrade to 0.7
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@4968 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
5956e254e7
commit
7c3b336e41
59 changed files with 34562 additions and 8454 deletions
102
modules/editor/skins/xquared/javascripts/plugin/Base.js
Normal file
102
modules/editor/skins/xquared/javascripts/plugin/Base.js
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* @namespace
|
||||
*/
|
||||
xq.plugin = {};
|
||||
|
||||
/**
|
||||
* @requires Xquared.js
|
||||
*/
|
||||
xq.plugin.Base = xq.Class(/** @lends xq.plugin.Base.prototype */{
|
||||
/**
|
||||
* Abstract base class for Xquared plugins.
|
||||
*
|
||||
* @constructs
|
||||
*/
|
||||
initialize: function() {},
|
||||
|
||||
/**
|
||||
* Loads plugin. Automatically called by xq.Editor.
|
||||
*
|
||||
* @param {xq.Editor} editor Editor instance.
|
||||
*/
|
||||
load: function(editor) {
|
||||
this.editor = editor;
|
||||
if(this.isEventListener()) this.editor.addListener(this);
|
||||
|
||||
this.onBeforeLoad(this.editor);
|
||||
this.editor.addShortcuts(this.getShortcuts() || []);
|
||||
this.editor.addAutocorrections(this.getAutocorrections() || []);
|
||||
this.editor.addAutocompletions(this.getAutocompletions() || []);
|
||||
this.editor.addTemplateProcessors(this.getTemplateProcessors() || []);
|
||||
this.editor.addContextMenuHandlers(this.getContextMenuHandlers() || []);
|
||||
this.onAfterLoad(this.editor);
|
||||
},
|
||||
|
||||
/**
|
||||
* Unloads plugin. Automatically called by xq.Editor
|
||||
*/
|
||||
unload: function() {
|
||||
this.onBeforeUnload(this.editor);
|
||||
for(var key in this.getShortcuts()) this.editor.removeShortcut(key);
|
||||
for(var key in this.getAutocorrections()) this.editor.removeAutocorrection(key);
|
||||
for(var key in this.getAutocompletions()) this.editor.removeAutocompletion(key);
|
||||
for(var key in this.getTemplateProcessors()) this.editor.removeTemplateProcessor(key);
|
||||
for(var key in this.getContextMenuHandlers()) this.editor.removeContextMenuHandler(key);
|
||||
this.onAfterUnload(this.editor);
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Always returns false.<br />
|
||||
* <br />
|
||||
* Derived class may override this to make a plugin as a event listener.<br />
|
||||
* Whenever you override this function, you should also implement at least one event handler for xq.Editor.
|
||||
*/
|
||||
isEventListener: function() {return false},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
onBeforeLoad: function(editor) {},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
onAfterLoad: function(editor) {},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
onBeforeUnload: function(editor) {},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
onAfterUnload: function(editor) {},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
getShortcuts: function() {return [];},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
getAutocorrections: function() {return [];},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
getAutocompletions: function() {return [];},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
getTemplateProcessors: function() {return [];},
|
||||
|
||||
/**
|
||||
* Callback function. Derived class may override this.
|
||||
*/
|
||||
getContextMenuHandlers: function() {return [];}
|
||||
});
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* @requires Xquared.js
|
||||
* @requires Browser.js
|
||||
* @requires Editor.js
|
||||
* @requires plugin/Base.js
|
||||
*/
|
||||
xq.plugin.EditorResizePlugin = xq.Class(xq.plugin.Base,
|
||||
/**
|
||||
* @name xq.plugin.EditorResizePlugin
|
||||
* @lends xq.plugin.EditorResizePlugin.prototype
|
||||
* @extends xq.plugin.Base
|
||||
* @constructor
|
||||
*/
|
||||
{
|
||||
isEventListener: function() {return true;},
|
||||
|
||||
onAfterLoad: function(xed) {
|
||||
this.xed = xed;
|
||||
this.bar = null;
|
||||
this.screen = null;
|
||||
this.active = false;
|
||||
},
|
||||
|
||||
onEditorInitialized: function(xed) {
|
||||
xed.registerEventFirer("Editor", "Resized");
|
||||
|
||||
var wrapper = this.xed.getOutmostWrapper();
|
||||
var doc = wrapper.ownerDocument;
|
||||
|
||||
// create resize bar
|
||||
this.bar = doc.createElement("DIV");
|
||||
if(xq.Browser.isIE6) this.bar.innerHTML = "<span></span>";
|
||||
this.bar.style.height = "6px";
|
||||
this.bar.style.backgroundColor = "#ddd";
|
||||
this.bar.style.cursor = "n-resize";
|
||||
wrapper.appendChild(this.bar);
|
||||
|
||||
// register event
|
||||
xq.observe(this.bar, 'mousedown', this.onMousedown.bindAsEventListener(this));
|
||||
xq.observe(this.bar, 'mouseup', this.onMouseup.bindAsEventListener(this));
|
||||
xq.observe(this.bar, 'click', this.onMouseup.bindAsEventListener(this));
|
||||
this.mousemoveHandler = this.onMousemove.bindAsEventListener(this);
|
||||
},
|
||||
|
||||
onMousedown: function(e) {
|
||||
if(this.active) return;
|
||||
|
||||
xq.observe(document, 'mousemove', this.mousemoveHandler);
|
||||
this.last = e.screenY;
|
||||
|
||||
var wrapper = this.xed.getOutmostWrapper();
|
||||
var doc = wrapper.ownerDocument;
|
||||
var wysiwygDiv = this.xed.getWysiwygEditorDiv();
|
||||
var sourceDiv = this.xed.getSourceEditorDiv();
|
||||
var visibleDiv = this.xed.getCurrentEditMode() == "wysiwyg" ? wysiwygDiv : sourceDiv;
|
||||
var location = xq.getCumulativeOffset(visibleDiv);
|
||||
|
||||
// create screen
|
||||
this.screen = doc.createElement("DIV");
|
||||
if(xq.Browser.isIE6) this.screen.innerHTML = "<span></span>";
|
||||
|
||||
if(xq.Browser.isIE6) {
|
||||
this.screen.style.backgroundColor = "#EEE";
|
||||
wysiwygDiv.style.display = "none";
|
||||
} else {
|
||||
this.screen.style.position = "absolute";
|
||||
this.screen.style.left = location.left + "px";
|
||||
this.screen.style.top = location.top + "px";
|
||||
}
|
||||
|
||||
this.screen.style.width = visibleDiv.clientWidth + "px";
|
||||
this.screen.style.height = visibleDiv.clientHeight + "px";
|
||||
wrapper.insertBefore(this.screen, visibleDiv);
|
||||
|
||||
this.resize(e.screenY);
|
||||
this.active = true;
|
||||
|
||||
xq.stopEvent(e);
|
||||
return true;
|
||||
},
|
||||
onMouseup: function(e) {
|
||||
if(!this.active) return;
|
||||
|
||||
this.active = false;
|
||||
|
||||
xq.stopObserving(document, 'mousemove', this.mousemoveHandler);
|
||||
this.resize(e.screenY);
|
||||
|
||||
if(xq.Browser.isIE6) {
|
||||
var wysiwygDiv = this.xed.getWysiwygEditorDiv();
|
||||
var sourceDiv = this.xed.getSourceEditorDiv();
|
||||
var visibleDiv = this.xed.getCurrentEditMode() == "wysiwyg" ? wysiwygDiv : sourceDiv;
|
||||
visibleDiv.style.display = "block";
|
||||
}
|
||||
|
||||
this.screen.parentNode.removeChild(this.screen);
|
||||
this.screen = null;
|
||||
|
||||
this.xed._fireOnResized(this.xed);
|
||||
|
||||
xq.stopEvent(e);
|
||||
return true;
|
||||
},
|
||||
onMousemove: function(e) {
|
||||
this.resize(e.screenY);
|
||||
|
||||
xq.stopEvent(e);
|
||||
return true;
|
||||
},
|
||||
resize: function(y) {
|
||||
var delta = y - this.last;
|
||||
|
||||
var wysiwygDiv = this.xed.getWysiwygEditorDiv();
|
||||
var sourceDiv = this.xed.getSourceEditorDiv();
|
||||
var newHeight = Math.max(0, this.screen.clientHeight + delta);
|
||||
|
||||
sourceDiv.style.height = wysiwygDiv.style.height = this.screen.style.height = newHeight + "px";
|
||||
|
||||
this.last = y;
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* @requires Xquared.js
|
||||
* @requires Browser.js
|
||||
* @requires Editor.js
|
||||
* @requires plugin/Base.js
|
||||
*/
|
||||
xq.plugin.EventLogPlugin = xq.Class(xq.plugin.Base,
|
||||
/**
|
||||
* @name xq.plugin.EventLogPlugin
|
||||
* @lends xq.plugin.EventLogPlugin.prototype
|
||||
* @extends xq.plugin.Base
|
||||
* @constructor
|
||||
*/
|
||||
{
|
||||
isEventListener: function() {return true;},
|
||||
|
||||
onAfterLoad: function(xed) {
|
||||
this.createLogWindow();
|
||||
},
|
||||
|
||||
onEditorStartInitialization: function(xed) {
|
||||
this.log("Start initialization.");
|
||||
},
|
||||
onEditorInitialized: function(xed) {
|
||||
this.log("Initialized.");
|
||||
},
|
||||
onEditorElementChanged: function(xed, from, to) {
|
||||
this.log("Element changed from <" + (from ? from.nodeName : null) + "> to <" + (to ? to.nodeName : null) + ">.");
|
||||
},
|
||||
onEditorBeforeEvent: function(xed, e) {
|
||||
this.log("Before event [" + e.type + "]");
|
||||
},
|
||||
onEditorAfterEvent: function(xed, e) {
|
||||
this.log("After event [" + e.type + "]");
|
||||
},
|
||||
onEditorCurrentContentChanged: function(xed) {
|
||||
this.log("Current content changed.");
|
||||
},
|
||||
onEditorStaticContentChanged: function(xed, content) {
|
||||
this.log("Static content changed.");
|
||||
},
|
||||
onEditorCurrentEditModeChanged: function(xed, from, to) {
|
||||
this.log("Edit mode changed from <" + from + "> to <" + to + ">.");
|
||||
},
|
||||
|
||||
|
||||
|
||||
createLogWindow: function() {
|
||||
var wrapper = document.createElement("DIV");
|
||||
wrapper.innerHTML = "<h2>Log</h2>";
|
||||
wrapper.style.width = "500px";
|
||||
document.body.appendChild(wrapper);
|
||||
|
||||
this.logWindow = document.createElement("PRE");
|
||||
this.logWindow.style.fontSize = "0.75em";
|
||||
this.logWindow.style.height = "200px";
|
||||
this.logWindow.style.overflow = "scroll";
|
||||
this.logWindow.style.border = "1px solid black";
|
||||
this.logWindow.style.padding = "2px";
|
||||
wrapper.appendChild(this.logWindow);
|
||||
},
|
||||
|
||||
log: function(message) {
|
||||
var line = document.createTextNode(this.getFormattedTime() + ": " + message);
|
||||
this.logWindow.insertBefore(document.createElement("BR"), this.logWindow.firstChild);
|
||||
this.logWindow.insertBefore(line, this.logWindow.firstChild);
|
||||
},
|
||||
|
||||
getFormattedTime: function() {
|
||||
var date = new Date();
|
||||
var time = date.toTimeString().split(" ")[0];
|
||||
var msec = "000" + date.getMilliseconds();
|
||||
msec = msec.substring(msec.length - 4);
|
||||
|
||||
return time + "." + msec;
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @requires Xquared.js
|
||||
* @requires Browser.js
|
||||
* @requires Editor.js
|
||||
* @requires plugin/Base.js
|
||||
* @requires ui/Control.js
|
||||
* @requires macro/Factory.js
|
||||
* @requires macro/FlashMovieMacro.js
|
||||
*/
|
||||
xq.plugin.FlashMovieMacroPlugin = xq.Class(xq.plugin.Base,
|
||||
/**
|
||||
* @name xq.plugin.FlashMovieMacroPlugin
|
||||
* @lends xq.plugin.FlashMovieMacroPlugin.prototype
|
||||
* @extends xq.plugin.Base
|
||||
* @constructor
|
||||
*/
|
||||
{
|
||||
onAfterLoad: function(xed) {
|
||||
xed.config.macroIds.push("FlashMovie");
|
||||
xed.config.defaultToolbarButtonGroups.insert.push(
|
||||
{className:"movie", title:"Movie", handler:"xed.handleMovie()"}
|
||||
)
|
||||
|
||||
xed.handleInsertMovie = function(html) {
|
||||
var macro = this.macroFactory.createMacroFromDefinition({id:"FlashMovie", params:{html:html}});
|
||||
if(macro) {
|
||||
var placeHolder = macro.createPlaceHolderHtml();
|
||||
this.rdom.insertHtml(placeHolder);
|
||||
|
||||
var historyAdded = this.editHistory.onCommand();
|
||||
this._fireOnCurrentContentChanged(this);
|
||||
} else {
|
||||
alert("Unknown URL pattern");
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
xed.handleMovie = function() {
|
||||
var dialog = new xq.ui.FormDialog(
|
||||
this,
|
||||
xq.ui_templates.basicMovieDialog,
|
||||
function(dialog) {},
|
||||
function(data) {
|
||||
this.focus();
|
||||
|
||||
if(xq.Browser.isTrident) {
|
||||
var rng = this.rdom.rng();
|
||||
rng.moveToBookmark(bm);
|
||||
rng.select();
|
||||
}
|
||||
|
||||
// cancel?
|
||||
if(!data) return;
|
||||
|
||||
this.handleInsertMovie(data.html);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if(xq.Browser.isTrident) var bm = this.rdom.rng().getBookmark();
|
||||
dialog.show({position: 'centerOfEditor'});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* @requires Xquared.js
|
||||
* @requires Browser.js
|
||||
* @requires Editor.js
|
||||
* @requires plugin/Base.js
|
||||
* @requires ui/Control.js
|
||||
* @requires macro/Factory.js
|
||||
* @requires macro/IFrameMacro.js
|
||||
*/
|
||||
xq.plugin.IFrameMacroPlugin = xq.Class(xq.plugin.Base,
|
||||
/**
|
||||
* @name xq.plugin.IFrameMacroPlugin
|
||||
* @lends xq.plugin.IFrameMacroPlugin.prototype
|
||||
* @extends xq.plugin.Base
|
||||
* @constructor
|
||||
*/
|
||||
{
|
||||
onAfterLoad: function(xed) {
|
||||
xed.config.macroIds.push("IFrame");
|
||||
xed.config.defaultToolbarButtonGroups.insert.push(
|
||||
{className:"iframe", title:"IFrame", handler:"xed.handleIFrame()"}
|
||||
)
|
||||
|
||||
xed.handleIFrame = function() {
|
||||
var dialog = new xq.ui.FormDialog(
|
||||
this,
|
||||
xq.ui_templates.basicIFrameDialog,
|
||||
function(dialog) {},
|
||||
function(data) {
|
||||
this.focus();
|
||||
|
||||
// cancel?
|
||||
if(!data) return;
|
||||
|
||||
var macro = this.macroFactory.createMacroFromDefinition({id:"IFrame", params:data});
|
||||
if(macro) {
|
||||
var placeHolder = macro.createPlaceHolderHtml();
|
||||
this.rdom.insertHtml(placeHolder);
|
||||
} else {
|
||||
alert("Unknown error");
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
dialog.show({position: 'centerOfEditor'});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* @requires Xquared.js
|
||||
* @requires Browser.js
|
||||
* @requires Editor.js
|
||||
* @requires plugin/Base.js
|
||||
* @requires ui/Control.js
|
||||
* @requires macro/Factory.js
|
||||
* @requires macro/JavascriptMacro.js
|
||||
*/
|
||||
xq.plugin.JavascriptMacroPlugin = xq.Class(xq.plugin.Base,
|
||||
/**
|
||||
* @name xq.plugin.JavascriptMacroPlugin
|
||||
* @lends xq.plugin.JavascriptMacroPlugin.prototype
|
||||
* @extends xq.plugin.Base
|
||||
* @constructor
|
||||
*/
|
||||
{
|
||||
onAfterLoad: function(xed) {
|
||||
xed.config.macroIds.push("Javascript");
|
||||
xed.config.defaultToolbarButtonGroups.insert.push(
|
||||
{className:"script", title:"Script", handler:"xed.handleScript()"}
|
||||
)
|
||||
|
||||
xed.handleInsertScript = function(url) {
|
||||
var params = {url: url};
|
||||
var macro = this.macroFactory.createMacroFromDefinition({id:"Javascript", params:params});
|
||||
if(macro) {
|
||||
var placeHolder = macro.createPlaceHolderHtml();
|
||||
this.rdom.insertHtml(placeHolder);
|
||||
|
||||
var historyAdded = this.editHistory.onCommand();
|
||||
this._fireOnCurrentContentChanged(this);
|
||||
} else {
|
||||
alert("Unknown URL pattern");
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
xed.handleScript = function() {
|
||||
var dialog = new xq.ui.FormDialog(
|
||||
this,
|
||||
xq.ui_templates.basicScriptDialog,
|
||||
function(dialog) {},
|
||||
function(data) {
|
||||
this.focus();
|
||||
|
||||
if(xq.Browser.isTrident) {
|
||||
var rng = this.rdom.rng();
|
||||
rng.moveToBookmark(bm);
|
||||
rng.select();
|
||||
}
|
||||
|
||||
// cancel?
|
||||
if(!data) return;
|
||||
|
||||
this.handleInsertScript(data.url);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if(xq.Browser.isTrident) var bm = this.rdom.rng().getBookmark();
|
||||
dialog.show({position: 'centerOfEditor'});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
110
modules/editor/skins/xquared/javascripts/plugin/MacroPlugin.js
Normal file
110
modules/editor/skins/xquared/javascripts/plugin/MacroPlugin.js
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/**
|
||||
* @requires Xquared.js
|
||||
* @requires Browser.js
|
||||
* @requires Editor.js
|
||||
*
|
||||
* @requires macro/Factory.js
|
||||
* @requires Layer.js
|
||||
* @requires Json2.js
|
||||
*
|
||||
* @requires plugin/Base.js
|
||||
*/
|
||||
xq.plugin.MacroPlugin = xq.Class(xq.plugin.Base,
|
||||
/**
|
||||
* @name xq.plugin.MacroPlugin
|
||||
* @lends xq.plugin.MacroPlugin.prototype
|
||||
* @extends xq.plugin.Base
|
||||
* @constructor
|
||||
*/
|
||||
{
|
||||
isEventListener: function() {return true;},
|
||||
|
||||
onAfterLoad: function(xed) {
|
||||
this.xed = xed;
|
||||
this.xed.config.macroIds = [];
|
||||
this.layers = [];
|
||||
},
|
||||
|
||||
onEditorStartInitialization: function(xed) {
|
||||
this.xed.validator.addListener(this);
|
||||
|
||||
this.xed.macroFactory = new xq.macro.Factory(this.xed.config.imagePathForContent + 'placeholder.gif');
|
||||
for(var i = 0; i < this.xed.config.macroIds.length; i++) {
|
||||
this.xed.macroFactory.register(this.xed.config.macroIds[i]);
|
||||
}
|
||||
|
||||
xed.timer.register(this.updateLayers.bind(this), 100);
|
||||
xed.timer.register(this.updateLayerList.bind(this), 2000);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Element} [placeHolder] place holder element
|
||||
*/
|
||||
attachMacro: function(element) {
|
||||
var longdesc = element.getAttribute("longdesc") || element.longdesc;
|
||||
var def = JSON.parse(unescape(longdesc));
|
||||
var macro = this.xed.macroFactory.createMacroFromDefinition(def);
|
||||
var layer = new xq.Layer(this.xed, element, macro.createHtml());
|
||||
macro.onLayerInitialzied(layer);
|
||||
this.layers.push(layer);
|
||||
},
|
||||
|
||||
isAttachedPlaceHolder: function(element) {
|
||||
for(var i = 0; i < this.layers.length; i++) {
|
||||
if(this.layers[i].element === element) return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
updateLayerList: function() {
|
||||
if(this.xed.getCurrentEditMode() !== 'wysiwyg') {
|
||||
for(var i = 0; i < this.layers.length; i++) {
|
||||
this.layers[i].detach();
|
||||
}
|
||||
this.layers = [];
|
||||
} else {
|
||||
var placeHolders = xq.getElementsByClassName(this.xed.rdom.getRoot(), "xqlayer", xq.Browser.isTrident ? "img" : null);
|
||||
for(var i = 0; i < placeHolders.length; i++) {
|
||||
if(!this.isAttachedPlaceHolder(placeHolders[i])) {
|
||||
this.attachMacro(placeHolders[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates all layers immediately. If there're invalid layers, detachs and removes them.
|
||||
*/
|
||||
updateLayers: function() {
|
||||
if(this.xed.getCurrentEditMode() !== 'wysiwyg') return;
|
||||
|
||||
for(var i = 0; i < this.layers.length; i++) {
|
||||
var layer = this.layers[i];
|
||||
if(layer.isValid()) {
|
||||
layer.updatePosition();
|
||||
} else {
|
||||
layer.detach();
|
||||
this.layers.splice(i, 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onValidatorPreprocessing: function(html) {
|
||||
var p = xq.compilePattern("<(IFRAME|SCRIPT|OBJECT|EMBED)\\s+[^>]+(?:/>|>.*?</(?:IFRAME|SCRIPT|OBJECT|EMBED)>)", "img");
|
||||
html.value = html.value.replace(p, function(str, tag) {
|
||||
var macro = this.xed.macroFactory.createMacroFromHtml(str);
|
||||
return macro ? macro.createPlaceHolderHtml() : "";
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
onValidatorAfterStringValidation: function(html) {
|
||||
var p1 = /<img\s+[^>]*class="xqlayer"\s+[^>]*\/>/mg;
|
||||
var p2 = /<img\s+[^>]*longdesc="(.+?)"\s+[^>]*\/>/m;
|
||||
|
||||
html.value = html.value.replace(p1, function(img) {
|
||||
var def = JSON.parse(unescape(img.match(p2)[1]));
|
||||
var macro = this.xed.macroFactory.createMacroFromDefinition(def);
|
||||
return macro.createHtml();
|
||||
}.bind(this));
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,224 @@
|
|||
/**
|
||||
* @requires Xquared.js
|
||||
* @requires Browser.js
|
||||
* @requires Editor.js
|
||||
* @requires plugin/Base.js
|
||||
*/
|
||||
xq.plugin.SpringnotePlugin = xq.Class(xq.plugin.Base,
|
||||
/**
|
||||
* @name xq.plugin.SpringnotePlugin
|
||||
* @lends xq.plugin.SpringnotePlugin.prototype
|
||||
* @extends xq.plugin.Base
|
||||
* @constructor
|
||||
*/
|
||||
{
|
||||
getShortcuts: function() {
|
||||
if(xq.Browser.isMac) {
|
||||
// Mac FF & Safari
|
||||
return [
|
||||
{event:"Ctrl+SPACE", handler:"xed.handleAutocompletion(); stop = true;"},
|
||||
{event:"Ctrl+Meta+0", handler:"xed.handleApplyBlock('P')"},
|
||||
{event:"Ctrl+Meta+1", handler:"xed.handleApplyBlock('H1')"},
|
||||
{event:"Ctrl+Meta+2", handler:"xed.handleApplyBlock('H2')"},
|
||||
{event:"Ctrl+Meta+3", handler:"xed.handleApplyBlock('H3')"},
|
||||
{event:"Ctrl+Meta+4", handler:"xed.handleApplyBlock('H4')"},
|
||||
{event:"Ctrl+Meta+5", handler:"xed.handleApplyBlock('H5')"},
|
||||
{event:"Ctrl+Meta+6", handler:"xed.handleApplyBlock('H6')"},
|
||||
|
||||
{event:"Ctrl+Meta+B", handler:"xed.handleApplyBlock('BLOCKQUOTE')"},
|
||||
{event:"Ctrl+Meta+D", handler:"xed.handleApplyBlock('DIV')"},
|
||||
{event:"Ctrl+Meta+EQUAL", handler:"xed.handleSeparator()"},
|
||||
|
||||
{event:"Ctrl+Meta+O", handler:"xed.handleList('OL')"},
|
||||
{event:"Ctrl+Meta+U", handler:"xed.handleList('UL')"},
|
||||
|
||||
{event:"Ctrl+Meta+E", handler:"xed.handleRemoveBlock()"},
|
||||
|
||||
{event:"Ctrl+(Meta)+COMMA", handler:"xed.handleJustify('left')"},
|
||||
{event:"Ctrl+(Meta)+PERIOD", handler:"xed.handleJustify('center')"},
|
||||
{event:"Ctrl+(Meta)+SLASH", handler:"xed.handleJustify('right')"},
|
||||
|
||||
{event:"Meta+UP", handler:"xed.handleMoveBlock(true)"},
|
||||
{event:"Meta+DOWN", handler:"xed.handleMoveBlock(false)"}
|
||||
];
|
||||
} else if(xq.Browser.isUbuntu) {
|
||||
// Ubunto FF
|
||||
return [
|
||||
{event:"Ctrl+SPACE", handler:"xed.handleAutocompletion(); stop = true;"},
|
||||
{event:"Ctrl+0", handler:"xed.handleApplyBlock('P')"},
|
||||
{event:"Ctrl+1", handler:"xed.handleApplyBlock('H1')"},
|
||||
{event:"Ctrl+2", handler:"xed.handleApplyBlock('H2')"},
|
||||
{event:"Ctrl+3", handler:"xed.handleApplyBlock('H3')"},
|
||||
{event:"Ctrl+4", handler:"xed.handleApplyBlock('H4')"},
|
||||
{event:"Ctrl+5", handler:"xed.handleApplyBlock('H5')"},
|
||||
{event:"Ctrl+6", handler:"xed.handleApplyBlock('H6')"},
|
||||
|
||||
{event:"Ctrl+Alt+B", handler:"xed.handleApplyBlock('BLOCKQUOTE')"},
|
||||
{event:"Ctrl+Alt+D", handler:"xed.handleApplyBlock('DIV')"},
|
||||
{event:"Alt+HYPHEN", handler:"xed.handleSeparator()"},
|
||||
|
||||
{event:"Ctrl+Alt+O", handler:"xed.handleList('OL')"},
|
||||
{event:"Ctrl+Alt+U", handler:"xed.handleList('UL')"},
|
||||
|
||||
{event:"Ctrl+Alt+E", handler:"xed.handleRemoveBlock()"},
|
||||
|
||||
{event:"Alt+COMMA", handler:"xed.handleJustify('left')"},
|
||||
{event:"Alt+PERIOD", handler:"xed.handleJustify('center')"},
|
||||
{event:"Alt+SLASH", handler:"xed.handleJustify('right')"},
|
||||
|
||||
{event:"Alt+UP", handler:"xed.handleMoveBlock(true)"},
|
||||
{event:"Alt+DOWN", handler:"xed.handleMoveBlock(false)"}
|
||||
];
|
||||
} else {
|
||||
// Win IE & FF && Safari
|
||||
return [
|
||||
{event:"Ctrl+SPACE", handler:"xed.handleAutocompletion(); stop = true;"},
|
||||
{event:"Alt+0", handler:"xed.handleApplyBlock('P')"},
|
||||
{event:"Alt+1", handler:"xed.handleApplyBlock('H1')"},
|
||||
{event:"Alt+2", handler:"xed.handleApplyBlock('H2')"},
|
||||
{event:"Alt+3", handler:"xed.handleApplyBlock('H3')"},
|
||||
{event:"Alt+4", handler:"xed.handleApplyBlock('H4')"},
|
||||
{event:"Alt+5", handler:"xed.handleApplyBlock('H5')"},
|
||||
{event:"Alt+6", handler:"xed.handleApplyBlock('H6')"},
|
||||
{event:"Alt+7", handler:"xed.handleInsertMacro('TableOfContents')"},
|
||||
{event:"Alt+8", handler:"xed.attachLayer()"},
|
||||
|
||||
{event:"Ctrl+Alt+B", handler:"xed.handleApplyBlock('BLOCKQUOTE')"},
|
||||
{event:"Ctrl+Alt+D", handler:"xed.handleApplyBlock('DIV')"},
|
||||
{event:"Alt+HYPHEN", handler:"xed.handleSeparator()"},
|
||||
|
||||
{event:"Ctrl+Alt+O", handler:"xed.handleList('OL')"},
|
||||
{event:"Ctrl+Alt+U", handler:"xed.handleList('UL')"},
|
||||
|
||||
{event:"Ctrl+Alt+E", handler:"xed.handleRemoveBlock()"},
|
||||
|
||||
{event:"Alt+COMMA", handler:"xed.handleJustify('left')"},
|
||||
{event:"Alt+PERIOD", handler:"xed.handleJustify('center')"},
|
||||
{event:"Alt+SLASH", handler:"xed.handleJustify('right')"},
|
||||
|
||||
{event:"Alt+UP", handler:"xed.handleMoveBlock(true)"},
|
||||
{event:"Alt+DOWN", handler:"xed.handleMoveBlock(false)"}
|
||||
];
|
||||
}
|
||||
},
|
||||
|
||||
getAutocorrections: function() {
|
||||
return [
|
||||
{id:'bullet', criteria: /^(\s|\ \;)*(\*|-)(\s|\ \;).+$/, handler: function(xed, rdom, block, text) {
|
||||
rdom.pushMarker();
|
||||
rdom.removePlaceHoldersAndEmptyNodes(block);
|
||||
block.innerHTML = block.innerHTML.replace(/((\s| )*(\*|\-)\s*)/, "");
|
||||
if(block.nodeName === "LI") xed.handleIndent();
|
||||
if(block.parentNode.nodeName !== "UL") xed.handleList('UL');
|
||||
rdom.popMarker(true);
|
||||
}},
|
||||
{id:'numbering', criteria: /^(\s|\ \;)*(\d\.|#)(\s|\ \;).+$/, handler: function(xed, rdom, block, text) {
|
||||
rdom.pushMarker();
|
||||
rdom.removePlaceHoldersAndEmptyNodes(block);
|
||||
block.innerHTML = block.innerHTML.replace(/(\s| )*(\d\.|\#)\s*/, "")
|
||||
if(block.nodeName === "LI") xed.handleIndent();
|
||||
if(block.parentNode.nodeName !== "OL") xed.handleList('OL');
|
||||
rdom.popMarker(true);
|
||||
}},
|
||||
{id:'imageUrl', criteria: /https?:\/\/.*?\/(.*?\.(jpg|jpeg|gif|bmp|png))$/i, handler: function(xed, rdom, block, text) {
|
||||
var fileName = text.match(/https?:\/\/.*?\/(.*?\.(jpg|jpeg|gif|bmp|png))$/i)[1];
|
||||
block.innerHTML = "";
|
||||
var img = rdom.createElement("img");
|
||||
img.src = text;
|
||||
img.alt = fileName;
|
||||
img.title = fileName;
|
||||
block.appendChild(img);
|
||||
rdom.selectElement(block);
|
||||
rdom.collapseSelection(false);
|
||||
}},
|
||||
{id:'separator', criteria: /^---+(\ |\s)*$/, handler: function(xed, rdom, block, text) {
|
||||
if(rdom.tree.isBlockContainer(block)) block = rdom.wrapAllInlineOrTextNodesAs("P", block, true)[0];
|
||||
rdom.insertNodeAt(rdom.createElement("HR"), block, "before");
|
||||
block.innerHTML = "";
|
||||
rdom.placeCaretAtStartOf(block);
|
||||
return true;
|
||||
}},
|
||||
{id:'heading', criteria: /^\=+[^=]*\=+(\ |\s)*$/, handler: function(xed, rdom, block, text) {
|
||||
var textWithoutEqualMarks = text.strip().replace(/=/g, "");
|
||||
var level = Math.min(6, parseInt((text.length - textWithoutEqualMarks.length) / 2))
|
||||
xed.handleApplyBlock('H' + level);
|
||||
block = rdom.getCurrentBlockElement();
|
||||
block.innerHTML = textWithoutEqualMarks;
|
||||
rdom.selectElement(block);
|
||||
rdom.collapseSelection();
|
||||
}}
|
||||
];
|
||||
},
|
||||
|
||||
getAutocompletions: function() {
|
||||
return [
|
||||
{
|
||||
id:'isbn',
|
||||
criteria: /@ISBN:\d+$/i,
|
||||
handler: function(xed, rdom, block, wrapper, text) {
|
||||
var isbn = text.split(":")[1]
|
||||
var korean = isbn.indexOf("97889") === 0 || isbn.indexOf("89") === 0
|
||||
var href = korean ?
|
||||
"http://www.aladdin.co.kr/shop/wproduct.aspx?ISBN=" :
|
||||
"http://www.amazon.com/exec/obidos/ISBN="
|
||||
var node = rdom.createElement('A');
|
||||
node.innerHTML = 'ISBN:' + isbn;
|
||||
node.href = href + isbn;
|
||||
node.className = 'external';
|
||||
node.title = 'ISBN:' + isbn;
|
||||
|
||||
wrapper.innerHTML = "";
|
||||
wrapper.appendChild(node);
|
||||
}
|
||||
},
|
||||
{
|
||||
id:'anchor',
|
||||
criteria: /@A(:(.+))?$/i,
|
||||
handler: function(xed, rdom, block, wrapper, text) {
|
||||
var m = text.match(/@A(:(.+))?$/i);
|
||||
var anchorId = m[2] ? m[2] : function() {
|
||||
var id = 0;
|
||||
while(true) {
|
||||
var element = rdom.$("a" + (id));
|
||||
if(!element) return "a" + id;
|
||||
id++;
|
||||
}
|
||||
}();
|
||||
|
||||
var node = rdom.createElement('A');
|
||||
node.id = anchorId;
|
||||
node.href = '#' + anchorId;
|
||||
node.className = 'anchor';
|
||||
node.title = 'Anchor ' + anchorId;
|
||||
node.innerHTML = '(' + anchorId + ')';
|
||||
|
||||
wrapper.innerHTML = "";
|
||||
wrapper.appendChild(node);
|
||||
}
|
||||
}
|
||||
];
|
||||
},
|
||||
|
||||
getTemplateProcessors: function() {
|
||||
return [
|
||||
{
|
||||
id:"datetime",
|
||||
handler:function(html) {
|
||||
var today = Date.get();
|
||||
var keywords = {
|
||||
year: today.getFullYear(),
|
||||
month: today.getMonth() + 1,
|
||||
date: today.getDate(),
|
||||
hour: today.getHours(),
|
||||
min: today.getMinutes(),
|
||||
sec: today.getSeconds()
|
||||
};
|
||||
|
||||
return html.replace(/\{xq:(year|month|date|hour|min|sec)\}/img, function(text, keyword) {
|
||||
return keywords[keyword] || keyword;
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue