Path: blob/main/website/GAUSS/inputs-ext/wysihtml5/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.js
2946 views
!function($, wysi) {1"use strict";23var tpl = {4"font-styles": function(locale, options) {5var size = (options && options.size) ? ' btn-'+options.size : '';6return "<li class='dropdown'>" +7"<a class='btn dropdown-toggle" + size + "' data-toggle='dropdown' href='#'>" +8"<i class='icon-font'></i> <span class='current-font'>" + locale.font_styles.normal + "</span> <b class='caret'></b>" +9"</a>" +10"<ul class='dropdown-menu'>" +11"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='div' tabindex='-1'>" + locale.font_styles.normal + "</a></li>" +12"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h1' tabindex='-1'>" + locale.font_styles.h1 + "</a></li>" +13"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h2' tabindex='-1'>" + locale.font_styles.h2 + "</a></li>" +14"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h3' tabindex='-1'>" + locale.font_styles.h3 + "</a></li>" +15"</ul>" +16"</li>";17},1819"emphasis": function(locale, options) {20var size = (options && options.size) ? ' btn-'+options.size : '';21return "<li>" +22"<div class='btn-group'>" +23"<a class='btn" + size + "' data-wysihtml5-command='bold' title='CTRL+B' tabindex='-1'>" + locale.emphasis.bold + "</a>" +24"<a class='btn" + size + "' data-wysihtml5-command='italic' title='CTRL+I' tabindex='-1'>" + locale.emphasis.italic + "</a>" +25"<a class='btn" + size + "' data-wysihtml5-command='underline' title='CTRL+U' tabindex='-1'>" + locale.emphasis.underline + "</a>" +26"</div>" +27"</li>";28},2930"lists": function(locale, options) {31var size = (options && options.size) ? ' btn-'+options.size : '';32return "<li>" +33"<div class='btn-group'>" +34"<a class='btn" + size + "' data-wysihtml5-command='insertUnorderedList' title='" + locale.lists.unordered + "' tabindex='-1'><i class='icon-list'></i></a>" +35"<a class='btn" + size + "' data-wysihtml5-command='insertOrderedList' title='" + locale.lists.ordered + "' tabindex='-1'><i class='icon-th-list'></i></a>" +36"<a class='btn" + size + "' data-wysihtml5-command='Outdent' title='" + locale.lists.outdent + "' tabindex='-1'><i class='icon-indent-right'></i></a>" +37"<a class='btn" + size + "' data-wysihtml5-command='Indent' title='" + locale.lists.indent + "' tabindex='-1'><i class='icon-indent-left'></i></a>" +38"</div>" +39"</li>";40},4142"link": function(locale, options) {43var size = (options && options.size) ? ' btn-'+options.size : '';44return "<li>" +45"<div class='bootstrap-wysihtml5-insert-link-modal modal hide fade'>" +46"<div class='modal-header'>" +47"<a class='close' data-dismiss='modal'>×</a>" +48"<h3>" + locale.link.insert + "</h3>" +49"</div>" +50"<div class='modal-body'>" +51"<input value='http://' class='bootstrap-wysihtml5-insert-link-url input-xlarge'>" +52"</div>" +53"<div class='modal-footer'>" +54"<a href='#' class='btn' data-dismiss='modal'>" + locale.link.cancel + "</a>" +55"<a href='#' class='btn btn-primary' data-dismiss='modal'>" + locale.link.insert + "</a>" +56"</div>" +57"</div>" +58"<a class='btn" + size + "' data-wysihtml5-command='createLink' title='" + locale.link.insert + "' tabindex='-1'><i class='icon-share'></i></a>" +59"</li>";60},6162"image": function(locale, options) {63var size = (options && options.size) ? ' btn-'+options.size : '';64return "<li>" +65"<div class='bootstrap-wysihtml5-insert-image-modal modal hide fade'>" +66"<div class='modal-header'>" +67"<a class='close' data-dismiss='modal'>×</a>" +68"<h3>" + locale.image.insert + "</h3>" +69"</div>" +70"<div class='modal-body'>" +71"<input value='http://' class='bootstrap-wysihtml5-insert-image-url input-xlarge'>" +72"</div>" +73"<div class='modal-footer'>" +74"<a href='#' class='btn' data-dismiss='modal'>" + locale.image.cancel + "</a>" +75"<a href='#' class='btn btn-primary' data-dismiss='modal'>" + locale.image.insert + "</a>" +76"</div>" +77"</div>" +78"<a class='btn" + size + "' data-wysihtml5-command='insertImage' title='" + locale.image.insert + "' tabindex='-1'><i class='icon-picture'></i></a>" +79"</li>";80},8182"html": function(locale, options) {83var size = (options && options.size) ? ' btn-'+options.size : '';84return "<li>" +85"<div class='btn-group'>" +86"<a class='btn" + size + "' data-wysihtml5-action='change_view' title='" + locale.html.edit + "' tabindex='-1'><i class='icon-pencil'></i></a>" +87"</div>" +88"</li>";89},9091"color": function(locale, options) {92var size = (options && options.size) ? ' btn-'+options.size : '';93return "<li class='dropdown'>" +94"<a class='btn dropdown-toggle" + size + "' data-toggle='dropdown' href='#' tabindex='-1'>" +95"<span class='current-color'>" + locale.colours.black + "</span> <b class='caret'></b>" +96"</a>" +97"<ul class='dropdown-menu'>" +98"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='black'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='black'>" + locale.colours.black + "</a></li>" +99"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='silver'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='silver'>" + locale.colours.silver + "</a></li>" +100"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='gray'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='gray'>" + locale.colours.gray + "</a></li>" +101"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='maroon'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='maroon'>" + locale.colours.maroon + "</a></li>" +102"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='red'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='red'>" + locale.colours.red + "</a></li>" +103"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='purple'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='purple'>" + locale.colours.purple + "</a></li>" +104"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='green'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='green'>" + locale.colours.green + "</a></li>" +105"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='olive'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='olive'>" + locale.colours.olive + "</a></li>" +106"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='navy'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='navy'>" + locale.colours.navy + "</a></li>" +107"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='blue'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='blue'>" + locale.colours.blue + "</a></li>" +108"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='orange'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='orange'>" + locale.colours.orange + "</a></li>" +109"</ul>" +110"</li>";111}112};113114var templates = function(key, locale, options) {115return tpl[key](locale, options);116};117118119var Wysihtml5 = function(el, options) {120this.el = el;121var toolbarOpts = options || defaultOptions;122for(var t in toolbarOpts.customTemplates) {123tpl[t] = toolbarOpts.customTemplates[t];124}125this.toolbar = this.createToolbar(el, toolbarOpts);126this.editor = this.createEditor(options);127128window.editor = this.editor;129130$('iframe.wysihtml5-sandbox').each(function(i, el){131$(el.contentWindow).off('focus.wysihtml5').on({132'focus.wysihtml5' : function(){133$('li.dropdown').removeClass('open');134}135});136});137};138139Wysihtml5.prototype = {140141constructor: Wysihtml5,142143createEditor: function(options) {144options = options || {};145146// Add the toolbar to a clone of the options object so multiple instances147// of the WYISYWG don't break because "toolbar" is already defined148options = $.extend(true, {}, options);149options.toolbar = this.toolbar[0];150151var editor = new wysi.Editor(this.el[0], options);152153if(options && options.events) {154for(var eventName in options.events) {155editor.on(eventName, options.events[eventName]);156}157}158return editor;159},160161createToolbar: function(el, options) {162var self = this;163var toolbar = $("<ul/>", {164'class' : "wysihtml5-toolbar",165'style': "display:none"166});167var culture = options.locale || defaultOptions.locale || "en";168for(var key in defaultOptions) {169var value = false;170171if(options[key] !== undefined) {172if(options[key] === true) {173value = true;174}175} else {176value = defaultOptions[key];177}178179if(value === true) {180toolbar.append(templates(key, locale[culture], options));181182if(key === "html") {183this.initHtml(toolbar);184}185186if(key === "link") {187this.initInsertLink(toolbar);188}189190if(key === "image") {191this.initInsertImage(toolbar);192}193}194}195196if(options.toolbar) {197for(key in options.toolbar) {198toolbar.append(options.toolbar[key]);199}200}201202toolbar.find("a[data-wysihtml5-command='formatBlock']").click(function(e) {203var target = e.target || e.srcElement;204var el = $(target);205self.toolbar.find('.current-font').text(el.html());206});207208toolbar.find("a[data-wysihtml5-command='foreColor']").click(function(e) {209var target = e.target || e.srcElement;210var el = $(target);211self.toolbar.find('.current-color').text(el.html());212});213214this.el.before(toolbar);215216return toolbar;217},218219initHtml: function(toolbar) {220var changeViewSelector = "a[data-wysihtml5-action='change_view']";221toolbar.find(changeViewSelector).click(function(e) {222toolbar.find('a.btn').not(changeViewSelector).toggleClass('disabled');223});224},225226initInsertImage: function(toolbar) {227var self = this;228var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal');229var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url');230var insertButton = insertImageModal.find('a.btn-primary');231var initialValue = urlInput.val();232var caretBookmark;233234var insertImage = function() {235var url = urlInput.val();236urlInput.val(initialValue);237self.editor.currentView.element.focus();238if (caretBookmark) {239self.editor.composer.selection.setBookmark(caretBookmark);240caretBookmark = null;241}242self.editor.composer.commands.exec("insertImage", url);243};244245urlInput.keypress(function(e) {246if(e.which == 13) {247insertImage();248insertImageModal.modal('hide');249}250});251252insertButton.click(insertImage);253254insertImageModal.on('shown', function() {255urlInput.focus();256});257258insertImageModal.on('hide', function() {259self.editor.currentView.element.focus();260});261262toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() {263var activeButton = $(this).hasClass("wysihtml5-command-active");264265if (!activeButton) {266self.editor.currentView.element.focus(false);267caretBookmark = self.editor.composer.selection.getBookmark();268insertImageModal.appendTo('body').modal('show');269insertImageModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {270e.stopPropagation();271});272return false;273}274else {275return true;276}277});278},279280initInsertLink: function(toolbar) {281var self = this;282var insertLinkModal = toolbar.find('.bootstrap-wysihtml5-insert-link-modal');283var urlInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-url');284var insertButton = insertLinkModal.find('a.btn-primary');285var initialValue = urlInput.val();286var caretBookmark;287288var insertLink = function() {289var url = urlInput.val();290urlInput.val(initialValue);291self.editor.currentView.element.focus();292if (caretBookmark) {293self.editor.composer.selection.setBookmark(caretBookmark);294caretBookmark = null;295}296self.editor.composer.commands.exec("createLink", {297href: url,298target: "_blank",299rel: "nofollow"300});301};302var pressedEnter = false;303304urlInput.keypress(function(e) {305if(e.which == 13) {306insertLink();307insertLinkModal.modal('hide');308}309});310311insertButton.click(insertLink);312313insertLinkModal.on('shown', function() {314urlInput.focus();315});316317insertLinkModal.on('hide', function() {318self.editor.currentView.element.focus();319});320321toolbar.find('a[data-wysihtml5-command=createLink]').click(function() {322var activeButton = $(this).hasClass("wysihtml5-command-active");323324if (!activeButton) {325self.editor.currentView.element.focus(false);326caretBookmark = self.editor.composer.selection.getBookmark();327insertLinkModal.appendTo('body').modal('show');328insertLinkModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {329e.stopPropagation();330});331return false;332}333else {334return true;335}336});337}338};339340// these define our public api341var methods = {342resetDefaults: function() {343$.fn.wysihtml5.defaultOptions = $.extend(true, {}, $.fn.wysihtml5.defaultOptionsCache);344},345bypassDefaults: function(options) {346return this.each(function () {347var $this = $(this);348$this.data('wysihtml5', new Wysihtml5($this, options));349});350},351shallowExtend: function (options) {352var settings = $.extend({}, $.fn.wysihtml5.defaultOptions, options || {});353var that = this;354return methods.bypassDefaults.apply(that, [settings]);355},356deepExtend: function(options) {357var settings = $.extend(true, {}, $.fn.wysihtml5.defaultOptions, options || {});358var that = this;359return methods.bypassDefaults.apply(that, [settings]);360},361init: function(options) {362var that = this;363return methods.shallowExtend.apply(that, [options]);364}365};366367$.fn.wysihtml5 = function ( method ) {368if ( methods[method] ) {369return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));370} else if ( typeof method === 'object' || ! method ) {371return methods.init.apply( this, arguments );372} else {373$.error( 'Method ' + method + ' does not exist on jQuery.wysihtml5' );374}375};376377$.fn.wysihtml5.Constructor = Wysihtml5;378379var defaultOptions = $.fn.wysihtml5.defaultOptions = {380"font-styles": true,381"color": false,382"emphasis": true,383"lists": true,384"html": false,385"link": true,386"image": true,387events: {},388parserRules: {389classes: {390// (path_to_project/lib/css/wysiwyg-color.css)391"wysiwyg-color-silver" : 1,392"wysiwyg-color-gray" : 1,393"wysiwyg-color-white" : 1,394"wysiwyg-color-maroon" : 1,395"wysiwyg-color-red" : 1,396"wysiwyg-color-purple" : 1,397"wysiwyg-color-fuchsia" : 1,398"wysiwyg-color-green" : 1,399"wysiwyg-color-lime" : 1,400"wysiwyg-color-olive" : 1,401"wysiwyg-color-yellow" : 1,402"wysiwyg-color-navy" : 1,403"wysiwyg-color-blue" : 1,404"wysiwyg-color-teal" : 1,405"wysiwyg-color-aqua" : 1,406"wysiwyg-color-orange" : 1407},408tags: {409"b": {},410"i": {},411"br": {},412"ol": {},413"ul": {},414"li": {},415"h1": {},416"h2": {},417"h3": {},418"blockquote": {},419"u": 1,420"img": {421"check_attributes": {422"width": "numbers",423"alt": "alt",424"src": "url",425"height": "numbers"426}427},428"a": {429set_attributes: {430target: "_blank",431rel: "nofollow"432},433check_attributes: {434href: "url" // important to avoid XSS435}436},437"span": 1,438"div": 1,439// to allow save and edit files with code tag hacks440"code": 1,441"pre": 1442}443},444stylesheets: ["./lib/css/wysiwyg-color.css"], // (path_to_project/lib/css/wysiwyg-color.css)445locale: "en"446};447448if (typeof $.fn.wysihtml5.defaultOptionsCache === 'undefined') {449$.fn.wysihtml5.defaultOptionsCache = $.extend(true, {}, $.fn.wysihtml5.defaultOptions);450}451452var locale = $.fn.wysihtml5.locale = {453en: {454font_styles: {455normal: "Normal text",456h1: "Heading 1",457h2: "Heading 2",458h3: "Heading 3"459},460emphasis: {461bold: "Bold",462italic: "Italic",463underline: "Underline"464},465lists: {466unordered: "Unordered list",467ordered: "Ordered list",468outdent: "Outdent",469indent: "Indent"470},471link: {472insert: "Insert link",473cancel: "Cancel"474},475image: {476insert: "Insert image",477cancel: "Cancel"478},479html: {480edit: "Edit HTML"481},482colours: {483black: "Black",484silver: "Silver",485gray: "Grey",486maroon: "Maroon",487red: "Red",488purple: "Purple",489green: "Green",490olive: "Olive",491navy: "Navy",492blue: "Blue",493orange: "Orange"494}495}496};497498}(window.jQuery, window.wysihtml5);499500501