Seditio Source
Root |
./othercms/ips_4.3.4/applications/core/interface/ckeditor/ckeditor/plugins/ipsquote/plugin.js
CKEDITOR.plugins.add("ipsquote",{requires:"widget",icons:"ipsquote",hidpi:!0,allowedContent:"blockquote",init:function(e){e.widgets.add("ipsquote",{button:ips.getString("editorQuote"),template:ips.templates.render("core.editor.quote",{citation:ips.getString("editorQuote"),contents:""}),editables:{content:{selector:".ipsQuote_contents"}},upcast:function(b){if("blockquote"==b.name&&b.hasClass("ipsQuote")){var c={},a=0;for(a in b.attributes)"data-ipsquote-"==a.substr(0,14)&&(c[a.substr(14)]=b.attributes[a]);
b.children[0].hasClass("ipsQuote_citation")?b.children[0].setHtml(ips.utils.getCitation(c)):b.setHtml(ips.templates.render("core.editor.legacyQuoteUpcast",{citation:ips.utils.getCitation(c),contents:b.getHtml()}));return!0}},insert:function(){function b(){e.widgets.finalizeCreation(g)}var c=e.getSelectedHtml(!0),a=e.getSelection();a&&a.getSelectedElement();var a="function"==typeof this.defaults?this.defaults():this.defaults,a=CKEDITOR.dom.element.createFromHtml(this.template.output(a)),d,f=e.widgets.wrapElement(a,
this.name),g=new CKEDITOR.dom.documentFragment(f.getDocument());g.append(f);(d=e.widgets.initOn(a,this,!1))?(a=d.once("edit",function(a){if(a.data.dialog)d.once("dialog",function(a){a=a.data;var c,f;c=a.once("ok",b,null,null,20);f=a.once("cancel",function(a){a.data&&!1===a.data.hide||e.widgets.destroy(d,!0)});a.once("hide",function(){c.removeListener();f.removeListener()})});else b()},null,null,999),d.edit(),a.removeListener(),c?("\x3cp\x3e"===c.substr(0,1)?d.editables.content.setHtml(c):d.editables.content.setHtml("\x3cp\x3e"+
c+"\x3c/p\x3e"),c=e.createRange(),c.moveToElementEditablePosition(d.wrapper.getNext())):(c=e.createRange(),c.moveToElementEditablePosition(d.editables.content)),c.select()):b()}});e.on("key",function(b){if(13==b.data.keyCode)for(var c=e.getSelection().getRanges(),a=0;a<c.length;a++){b=c[a].getCommonAncestor();b=b instanceof CKEDITOR.dom.text?b.getParent():b;var d=b.getHtml(),d=d.replace(/\<br\>/,""),d=d.replace(/\<span.*?\>\s*?\<\/span\>/g,""),d=$.trim(d);"span"!=b.getName()||d||(b=b.getParent());
if("p"==b.getName()&&!d&&(d=b.getAscendant(function(a){return a instanceof CKEDITOR.dom.element&&"div"==a.getName()&&a.hasClass("ipsQuote_contents")},!0))){if(b.getNext()){for(var c=CKEDITOR.dom.element.createFromHtml(ips.templates.render("core.editor.quote",{citation:d.getParent().findOne(".ipsQuote_citation").getText(),contents:""})),f=b,a=[];f=f.getNext();)a.push(f);for(var f=c.findOne(".ipsQuote_contents"),g=0;g<a.length;g++)a[g].move(f);a=CKEDITOR.dom.element.createFromHtml("\x3cp\x3e\x3cbr\x3e\x3c/p\x3e");
a.insertAfter(d.getParent().getParent());c.insertAfter(a);e.widgets.initOn(c,"ipsquote");c=e.createRange();c.moveToPosition(a,CKEDITOR.POSITION_AFTER_START);e.getSelection().selectRanges([c]);b.remove();e.focus()}else b.remove(),e.focus(),c=e.createRange(),b=d.getParent().getParent(),d=b.getNext(),d||(d=new CKEDITOR.dom.element("p",e.document),d.insertAfter(b)),c.moveToPosition(d,CKEDITOR.POSITION_AFTER_START),e.getSelection().selectRanges([c]);return!1}}},this,0);e.addCommand("ipsQuoteBreakout",
{exec:function(b,c){var a=b.getSelection(),d=a.getSelectedElement();if(!d)for(var e=a.getRanges(),a=0;a<e.length;a++)d=e[a].getCommonAncestor();d=d.getAscendant(function(a){return a instanceof CKEDITOR.dom.element&&a.hasClass("cke_widget_wrapper")},!0);e=d.find(".ipsQuote_contents \x3e *");for(a=0;a<e.count();a++)b.insertElement(e.getItem(a).clone(!0));d.remove()}});e.addCommand("ipsQuoteRemove",{exec:function(b){var c=b.getSelection(),a=c.createBookmarks2(!0),d=c.getSelectedElement();if(!d)for(var c=
c.getRanges(),e=0;e<c.length;e++)d=c[e].getCommonAncestor();d.getAscendant(function(a){return a instanceof CKEDITOR.dom.element&&a.hasClass("cke_widget_wrapper")},!0).remove();b.getSelection().selectBookmarks(a)}});e.contextMenu&&(e.addMenuGroup("ipsQuote"),e.addMenuItem("ipsQuoteBreakout",{label:ips.getString("editorQuoteBreakout"),icon:null,command:"ipsQuoteBreakout",group:"ipsQuote"}),e.addMenuItem("ipsQuoteRemove",{label:ips.getString("editorQuoteRemove"),icon:null,command:"ipsQuoteRemove",group:"ipsQuote"}),
e.contextMenu.addListener(function(b,c){if(b.getAscendant(function(a){return a instanceof CKEDITOR.dom.element&&a.hasClass("ipsQuote")},!0)||b.find(".ipsQuote").count())return{ipsQuoteBreakout:CKEDITOR.TRISTATE_OFF,ipsQuoteRemove:CKEDITOR.TRISTATE_OFF}}))}});