// Generated by CoffeeScript 1.10.0 /* Hallo {{ VERSION }} - a rich text editing jQuery UI widget (c) 2011 Henri Bergius, IKS Consortium Hallo may be freely distributed under the MIT license http://hallojs.org */ (function() { (function(jQuery) { return jQuery.widget('IKS.hallo', { toolbar: null, bound: false, originalContent: '', previousContent: '', uuid: '', selection: null, _keepActivated: false, originalHref: null, options: { editable: true, plugins: {}, toolbar: 'halloToolbarContextual', parentElement: 'body', buttonCssClass: null, toolbarCssClass: null, toolbarPositionAbove: false, toolbarOptions: {}, placeholder: '', forceStructured: true, checkTouch: true, touchScreen: null }, _create: function() { var options, plugin, ref; this.id = this._generateUUID(); if (this.options.checkTouch && this.options.touchScreen === null) { this.checkTouch(); } ref = this.options.plugins; for (plugin in ref) { options = ref[plugin]; if (!jQuery.isPlainObject(options)) { options = {}; } jQuery.extend(options, { editable: this, uuid: this.id, buttonCssClass: this.options.buttonCssClass }); jQuery(this.element)[plugin](options); } this.element.one('halloactivated', (function(_this) { return function() { return _this._prepareToolbar(); }; })(this)); return this.originalContent = this.getContents(); }, _init: function() { if (this.options.editable) { return this.enable(); } else { return this.disable(); } }, destroy: function() { var options, plugin, ref; this.disable(); if (this.toolbar) { this.toolbar.remove(); this.element[this.options.toolbar]('destroy'); } ref = this.options.plugins; for (plugin in ref) { options = ref[plugin]; jQuery(this.element)[plugin]('destroy'); } return jQuery.Widget.prototype.destroy.call(this); }, disable: function() { this.element.attr("contentEditable", false); this.element.off("focus", this._activated); this.element.off("blur", this._deactivated); this.element.off("keyup paste change", this._checkModified); this.element.off("keyup", this._keys); this.element.off("keyup mouseup", this._checkSelection); this.bound = false; jQuery(this.element).removeClass('isModified'); jQuery(this.element).removeClass('inEditMode'); this.element.parents('a').addBack().each((function(_this) { return function(idx, elem) { var element; element = jQuery(elem); if (!element.is('a')) { return; } if (!_this.originalHref) { return; } return element.attr('href', _this.originalHref); }; })(this)); return this._trigger("disabled", null); }, enable: function() { this.element.parents('a[href]').addBack().each((function(_this) { return function(idx, elem) { var element; element = jQuery(elem); if (!element.is('a[href]')) { return; } _this.originalHref = element.attr('href'); return element.removeAttr('href'); }; })(this)); this.element.attr("contentEditable", true); if (!jQuery.parseHTML(this.element.html())) { this.element.html(this.options.placeholder); jQuery(this.element).addClass('inPlaceholderMode'); this.element.css({ 'min-width': this.element.innerWidth(), 'min-height': this.element.innerHeight() }); } if (!this.bound) { this.element.on("focus", this, this._activated); this.element.on("blur", this, this._deactivated); this.element.on("keyup paste change", this, this._checkModified); this.element.on("keyup", this, this._keys); this.element.on("keyup mouseup", this, this._checkSelection); this.bound = true; } if (this.options.forceStructured) { this._forceStructured(); } return this._trigger("enabled", null); }, activate: function() { return this.element.focus(); }, containsSelection: function() { var range; range = this.getSelection(); return this.element.has(range.startContainer).length > 0; }, getSelection: function() { var range, sel; sel = rangy.getSelection(); range = null; if (sel.rangeCount > 0) { range = sel.getRangeAt(0); } else { range = rangy.createRange(); } return range; }, restoreSelection: function(range) { var sel; sel = rangy.getSelection(); return sel.setSingleRange(range); }, replaceSelection: function(cb) { var newTextNode, r, range, sel, t; if (navigator.appName === 'Microsoft Internet Explorer') { t = document.selection.createRange().text; r = document.selection.createRange(); return r.pasteHTML(cb(t)); } else { sel = window.getSelection(); range = sel.getRangeAt(0); newTextNode = document.createTextNode(cb(range.extractContents())); range.insertNode(newTextNode); range.setStartAfter(newTextNode); sel.removeAllRanges(); return sel.addRange(range); } }, removeAllSelections: function() { if (navigator.appName === 'Microsoft Internet Explorer') { return range.empty(); } else { return window.getSelection().removeAllRanges(); } }, getPluginInstance: function(plugin) { var instance; instance = jQuery(this.element).data("IKS-" + plugin); if (instance) { return instance; } instance = jQuery(this.element).data(plugin); if (instance) { return instance; } throw new Error("Plugin " + plugin + " not found"); }, getContents: function() { var cleanup, instance, plugin; for (plugin in this.options.plugins) { instance = this.getPluginInstance(plugin); if (!instance) { continue; } cleanup = instance.cleanupContentClone; if (!jQuery.isFunction(cleanup)) { continue; } jQuery(this.element)[plugin]('cleanupContentClone', this.element); } return this.element.html(); }, setContents: function(contents) { return this.element.html(contents); }, isModified: function() { if (!this.previousContent) { this.previousContent = this.originalContent; } return this.previousContent !== this.getContents(); }, setUnmodified: function() { jQuery(this.element).removeClass('isModified'); return this.previousContent = this.getContents(); }, setModified: function() { jQuery(this.element).addClass('isModified'); return this._trigger('modified', null, { editable: this, content: this.getContents() }); }, restoreOriginalContent: function() { return this.element.html(this.originalContent); }, execute: function(command, value) { if (document.execCommand(command, false, value)) { return this.element.trigger("change"); } }, protectFocusFrom: function(el) { return el.on("mousedown", (function(_this) { return function(event) { event.preventDefault(); _this._protectToolbarFocus = true; return setTimeout(function() { return _this._protectToolbarFocus = false; }, 300); }; })(this)); }, keepActivated: function(_keepActivated) { this._keepActivated = _keepActivated; }, _generateUUID: function() { var S4; S4 = function() { return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1); }; return "" + (S4()) + (S4()) + "-" + (S4()) + "-" + (S4()) + "-" + (S4()) + "-" + (S4()) + (S4()) + (S4()); }, _prepareToolbar: function() { var defaults, instance, plugin, populate, toolbarOptions; this.toolbar = jQuery('
').hide(); if (this.options.toolbarCssClass) { this.toolbar.addClass(this.options.toolbarCssClass); } defaults = { editable: this, parentElement: this.options.parentElement, toolbar: this.toolbar, positionAbove: this.options.toolbarPositionAbove }; toolbarOptions = jQuery.extend({}, defaults, this.options.toolbarOptions); this.element[this.options.toolbar](toolbarOptions); for (plugin in this.options.plugins) { instance = this.getPluginInstance(plugin); if (!instance) { continue; } populate = instance.populateToolbar; if (!jQuery.isFunction(populate)) { continue; } this.element[plugin]('populateToolbar', this.toolbar); } this.element[this.options.toolbar]('setPosition'); return this.protectFocusFrom(this.toolbar); }, changeToolbar: function(element, toolbar, hide) { var originalToolbar; if (hide == null) { hide = false; } originalToolbar = this.options.toolbar; this.options.parentElement = element; if (toolbar) { this.options.toolbar = toolbar; } if (!this.toolbar) { return; } this.element[originalToolbar]('destroy'); this.toolbar.remove(); this._prepareToolbar(); if (hide) { return this.toolbar.hide(); } }, _checkModified: function(event) { var widget; widget = event.data; if (widget.isModified()) { return widget.setModified(); } }, _keys: function(event) { var old, widget; widget = event.data; if (event.keyCode === 27) { old = widget.getContents(); widget.restoreOriginalContent(event); widget._trigger("restored", null, { editable: widget, content: widget.getContents(), thrown: old }); return widget.turnOff(); } }, _rangesEqual: function(r1, r2) { if (r1.startContainer !== r2.startContainer) { return false; } if (r1.startOffset !== r2.startOffset) { return false; } if (r1.endContainer !== r2.endContainer) { return false; } if (r1.endOffset !== r2.endOffset) { return false; } return true; }, _checkSelection: function(event) { var widget; if (event.keyCode === 27) { return; } widget = event.data; return setTimeout(function() { var sel; sel = widget.getSelection(); if (widget._isEmptySelection(sel) || widget._isEmptyRange(sel)) { if (widget.selection) { widget.selection = null; widget._trigger("unselected", null, { editable: widget, originalEvent: event }); } return; } if (!widget.selection || !widget._rangesEqual(sel, widget.selection)) { widget.selection = sel.cloneRange(); return widget._trigger("selected", null, { editable: widget, selection: widget.selection, ranges: [widget.selection], originalEvent: event }); } }, 0); }, _isEmptySelection: function(selection) { if (selection.type === "Caret") { return true; } return false; }, _isEmptyRange: function(range) { if (range.collapsed) { return true; } if (range.isCollapsed) { if (typeof range.isCollapsed === 'function') { return range.isCollapsed(); } return range.isCollapsed; } return false; }, turnOn: function() { if (this.getContents() === this.options.placeholder) { this.setContents(''); } jQuery(this.element).removeClass('inPlaceholderMode'); jQuery(this.element).addClass('inEditMode'); return this._trigger("activated", null, this); }, turnOff: function() { jQuery(this.element).removeClass('inEditMode'); this._trigger("deactivated", null, this); if (!this.getContents()) { jQuery(this.element).addClass('inPlaceholderMode'); return this.setContents(this.options.placeholder); } }, _activated: function(event) { return event.data.turnOn(); }, _deactivated: function(event) { if (event.data._keepActivated) { return; } if (event.data._protectToolbarFocus !== true) { return event.data.turnOff(); } else { return setTimeout(function() { return jQuery(event.data.element).focus(); }, 300); } }, _forceStructured: function(event) { var e, error1, error2, error3; try { return document.execCommand('styleWithCSS', 0, false); } catch (error1) { e = error1; try { return document.execCommand('useCSS', 0, true); } catch (error2) { e = error2; try { return document.execCommand('styleWithCSS', false, false); } catch (error3) { e = error3; } } } }, checkTouch: function() { return this.options.touchScreen = !!('createTouch' in document); } }); })(jQuery); (function(jQuery) { var z; z = null; if (this.VIE !== void 0) { z = new VIE; z.use(new z.StanbolService({ proxyDisabled: true, url: 'http://dev.iks-project.eu:8081' })); } return jQuery.widget('IKS.halloannotate', { options: { vie: z, editable: null, toolbar: null, uuid: '', select: function() {}, decline: function() {}, remove: function() {}, buttonCssClass: null }, _create: function() { var editableElement, turnOffAnnotate, widget; widget = this; if (this.options.vie === void 0) { throw new Error('The halloannotate plugin requires VIE'); return; } if (typeof this.element.annotate !== 'function') { throw new Error('The halloannotate plugin requires annotate.js'); return; } this.state = 'off'; this.instantiate(); turnOffAnnotate = function() { var editable; editable = this; return jQuery(editable).halloannotate('turnOff'); }; editableElement = this.options.editable.element; return editableElement.on('hallodisabled', turnOffAnnotate); }, populateToolbar: function(toolbar) { var buttonHolder; buttonHolder = jQuery(""); this.button = buttonHolder.hallobutton({ label: 'Annotate', icon: 'fa-tags', editable: this.options.editable, command: null, uuid: this.options.uuid, cssClass: this.options.buttonCssClass, queryState: false }); buttonHolder.on('change', (function(_this) { return function(event) { if (_this.state === "pending") { return; } if (_this.state === "off") { return _this.turnOn(); } return _this.turnOff(); }; })(this)); buttonHolder.buttonset(); return toolbar.append(this.button); }, cleanupContentClone: function(el) { if (this.state === 'on') { return el.find(".entity:not([about])").each(function() { return jQuery(this).replaceWith(jQuery(this).html()); }); } }, instantiate: function() { var widget; widget = this; return this.options.editable.element.annotate({ vie: this.options.vie, debug: false, showTooltip: true, select: this.options.select, remove: this.options.remove, success: this.options.success, error: this.options.error }).on('annotateselect', function(event, data) { return widget.options.editable.setModified(); }).on('annotateremove', function() { return jQuery.noop(); }); }, turnPending: function() { this.state = 'pending'; this.button.hallobutton('checked', false); return this.button.hallobutton('disable'); }, turnOn: function() { var e, error1, widget; this.turnPending(); widget = this; try { return this.options.editable.element.annotate('enable', (function(_this) { return function(success) { if (!success) { return; } _this.state = 'on'; _this.button.hallobutton('checked', true); return _this.button.hallobutton('enable'); }; })(this)); } catch (error1) { e = error1; return alert(e); } }, turnOff: function() { this.options.editable.element.annotate('disable'); this.state = 'off'; if (!this.button) { return; } this.button.attr('checked', false); this.button.find("label").removeClass("ui-state-clicked"); return this.button.button('refresh'); } }); })(jQuery); (function(jQuery) { return jQuery.widget('IKS.halloblacklist', { options: { tags: [] }, _init: function() { if (this.options.tags.indexOf('br') !== -1) { return this.element.on('keydown', function(event) { if (event.originalEvent.keyCode === 13) { return event.preventDefault(); } }); } }, cleanupContentClone: function(el) { var i, len, ref, results1, tag; ref = this.options.tags; results1 = []; for (i = 0, len = ref.length; i < len; i++) { tag = ref[i]; results1.push(jQuery(tag, el).remove()); } return results1; } }); })(jQuery); (function(jQuery) { return jQuery.widget('IKS.halloblock', { options: { editable: null, toolbar: null, uuid: '', elements: ['h1', 'h2', 'h3', 'p', 'pre', 'blockquote'], buttonCssClass: null }, populateToolbar: function(toolbar) { var buttonset, contentId, target; buttonset = jQuery(""); contentId = this.options.uuid + "-" + this.widgetName + "-data"; target = this._prepareDropdown(contentId); toolbar.append(buttonset); buttonset.hallobuttonset(); buttonset.append(target); return buttonset.append(this._prepareButton(target)); }, _prepareDropdown: function(contentId) { var addElement, containingElement, contentArea, element, i, len, ref; contentArea = jQuery("
"); containingElement = this.options.editable.element.get(0).tagName.toLowerCase(); addElement = (function(_this) { return function(element) { var el, events, queryState; el = jQuery(""); if (containingElement === element) { el.addClass('selected'); } if (containingElement !== 'div') { el.addClass('disabled'); } el.on('click', function() { var tagName; tagName = element.toUpperCase(); if (el.hasClass('disabled')) { return; } if (navigator.appName === 'Microsoft Internet Explorer') { _this.options.editable.execute('FormatBlock', "<" + tagName + ">"); return; } return _this.options.editable.execute('formatBlock', tagName); }); queryState = function(event) { var block; block = document.queryCommandValue('formatBlock'); if (block.toLowerCase() === element) { el.addClass('selected'); return; } return el.removeClass('selected'); }; events = 'keyup paste change mouseup'; _this.options.editable.element.on(events, queryState); _this.options.editable.element.on('halloenabled', function() { return _this.options.editable.element.on(events, queryState); }); _this.options.editable.element.on('hallodisabled', function() { return _this.options.editable.element.off(events, queryState); }); return el; }; })(this); ref = this.options.elements; for (i = 0, len = ref.length; i < len; i++) { element = ref[i]; contentArea.append(addElement(element)); } return contentArea; }, _prepareButton: function(target) { var buttonElement; buttonElement = jQuery(''); buttonElement.hallodropdownbutton({ uuid: this.options.uuid, editable: this.options.editable, label: 'block', icon: 'fa-text-height', target: target, cssClass: this.options.buttonCssClass }); return buttonElement; } }); })(jQuery); (function(jQuery) { var rangyMessage; rangyMessage = 'The hallocleanhtml plugin requires the selection save and restore module from Rangy'; return jQuery.widget('IKS.hallocleanhtml', { _create: function() { var editor; if (jQuery.htmlClean === void 0) { throw new Error('The hallocleanhtml plugin requires jQuery.htmlClean'); return; } editor = this.element; return editor.bind('paste', this, (function(_this) { return function(event) { var lastContent, lastRange, widget; if (rangy.saveSelection === void 0) { throw new Error(rangyMessage); return; } widget = event.data; widget.options.editable.getSelection().deleteContents(); lastRange = rangy.saveSelection(); lastContent = editor.html(); editor.html(''); return setTimeout(function() { var cleanPasted, error, error1, pasted, range; pasted = editor.html(); cleanPasted = jQuery.htmlClean(pasted, _this.options); editor.html(lastContent); rangy.restoreSelection(lastRange); if (cleanPasted !== '') { try { return document.execCommand('insertHTML', false, cleanPasted); } catch (error1) { error = error1; range = widget.options.editable.getSelection(); return range.insertNode(range.createContextualFragment(cleanPasted)); } } }, 4); }; })(this)); } }); })(jQuery); (function(jQuery) { return jQuery.widget("IKS.halloformat", { options: { editable: null, uuid: '', formattings: { bold: true, italic: true, strikeThrough: false, underline: false }, buttonCssClass: null }, populateToolbar: function(toolbar) { var buttonize, buttonset, enabled, format, ref, widget; widget = this; buttonset = jQuery(""); buttonize = (function(_this) { return function(format) { var buttonHolder; buttonHolder = jQuery(''); buttonHolder.hallobutton({ label: format, editable: _this.options.editable, command: format, uuid: _this.options.uuid, cssClass: _this.options.buttonCssClass }); return buttonset.append(buttonHolder); }; })(this); ref = this.options.formattings; for (format in ref) { enabled = ref[format]; if (!enabled) { continue; } buttonize(format); } buttonset.hallobuttonset(); return toolbar.append(buttonset); } }); })(jQuery); (function(jQuery) { return jQuery.widget("IKS.halloheadings", { options: { editable: null, uuid: '', formatBlocks: ["p", "h1", "h2", "h3"], buttonCssClass: null }, populateToolbar: function(toolbar) { var buttonize, buttonset, command, format, i, ie, len, ref, widget; widget = this; buttonset = jQuery(""); ie = navigator.appName === 'Microsoft Internet Explorer'; command = (ie ? "FormatBlock" : "formatBlock"); buttonize = (function(_this) { return function(format) { var buttonHolder; buttonHolder = jQuery(''); buttonHolder.hallobutton({ label: format, editable: _this.options.editable, command: command, commandValue: (ie ? "<" + format + ">" : format), uuid: _this.options.uuid, cssClass: _this.options.buttonCssClass, queryState: function(event) { var compared, e, error1, i, len, map, ref, result, val, value; try { value = document.queryCommandValue(command); if (ie) { map = { p: "normal" }; ref = [1, 2, 3, 4, 5, 6]; for (i = 0, len = ref.length; i < len; i++) { val = ref[i]; map["h" + val] = val; } compared = value.match(new RegExp(map[format], "i")); } else { compared = value.match(new RegExp(format, "i")); } result = compared ? true : false; return buttonHolder.hallobutton('checked', result); } catch (error1) { e = error1; } } }); buttonHolder.find('button .ui-button-text').text(format.toUpperCase()); return buttonset.append(buttonHolder); }; })(this); ref = this.options.formatBlocks; for (i = 0, len = ref.length; i < len; i++) { format = ref[i]; buttonize(format); } buttonset.hallobuttonset(); return toolbar.append(buttonset); } }); })(jQuery); (function(jQuery) { return jQuery.widget("IKS.hallohtml", { options: { editable: null, toolbar: null, uuid: "", lang: 'en', dialogOpts: { autoOpen: false, width: 600, height: 'auto', modal: false, resizable: true, draggable: true, dialogClass: 'htmledit-dialog' }, dialog: null, buttonCssClass: null }, translations: { en: { title: 'Edit HTML', update: 'Update' }, de: { title: 'HTML bearbeiten', update: 'Aktualisieren' } }, texts: null, populateToolbar: function($toolbar) { var $buttonHolder, $buttonset, id, selector, widget; widget = this; this.texts = this.translations[this.options.lang]; this.options.toolbar = $toolbar; selector = this.options.uuid + "-htmledit-dialog"; this.options.dialog = jQuery("
").attr('id', selector); $buttonset = jQuery("").addClass(widget.widgetName); id = this.options.uuid + "-htmledit"; $buttonHolder = jQuery(''); $buttonHolder.hallobutton({ label: this.texts.title, icon: 'fa-list-alt', editable: this.options.editable, command: null, queryState: false, uuid: this.options.uuid, cssClass: this.options.buttonCssClass }); $buttonset.append($buttonHolder); this.button = $buttonHolder; this.button.click(function() { if (widget.options.dialog.dialog("isOpen")) { widget._closeDialog(); } else { widget._openDialog(); } return false; }); this.options.editable.element.on("hallodeactivated", function() { return widget._closeDialog(); }); $toolbar.append($buttonset); this.options.dialog.dialog(this.options.dialogOpts); return this.options.dialog.dialog("option", "title", this.texts.title); }, _openDialog: function() { var $editableEl, html, widget, xposition, yposition; widget = this; $editableEl = jQuery(this.options.editable.element); xposition = $editableEl.offset().left + $editableEl.outerWidth() + 10; yposition = this.options.toolbar.offset().top - jQuery(document).scrollTop(); this.options.dialog.dialog("option", "position", [xposition, yposition]); this.options.editable.keepActivated(true); this.options.dialog.dialog("open"); this.options.dialog.on('dialogclose', (function(_this) { return function() { jQuery('label', _this.button).removeClass('ui-state-active'); _this.options.editable.element.focus(); return _this.options.editable.keepActivated(false); }; })(this)); this.options.dialog.html(jQuery("