gui 에디터 추가

This commit is contained in:
Hide_D committed 2018-08-30 01:25:45 +09:00
1 parent e2ee292e47
commit 613425855d
74 files changed
+7344 -8

No files matched your search

@@ -0,0 +1,190 @@
/*/* ===========================================================
* trumbowyg.history.js v1.0
* history plugin for Trumbowyg
* http://alex-d.github.com/Trumbowyg
* ===========================================================
* Author : Sven Dunemann [dunemann@forelabs.eu]
*/
(function ($) {
'use strict';
$.extend(true, $.trumbowyg, {
langs: {
de: {
history: {
redo: 'Wiederholen',
undo: 'Rückgängig'
}
},
en: {
history: {
redo: 'Redo',
undo: 'Undo'
}
},
fr: {
history: {
redo: 'Annuler',
undo: 'Rétablir'
}
}
},
plugins: {
history: {
init: function (t) {
t.o.plugins.history = $.extend(true, {
_stack: [],
_index: -1,
_focusEl: undefined
}, t.o.plugins.history || {});
var btnBuildDefRedo = {
title: t.lang.history.redo,
ico: 'redo',
key: 'Y',
fn: function () {
if (t.o.plugins.history._index < t.o.plugins.history._stack.length - 1) {
t.o.plugins.history._index += 1;
var index = t.o.plugins.history._index;
var newState = t.o.plugins.history._stack[index];
t.execCmd('html', newState);
// because of some semantic optimisations we have to save the state back
// to history
t.o.plugins.history._stack[index] = t.$ed.html();
carretToEnd();
toggleButtonStates();
}
}
};
var btnBuildDefUndo = {
title: t.lang.history.undo,
ico: 'undo',
key: 'Z',
fn: function () {
if (t.o.plugins.history._index > 0) {
t.o.plugins.history._index -= 1;
var index = t.o.plugins.history._index,
newState = t.o.plugins.history._stack[index];
t.execCmd('html', newState);
// because of some semantic optimisations we have to save the state back
// to history
t.o.plugins.history._stack[index] = t.$ed.html();
carretToEnd();
toggleButtonStates();
}
}
};
var pushToHistory = function () {
var index = t.o.plugins.history._index,
stack = t.o.plugins.history._stack,
latestState = stack.slice(-1)[0] || '<p></p>',
prevState = stack[index],
newState = t.$ed.html(),
focusEl = t.doc.getSelection().focusNode,
focusElText = '',
latestStateTagsList,
newStateTagsList,
prevFocusEl = t.o.plugins.history._focusEl;
latestStateTagsList = $('<div>' + latestState + '</div>').find('*').map(function () {
return this.localName;
});
newStateTagsList = $('<div>' + newState + '</div>').find('*').map(function () {
return this.localName;
});
if (focusEl) {
t.o.plugins.history._focusEl = focusEl;
focusElText = focusEl.outerHTML || focusEl.textContent;
}
if (newState !== prevState) {
// a new stack entry is defined when current insert ends on a whitespace character
// or count of node elements has been changed
// or focused element differs from previous one
if (focusElText.slice(-1).match(/\s/) ||
!arraysAreIdentical(latestStateTagsList, newStateTagsList) ||
t.o.plugins.history._index <= 0 || focusEl !== prevFocusEl)
{
t.o.plugins.history._index += 1;
// remove newer entries in history when something new was added
// because timeline was changes with interaction
t.o.plugins.history._stack = stack.slice(
0, t.o.plugins.history._index
);
// now add new state to modifed history
t.o.plugins.history._stack.push(newState);
} else {
// modify last stack entry
t.o.plugins.history._stack[index] = newState;
}
toggleButtonStates();
}
};
var toggleButtonStates = function () {
var index = t.o.plugins.history._index,
stackSize = t.o.plugins.history._stack.length,
undoState = (index > 0),
redoState = (stackSize !== 0 && index !== stackSize - 1);
toggleButtonState('historyUndo', undoState);
toggleButtonState('historyRedo', redoState);
};
var toggleButtonState = function (btn, enable) {
var button = t.$box.find('.trumbowyg-' + btn + '-button');
if (enable) {
button.removeClass('trumbowyg-disable');
} else if (!button.hasClass('trumbowyg-disable')) {
button.addClass('trumbowyg-disable');
}
};
var arraysAreIdentical = function (a, b) {
if (a === b) {
return true;
}
if (a == null || b == null) {
return false;
}
if (a.length !== b.length) {
return false;
}
for (var i = 0; i < a.length; i += 1) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
};
var carretToEnd = function () {
var node = t.doc.getSelection().focusNode,
range = t.doc.createRange();
if (node.childNodes.length > 0) {
range.setStartAfter(node.childNodes[node.childNodes.length - 1]);
range.setEndAfter(node.childNodes[node.childNodes.length - 1]);
t.doc.getSelection().removeAllRanges();
t.doc.getSelection().addRange(range);
}
};
t.$c.on('tbwinit tbwchange', pushToHistory);
t.addBtnDef('historyRedo', btnBuildDefRedo);
t.addBtnDef('historyUndo', btnBuildDefUndo);
}
}
}
});
})(jQuery);
@@ -0,0 +1 @@
!function(i){"use strict";i.extend(!0,i.trumbowyg,{langs:{de:{history:{redo:"Wiederholen",undo:"Rückgängig"}},en:{history:{redo:"Redo",undo:"Undo"}},fr:{history:{redo:"Annuler",undo:"Rétablir"}}},plugins:{history:{init:function(o){o.o.plugins.history=i.extend(!0,{_stack:[],_index:-1,_focusEl:void 0},o.o.plugins.history||{});var t={title:o.lang.history.redo,ico:"redo",key:"Y",fn:function(){if(o.o.plugins.history._index<o.o.plugins.history._stack.length-1){o.o.plugins.history._index+=1;var i=o.o.plugins.history._index,t=o.o.plugins.history._stack[i];o.execCmd("html",t),o.o.plugins.history._stack[i]=o.$ed.html(),d(),e()}}},n={title:o.lang.history.undo,ico:"undo",key:"Z",fn:function(){if(o.o.plugins.history._index>0){o.o.plugins.history._index-=1;var i=o.o.plugins.history._index,t=o.o.plugins.history._stack[i];o.execCmd("html",t),o.o.plugins.history._stack[i]=o.$ed.html(),d(),e()}}},s=function(){var t,n,s=o.o.plugins.history._index,r=o.o.plugins.history._stack,d=r.slice(-1)[0]||"<p></p>",u=r[s],h=o.$ed.html(),c=o.doc.getSelection().focusNode,g="",a=o.o.plugins.history._focusEl;t=i("<div>"+d+"</div>").find("*").map(function(){return this.localName}),n=i("<div>"+h+"</div>").find("*").map(function(){return this.localName}),c&&(o.o.plugins.history._focusEl=c,g=c.outerHTML||c.textContent),h!==u&&(g.slice(-1).match(/\s/)||!l(t,n)||o.o.plugins.history._index<=0||c!==a?(o.o.plugins.history._index+=1,o.o.plugins.history._stack=r.slice(0,o.o.plugins.history._index),o.o.plugins.history.Line truncated