Add consultation module assets and libraries
This commit is contained in:
216
konsultasi/libs/Trumbowyg/plugins/history/trumbowyg.history.js
Normal file
216
konsultasi/libs/Trumbowyg/plugins/history/trumbowyg.history.js
Normal file
@@ -0,0 +1,216 @@
|
||||
/*/* ===========================================================
|
||||
* 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: {
|
||||
// jshint camelcase:false
|
||||
de: {
|
||||
history: {
|
||||
redo: 'Wiederholen',
|
||||
undo: 'Rückgängig'
|
||||
}
|
||||
},
|
||||
en: {
|
||||
history: {
|
||||
redo: 'Redo',
|
||||
undo: 'Undo'
|
||||
}
|
||||
},
|
||||
da: {
|
||||
history: {
|
||||
redo: 'Annuller fortryd',
|
||||
undo: 'Fortryd'
|
||||
}
|
||||
},
|
||||
fr: {
|
||||
history: {
|
||||
redo: 'Annuler',
|
||||
undo: 'Rétablir'
|
||||
}
|
||||
},
|
||||
zh_tw: {
|
||||
history: {
|
||||
redo: '重做',
|
||||
undo: '復原'
|
||||
}
|
||||
},
|
||||
pt_br: {
|
||||
history: {
|
||||
redo: 'Refazer',
|
||||
undo: 'Desfazer'
|
||||
}
|
||||
},
|
||||
ko: {
|
||||
history: {
|
||||
redo: '다시 실행',
|
||||
undo: '되돌리기'
|
||||
}
|
||||
},
|
||||
// jshint camelcase:true
|
||||
},
|
||||
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 modified 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);
|
||||
1
konsultasi/libs/Trumbowyg/plugins/history/trumbowyg.history.min.js
vendored
Normal file
1
konsultasi/libs/Trumbowyg/plugins/history/trumbowyg.history.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(o){"use strict";o.extend(!0,o.trumbowyg,{langs:{de:{history:{redo:"Wiederholen",undo:"Rückgängig"}},en:{history:{redo:"Redo",undo:"Undo"}},da:{history:{redo:"Annuller fortryd",undo:"Fortryd"}},fr:{history:{redo:"Annuler",undo:"Rétablir"}},zh_tw:{history:{redo:"重做",undo:"復原"}},pt_br:{history:{redo:"Refazer",undo:"Desfazer"}},ko:{history:{redo:"다시 실행",undo:"되돌리기"}}},plugins:{history:{init:function(i){i.o.plugins.history=o.extend(!0,{_stack:[],_index:-1,_focusEl:void 0},i.o.plugins.history||{});var t={title:i.lang.history.redo,ico:"redo",key:"Y",fn:function(){if(i.o.plugins.history._index<i.o.plugins.history._stack.length-1){i.o.plugins.history._index+=1;var o=i.o.plugins.history._index,t=i.o.plugins.history._stack[o];i.execCmd("html",t),i.o.plugins.history._stack[o]=i.$ed.html(),l(),s()}}},n={title:i.lang.history.undo,ico:"undo",key:"Z",fn:function(){if(i.o.plugins.history._index>0){i.o.plugins.history._index-=1;var o=i.o.plugins.history._index,t=i.o.plugins.history._stack[o];i.execCmd("html",t),i.o.plugins.history._stack[o]=i.$ed.html(),l(),s()}}},e=function(){var t,n,e=i.o.plugins.history._index,r=i.o.plugins.history._stack,l=r.slice(-1)[0]||"<p></p>",u=r[e],h=i.$ed.html(),c=i.doc.getSelection().focusNode,g="",a=i.o.plugins.history._focusEl;t=o("<div>"+l+"</div>").find("*").map(function(){return this.localName}),n=o("<div>"+h+"</div>").find("*").map(function(){return this.localName}),c&&(i.o.plugins.history._focusEl=c,g=c.outerHTML||c.textContent),h!==u&&(g.slice(-1).match(/\s/)||!d(t,n)||i.o.plugins.history._index<=0||c!==a?(i.o.plugins.history._index+=1,i.o.plugins.history._stack=r.slice(0,i.o.plugins.history._index),i.o.plugins.history._stack.push(h)):i.o.plugins.history._stack[e]=h,s())},s=function(){var o=i.o.plugins.history._index,t=i.o.plugins.history._stack.length,n=o>0,e=0!==t&&o!==t-1;r("historyUndo",n),r("historyRedo",e)},r=function(o,t){var n=i.$box.find(".trumbowyg-"+o+"-button");t?n.removeClass("trumbowyg-disable"):n.hasClass("trumbowyg-disable")||n.addClass("trumbowyg-disable")},d=function(o,i){if(o===i)return!0;if(null==o||null==i)return!1;if(o.length!==i.length)return!1;for(var t=0;t<o.length;t+=1)if(o[t]!==i[t])return!1;return!0},l=function(){var o=i.doc.getSelection().focusNode,t=i.doc.createRange();o.childNodes.length>0&&(t.setStartAfter(o.childNodes[o.childNodes.length-1]),t.setEndAfter(o.childNodes[o.childNodes.length-1]),i.doc.getSelection().removeAllRanges(),i.doc.getSelection().addRange(t))};i.$c.on("tbwinit tbwchange",e),i.addBtnDef("historyRedo",t),i.addBtnDef("historyUndo",n)}}}})}(jQuery);
|
||||
Reference in New Issue
Block a user