in src/OrchardCore.Modules/OrchardCore.Resources/Assets/trumbowyg/js/trumbowyg.js [213:470]
var Trumbowyg = function (editorElem, options) {
var t = this,
trumbowygIconsId = 'trumbowyg-icons',
$trumbowyg = $.trumbowyg;
// Get the document of the element. It use to makes the plugin
// compatible on iframes.
t.doc = editorElem.ownerDocument || document;
// jQuery object of the editor
t.$ta = $(editorElem); // $ta : Textarea
t.$c = $(editorElem); // $c : creator
options = options || {};
// Localization management
if (options.lang != null || $trumbowyg.langs[options.lang] != null) {
t.lang = $.extend(true, {}, $trumbowyg.langs.en, $trumbowyg.langs[options.lang]);
} else {
t.lang = $trumbowyg.langs.en;
}
t.hideButtonTexts = $trumbowyg.hideButtonTexts != null ? $trumbowyg.hideButtonTexts : options.hideButtonTexts;
// SVG path
var svgPathOption = $trumbowyg.svgPath != null ? $trumbowyg.svgPath : options.svgPath;
t.hasSvg = svgPathOption !== false;
t.svgPath = !!t.doc.querySelector('base') ? window.location.href.split('#')[0] : '';
if ($('#' + trumbowygIconsId, t.doc).length === 0 && svgPathOption !== false) {
if (svgPathOption == null) {
// Hack to get svgPathOption based on trumbowyg.js path
var scriptElements = document.getElementsByTagName('script');
for (var i = 0; i < scriptElements.length; i += 1) {
var source = scriptElements[i].src;
var matches = source.match('trumbowyg(\.min)?\.js');
if (matches != null) {
svgPathOption = source.substring(0, source.indexOf(matches[0])) + 'ui/icons.svg';
}
}
if (svgPathOption == null) {
console.warn('You must define svgPath: https://goo.gl/CfTY9U'); // jshint ignore:line
}
}
var div = t.doc.createElement('div');
div.id = trumbowygIconsId;
t.doc.body.insertBefore(div, t.doc.body.childNodes[0]);
$.ajax({
async: true,
type: 'GET',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
dataType: 'xml',
crossDomain: true,
url: svgPathOption,
data: null,
beforeSend: null,
complete: null,
success: function (data) {
div.innerHTML = new XMLSerializer().serializeToString(data.documentElement);
}
});
}
/**
* When the button is associated to a empty object
* fn and title attributes are defined from the button key value
*
* For example
* foo: {}
* is equivalent to :
* foo: {
* fn: 'foo',
* title: this.lang.foo
* }
*/
var h = t.lang.header, // Header translation
isBlinkFunction = function () {
return (window.chrome || (window.Intl && Intl.v8BreakIterator)) && 'CSS' in window;
};
t.btnsDef = {
viewHTML: {
fn: 'toggle',
class: 'trumbowyg-not-disable',
},
undo: {
isSupported: isBlinkFunction,
key: 'Z'
},
redo: {
isSupported: isBlinkFunction,
key: 'Y'
},
p: {
fn: 'formatBlock'
},
blockquote: {
fn: 'formatBlock'
},
h1: {
fn: 'formatBlock',
title: h + ' 1'
},
h2: {
fn: 'formatBlock',
title: h + ' 2'
},
h3: {
fn: 'formatBlock',
title: h + ' 3'
},
h4: {
fn: 'formatBlock',
title: h + ' 4'
},
h5: {
fn: 'formatBlock',
title: h + ' 5'
},
h6: {
fn: 'formatBlock',
title: h + ' 6'
},
subscript: {
tag: 'sub'
},
superscript: {
tag: 'sup'
},
bold: {
key: 'B',
tag: 'b'
},
italic: {
key: 'I',
tag: 'i'
},
underline: {
tag: 'u'
},
strikethrough: {
tag: 'strike'
},
strong: {
fn: 'bold',
key: 'B'
},
em: {
fn: 'italic',
key: 'I'
},
del: {
fn: 'strikethrough'
},
createLink: {
key: 'K',
tag: 'a'
},
unlink: {},
insertImage: {},
justifyLeft: {
tag: 'left',
forceCss: true
},
justifyCenter: {
tag: 'center',
forceCss: true
},
justifyRight: {
tag: 'right',
forceCss: true
},
justifyFull: {
tag: 'justify',
forceCss: true
},
unorderedList: {
fn: 'insertUnorderedList',
tag: 'ul'
},
orderedList: {
fn: 'insertOrderedList',
tag: 'ol'
},
horizontalRule: {
fn: 'insertHorizontalRule'
},
removeformat: {},
fullscreen: {
class: 'trumbowyg-not-disable'
},
close: {
fn: 'destroy',
class: 'trumbowyg-not-disable'
},
// Dropdowns
formatting: {
dropdown: ['p', 'blockquote', 'h1', 'h2', 'h3', 'h4'],
ico: 'p'
},
link: {
dropdown: ['createLink', 'unlink']
}
};
// Defaults Options
t.o = $.extend(true, {}, $trumbowyg.defaultOptions, options);
if (!t.o.hasOwnProperty('imgDblClickHandler')) {
t.o.imgDblClickHandler = t.getDefaultImgDblClickHandler();
}
t.urlPrefix = t.setupUrlPrefix();
t.disabled = t.o.disabled || (editorElem.nodeName === 'TEXTAREA' && editorElem.disabled);
if (options.btns) {
t.o.btns = options.btns;
} else if (!t.o.semantic) {
t.o.btns[3] = ['bold', 'italic', 'underline', 'strikethrough'];
}
$.each(t.o.btnsDef, function (btnName, btnDef) {
t.addBtnDef(btnName, btnDef);
});
// put this here in the event it would be merged in with options
t.eventNamespace = 'trumbowyg-event';
// Keyboard shortcuts are load in this array
t.keys = [];
// Tag to button dynamically hydrated
t.tagToButton = {};
t.tagHandlers = [];
// Admit multiple paste handlers
t.pasteHandlers = [].concat(t.o.pasteHandlers);
// Check if browser is IE
t.isIE = navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') !== -1;
// Check if we are on macOs
t.isMac = navigator.platform.toUpperCase().indexOf('MAC') !== -1;
t.init();
};