Add consultation module assets and libraries
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
/* ===========================================================
|
||||
* trumbowyg.preformatted.js v1.0
|
||||
* Preformatted plugin for Trumbowyg
|
||||
* http://alex-d.github.com/Trumbowyg
|
||||
* ===========================================================
|
||||
* Author : Casella Edoardo (Civile)
|
||||
*/
|
||||
|
||||
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
$.extend(true, $.trumbowyg, {
|
||||
langs: {
|
||||
// jshint camelcase:false
|
||||
en: {
|
||||
preformatted: 'Code sample <pre>'
|
||||
},
|
||||
da: {
|
||||
preformatted: 'Præformateret <pre>'
|
||||
},
|
||||
fr: {
|
||||
preformatted: 'Exemple de code <pre>'
|
||||
},
|
||||
it: {
|
||||
preformatted: 'Codice <pre>'
|
||||
},
|
||||
zh_cn: {
|
||||
preformatted: '代码示例 <pre>'
|
||||
},
|
||||
ru: {
|
||||
preformatted: 'Пример кода <pre>'
|
||||
},
|
||||
ja: {
|
||||
preformatted: 'コードサンプル <pre>'
|
||||
},
|
||||
tr: {
|
||||
preformatted: 'Kod örneği <pre>'
|
||||
},
|
||||
zh_tw: {
|
||||
preformatted: '代碼範例 <pre>'
|
||||
},
|
||||
pt_br: {
|
||||
preformatted: 'Exemple de código <pre>'
|
||||
},
|
||||
ko: {
|
||||
preformatted: '코드 예제 <pre>'
|
||||
},
|
||||
},
|
||||
// jshint camelcase:true
|
||||
|
||||
plugins: {
|
||||
preformatted: {
|
||||
init: function (trumbowyg) {
|
||||
var btnDef = {
|
||||
fn: function () {
|
||||
trumbowyg.saveRange();
|
||||
var text = trumbowyg.getRangeText();
|
||||
if (text.replace(/\s/g, '') !== '') {
|
||||
try {
|
||||
var curtag = getSelectionParentElement().tagName.toLowerCase();
|
||||
if (curtag === 'code' || curtag === 'pre') {
|
||||
return unwrapCode();
|
||||
}
|
||||
else {
|
||||
trumbowyg.execCmd('insertHTML', '<pre><code>' + strip(text) + '</code></pre>');
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
},
|
||||
tag: 'pre'
|
||||
};
|
||||
|
||||
trumbowyg.addBtnDef('preformatted', btnDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* GetSelectionParentElement
|
||||
*/
|
||||
function getSelectionParentElement() {
|
||||
var parentEl = null,
|
||||
selection;
|
||||
|
||||
if (window.getSelection) {
|
||||
selection = window.getSelection();
|
||||
if (selection.rangeCount) {
|
||||
parentEl = selection.getRangeAt(0).commonAncestorContainer;
|
||||
if (parentEl.nodeType !== 1) {
|
||||
parentEl = parentEl.parentNode;
|
||||
}
|
||||
}
|
||||
} else if ((selection = document.selection) && selection.type !== 'Control') {
|
||||
parentEl = selection.createRange().parentElement();
|
||||
}
|
||||
|
||||
return parentEl;
|
||||
}
|
||||
|
||||
/*
|
||||
* Strip
|
||||
* returns a text without HTML tags
|
||||
*/
|
||||
function strip(html) {
|
||||
var tmp = document.createElement('DIV');
|
||||
tmp.innerHTML = html;
|
||||
return tmp.textContent || tmp.innerText || '';
|
||||
}
|
||||
|
||||
/*
|
||||
* UnwrapCode
|
||||
* ADD/FIX: to improve, works but can be better
|
||||
* "paranoic" solution
|
||||
*/
|
||||
function unwrapCode() {
|
||||
var container = null;
|
||||
|
||||
if (document.selection) { //for IE
|
||||
container = document.selection.createRange().parentElement();
|
||||
} else {
|
||||
var select = window.getSelection();
|
||||
if (select.rangeCount > 0) {
|
||||
container = select.getRangeAt(0).startContainer.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
//'paranoic' unwrap
|
||||
var ispre = $(container).contents().closest('pre').length;
|
||||
var iscode = $(container).contents().closest('code').length;
|
||||
|
||||
if (ispre && iscode) {
|
||||
$(container).contents().unwrap('code').unwrap('pre');
|
||||
} else if (ispre) {
|
||||
$(container).contents().unwrap('pre');
|
||||
} else if (iscode) {
|
||||
$(container).contents().unwrap('code');
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
||||
1
konsultasi/libs/Trumbowyg/plugins/preformatted/trumbowyg.preformatted.min.js
vendored
Normal file
1
konsultasi/libs/Trumbowyg/plugins/preformatted/trumbowyg.preformatted.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){"use strict";function t(){var e,t=null;return window.getSelection?(e=window.getSelection(),e.rangeCount&&(t=e.getRangeAt(0).commonAncestorContainer,1!==t.nodeType&&(t=t.parentNode))):(e=document.selection)&&"Control"!==e.type&&(t=e.createRange().parentElement()),t}function r(e){var t=document.createElement("DIV");return t.innerHTML=e,t.textContent||t.innerText||""}function n(){var t=null;if(document.selection)t=document.selection.createRange().parentElement();else{var r=window.getSelection();r.rangeCount>0&&(t=r.getRangeAt(0).startContainer.parentNode)}var n=e(t).contents().closest("pre").length,o=e(t).contents().closest("code").length;n&&o?e(t).contents().unwrap("code").unwrap("pre"):n?e(t).contents().unwrap("pre"):o&&e(t).contents().unwrap("code")}e.extend(!0,e.trumbowyg,{langs:{en:{preformatted:"Code sample <pre>"},da:{preformatted:"Præformateret <pre>"},fr:{preformatted:"Exemple de code <pre>"},it:{preformatted:"Codice <pre>"},zh_cn:{preformatted:"代码示例 <pre>"},ru:{preformatted:"Пример кода <pre>"},ja:{preformatted:"コードサンプル <pre>"},tr:{preformatted:"Kod örneği <pre>"},zh_tw:{preformatted:"代碼範例 <pre>"},pt_br:{preformatted:"Exemple de código <pre>"},ko:{preformatted:"코드 예제 <pre>"}},plugins:{preformatted:{init:function(e){var o={fn:function(){e.saveRange();var o=e.getRangeText();if(""!==o.replace(/\s/g,""))try{var a=t().tagName.toLowerCase();if("code"===a||"pre"===a)return n();e.execCmd("insertHTML","<pre><code>"+r(o)+"</code></pre>")}catch(p){}},tag:"pre"};e.addBtnDef("preformatted",o)}}}})}(jQuery);
|
||||
Reference in New Issue
Block a user