Add WebCms
This commit is contained in:
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* plugin.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/*global tinymce:true */
|
||||
|
||||
tinymce.PluginManager.add('layer', function(editor) {
|
||||
function getParentLayer(node) {
|
||||
do {
|
||||
if (node.className && node.className.indexOf('mceItemLayer') != -1) {
|
||||
return node;
|
||||
}
|
||||
} while ((node = node.parentNode));
|
||||
}
|
||||
|
||||
function visualAid(e) {
|
||||
var dom = editor.dom;
|
||||
|
||||
tinymce.each(dom.select('div,p', e), function(e) {
|
||||
if (/^(absolute|relative|fixed)$/i.test(e.style.position)) {
|
||||
if (e.hasVisual) {
|
||||
dom.addClass(e, 'mceItemVisualAid');
|
||||
} else {
|
||||
dom.removeClass(e, 'mceItemVisualAid');
|
||||
}
|
||||
|
||||
dom.addClass(e, 'mceItemLayer');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function move(d) {
|
||||
var i, z = [], le = getParentLayer(editor.selection.getNode()), ci = -1, fi = -1, nl;
|
||||
|
||||
nl = [];
|
||||
tinymce.walk(editor.getBody(), function(n) {
|
||||
if (n.nodeType == 1 && /^(absolute|relative|static)$/i.test(n.style.position)) {
|
||||
nl.push(n);
|
||||
}
|
||||
}, 'childNodes');
|
||||
|
||||
// Find z-indexes
|
||||
for (i = 0; i < nl.length; i++) {
|
||||
z[i] = nl[i].style.zIndex ? parseInt(nl[i].style.zIndex, 10) : 0;
|
||||
|
||||
if (ci < 0 && nl[i] == le) {
|
||||
ci = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (d < 0) {
|
||||
// Move back
|
||||
|
||||
// Try find a lower one
|
||||
for (i = 0; i < z.length; i++) {
|
||||
if (z[i] < z[ci]) {
|
||||
fi = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fi > -1) {
|
||||
nl[ci].style.zIndex = z[fi];
|
||||
nl[fi].style.zIndex = z[ci];
|
||||
} else {
|
||||
if (z[ci] > 0) {
|
||||
nl[ci].style.zIndex = z[ci] - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Move forward
|
||||
|
||||
// Try find a higher one
|
||||
for (i = 0; i < z.length; i++) {
|
||||
if (z[i] > z[ci]) {
|
||||
fi = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fi > -1) {
|
||||
nl[ci].style.zIndex = z[fi];
|
||||
nl[fi].style.zIndex = z[ci];
|
||||
} else {
|
||||
nl[ci].style.zIndex = z[ci] + 1;
|
||||
}
|
||||
}
|
||||
|
||||
editor.execCommand('mceRepaint');
|
||||
}
|
||||
|
||||
function insertLayer() {
|
||||
var dom = editor.dom, p = dom.getPos(dom.getParent(editor.selection.getNode(), '*'));
|
||||
var body = editor.getBody();
|
||||
|
||||
editor.dom.add(body, 'div', {
|
||||
style: {
|
||||
position: 'absolute',
|
||||
left: p.x,
|
||||
top: (p.y > 20 ? p.y : 20),
|
||||
width: 100,
|
||||
height: 100
|
||||
},
|
||||
'class': 'mceItemVisualAid mceItemLayer'
|
||||
}, editor.selection.getContent() || editor.getLang('layer.content'));
|
||||
|
||||
// Workaround for IE where it messes up the JS engine if you insert a layer on IE 6,7
|
||||
if (tinymce.Env.ie) {
|
||||
dom.setHTML(body, body.innerHTML);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleAbsolute() {
|
||||
var le = getParentLayer(editor.selection.getNode());
|
||||
|
||||
if (!le) {
|
||||
le = editor.dom.getParent(editor.selection.getNode(), 'DIV,P,IMG');
|
||||
}
|
||||
|
||||
if (le) {
|
||||
if (le.style.position.toLowerCase() == "absolute") {
|
||||
editor.dom.setStyles(le, {
|
||||
position: '',
|
||||
left: '',
|
||||
top: '',
|
||||
width: '',
|
||||
height: ''
|
||||
});
|
||||
|
||||
editor.dom.removeClass(le, 'mceItemVisualAid');
|
||||
editor.dom.removeClass(le, 'mceItemLayer');
|
||||
} else {
|
||||
if (!le.style.left) {
|
||||
le.style.left = 20 + 'px';
|
||||
}
|
||||
|
||||
if (!le.style.top) {
|
||||
le.style.top = 20 + 'px';
|
||||
}
|
||||
|
||||
if (!le.style.width) {
|
||||
le.style.width = le.width ? (le.width + 'px') : '100px';
|
||||
}
|
||||
|
||||
if (!le.style.height) {
|
||||
le.style.height = le.height ? (le.height + 'px') : '100px';
|
||||
}
|
||||
|
||||
le.style.position = "absolute";
|
||||
|
||||
editor.dom.setAttrib(le, 'data-mce-style', '');
|
||||
editor.addVisual(editor.getBody());
|
||||
}
|
||||
|
||||
editor.execCommand('mceRepaint');
|
||||
editor.nodeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Register commands
|
||||
editor.addCommand('mceInsertLayer', insertLayer);
|
||||
|
||||
editor.addCommand('mceMoveForward', function() {
|
||||
move(1);
|
||||
});
|
||||
|
||||
editor.addCommand('mceMoveBackward', function() {
|
||||
move(-1);
|
||||
});
|
||||
|
||||
editor.addCommand('mceMakeAbsolute', function() {
|
||||
toggleAbsolute();
|
||||
});
|
||||
|
||||
// Register buttons
|
||||
editor.addButton('moveforward', {title: 'layer.forward_desc', cmd: 'mceMoveForward'});
|
||||
editor.addButton('movebackward', {title: 'layer.backward_desc', cmd: 'mceMoveBackward'});
|
||||
editor.addButton('absolute', {title: 'layer.absolute_desc', cmd: 'mceMakeAbsolute'});
|
||||
editor.addButton('insertlayer', {title: 'layer.insertlayer_desc', cmd: 'mceInsertLayer'});
|
||||
|
||||
editor.on('init', function() {
|
||||
if (tinymce.Env.ie) {
|
||||
editor.getDoc().execCommand('2D-Position', false, true);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove serialized styles when selecting a layer since it might be changed by a drag operation
|
||||
editor.on('mouseup', function(e) {
|
||||
var layer = getParentLayer(e.target);
|
||||
|
||||
if (layer) {
|
||||
editor.dom.setAttrib(layer, 'data-mce-style', '');
|
||||
}
|
||||
});
|
||||
|
||||
// Fixes edit focus issues with layers on Gecko
|
||||
// This will enable designMode while inside a layer and disable it when outside
|
||||
editor.on('mousedown', function(e) {
|
||||
var node = e.target, doc = editor.getDoc(), parent;
|
||||
|
||||
if (tinymce.Env.gecko) {
|
||||
if (getParentLayer(node)) {
|
||||
if (doc.designMode !== 'on') {
|
||||
doc.designMode = 'on';
|
||||
|
||||
// Repaint caret
|
||||
node = doc.body;
|
||||
parent = node.parentNode;
|
||||
parent.removeChild(node);
|
||||
parent.appendChild(node);
|
||||
}
|
||||
} else if (doc.designMode == 'on') {
|
||||
doc.designMode = 'off';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
editor.on('NodeChange', visualAid);
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
tinymce.PluginManager.add("layer",function(a){function b(a){do if(a.className&&-1!=a.className.indexOf("mceItemLayer"))return a;while(a=a.parentNode)}function c(b){var c=a.dom;tinymce.each(c.select("div,p",b),function(a){/^(absolute|relative|fixed)$/i.test(a.style.position)&&(a.hasVisual?c.addClass(a,"mceItemVisualAid"):c.removeClass(a,"mceItemVisualAid"),c.addClass(a,"mceItemLayer"))})}function d(c){var d,e,f=[],g=b(a.selection.getNode()),h=-1,i=-1;for(e=[],tinymce.walk(a.getBody(),function(a){1==a.nodeType&&/^(absolute|relative|static)$/i.test(a.style.position)&&e.push(a)},"childNodes"),d=0;d<e.length;d++)f[d]=e[d].style.zIndex?parseInt(e[d].style.zIndex,10):0,0>h&&e[d]==g&&(h=d);if(0>c){for(d=0;d<f.length;d++)if(f[d]<f[h]){i=d;break}i>-1?(e[h].style.zIndex=f[i],e[i].style.zIndex=f[h]):f[h]>0&&(e[h].style.zIndex=f[h]-1)}else{for(d=0;d<f.length;d++)if(f[d]>f[h]){i=d;break}i>-1?(e[h].style.zIndex=f[i],e[i].style.zIndex=f[h]):e[h].style.zIndex=f[h]+1}a.execCommand("mceRepaint")}function e(){var b=a.dom,c=b.getPos(b.getParent(a.selection.getNode(),"*")),d=a.getBody();a.dom.add(d,"div",{style:{position:"absolute",left:c.x,top:c.y>20?c.y:20,width:100,height:100},"class":"mceItemVisualAid mceItemLayer"},a.selection.getContent()||a.getLang("layer.content")),tinymce.Env.ie&&b.setHTML(d,d.innerHTML)}function f(){var c=b(a.selection.getNode());c||(c=a.dom.getParent(a.selection.getNode(),"DIV,P,IMG")),c&&("absolute"==c.style.position.toLowerCase()?(a.dom.setStyles(c,{position:"",left:"",top:"",width:"",height:""}),a.dom.removeClass(c,"mceItemVisualAid"),a.dom.removeClass(c,"mceItemLayer")):(c.style.left||(c.style.left="20px"),c.style.top||(c.style.top="20px"),c.style.width||(c.style.width=c.width?c.width+"px":"100px"),c.style.height||(c.style.height=c.height?c.height+"px":"100px"),c.style.position="absolute",a.dom.setAttrib(c,"data-mce-style",""),a.addVisual(a.getBody())),a.execCommand("mceRepaint"),a.nodeChanged())}a.addCommand("mceInsertLayer",e),a.addCommand("mceMoveForward",function(){d(1)}),a.addCommand("mceMoveBackward",function(){d(-1)}),a.addCommand("mceMakeAbsolute",function(){f()}),a.addButton("moveforward",{title:"layer.forward_desc",cmd:"mceMoveForward"}),a.addButton("movebackward",{title:"layer.backward_desc",cmd:"mceMoveBackward"}),a.addButton("absolute",{title:"layer.absolute_desc",cmd:"mceMakeAbsolute"}),a.addButton("insertlayer",{title:"layer.insertlayer_desc",cmd:"mceInsertLayer"}),a.on("init",function(){tinymce.Env.ie&&a.getDoc().execCommand("2D-Position",!1,!0)}),a.on("mouseup",function(c){var d=b(c.target);d&&a.dom.setAttrib(d,"data-mce-style","")}),a.on("mousedown",function(c){var d,e=c.target,f=a.getDoc();tinymce.Env.gecko&&(b(e)?"on"!==f.designMode&&(f.designMode="on",e=f.body,d=e.parentNode,d.removeChild(e),d.appendChild(e)):"on"==f.designMode&&(f.designMode="off"))}),a.on("NodeChange",c)});
|
||||
Reference in New Issue
Block a user