diff --git a/src/plugins/oer/copy/lib/copy-plugin.coffee b/src/plugins/oer/copy/lib/copy-plugin.coffee index 8f65faeb0b..a06e818ced 100644 --- a/src/plugins/oer/copy/lib/copy-plugin.coffee +++ b/src/plugins/oer/copy/lib/copy-plugin.coffee @@ -2,6 +2,23 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa buffer = '' srcpath = null + content_type = null + + getSection = ($el) -> + headings = ['h1', 'h2', 'h3'] + level = headings.indexOf $el[0].nodeName.toLowerCase() + # Pick up all elements until the next heading of the same level or higher + selector = headings.slice(0, level+1).join(',') + + if $el.addBack + # Jquery >= 1.8 + $el = $el.nextUntil(selector).addBack() + else + # Jquery < 1.8 + $el = $el.nextUntil(selector).andSelf() + html = '' + html += jQuery(e).outerHtml() for e in $el + return html Plugin.create 'copy', getCurrentPath: -> @@ -26,13 +43,21 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa else return srcpath - buffer: (content, path) -> + getContentType: -> + if localStorage + return localStorage.alohaOerCopyContentType + else + return content_type + + buffer: (content, type, path) -> buffer = content buffer = buffer.replace /id="[^"]+"/, '' - srcpath = path + content_type = type or 'text/html' + srcpath = path or @getCurrentPath() localStorage.alohaOerCopyBuffer = buffer if localStorage localStorage.alohaOerCopySrcPath = srcpath if localStorage + localStorage.alohaOerCopyContentType = content_type if localStorage # Disable copy button, it will re-enable when you move the cursor. This # gives visual feedback and prevents you from copying the same thing @@ -42,25 +67,16 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa @pastebutton.flash?() copySection: ($el) -> - headings = ['h1', 'h2', 'h3'] - level = headings.indexOf $el[0].nodeName.toLowerCase() - # Pick up all elements until the next heading of the same level or higher - selector = headings.slice(0, level+1).join(',') - - if $el.addBack - # Jquery >= 1.8 - $el = $el.nextUntil(selector).addBack() - else - # Jquery < 1.8 - $el = $el.nextUntil(selector).andSelf() - html = '' - html += jQuery(e).outerHtml() for e in $el - - path = @getCurrentPath() - if path != null - @buffer html, path - else - @buffer html + content = getSection($el) + + # Fire a copy event, allow something more suitable to handle this. + evt = $.Event('copy') + evt.oerContent = content + evt.clipboardData = + setData: (t, c) => @buffer c, t + Aloha.activeEditable.obj.trigger(evt) + if not evt.isDefaultPrevented() + @buffer content init: -> plugin = @ @@ -89,7 +105,19 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa tooltip: 'Paste', click: (e) -> e.preventDefault() - range = Aloha.Selection.getRangeObject() + + # Fire a paste event, allow something else to handle this, if that + # something deems itself more suitable. + evt = $.Event('paste') + evt.clipboardData = + getData: (t) -> + if t == plugin.getContentType() + return plugin.getBuffer() + return null + Aloha.activeEditable.obj.trigger(evt) + return if evt.isDefaultPrevented() + + # Default paste behaviour follows $elements = jQuery plugin.getBuffer() dstpath = plugin.getCurrentPath() @@ -111,6 +139,7 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa else console.log "Image path already absolute: #{imgpath}" + range = Aloha.Selection.getRangeObject() GENTICS.Utils.Dom.insertIntoDOM $elements, range, Aloha.activeEditable.obj @copybutton = UI.adopt "copy", Button, diff --git a/src/plugins/oer/copy/lib/copy-plugin.js b/src/plugins/oer/copy/lib/copy-plugin.js index dbac070859..9b44348c27 100644 --- a/src/plugins/oer/copy/lib/copy-plugin.js +++ b/src/plugins/oer/copy/lib/copy-plugin.js @@ -1,10 +1,27 @@ -// Generated by CoffeeScript 1.5.0 +// Generated by CoffeeScript 1.6.3 (function() { - define(['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './path', 'css!copy/css/copy.css'], function(Aloha, Plugin, jQuery, UI, Button, PubSub, Path) { - var buffer, srcpath; + var buffer, content_type, getSection, srcpath; buffer = ''; srcpath = null; + content_type = null; + getSection = function($el) { + var e, headings, html, level, selector, _i, _len; + headings = ['h1', 'h2', 'h3']; + level = headings.indexOf($el[0].nodeName.toLowerCase()); + selector = headings.slice(0, level + 1).join(','); + if ($el.addBack) { + $el = $el.nextUntil(selector).addBack(); + } else { + $el = $el.nextUntil(selector).andSelf(); + } + html = ''; + for (_i = 0, _len = $el.length; _i < _len; _i++) { + e = $el[_i]; + html += jQuery(e).outerHtml(); + } + return html; + }; return Plugin.create('copy', { getCurrentPath: function() { if (this.settings.path) { @@ -26,41 +43,46 @@ return srcpath; } }, - buffer: function(content, path) { + getContentType: function() { + if (localStorage) { + return localStorage.alohaOerCopyContentType; + } else { + return content_type; + } + }, + buffer: function(content, type, path) { var _base; buffer = content; buffer = buffer.replace(/id="[^"]+"/, ''); - srcpath = path; + content_type = type || 'text/html'; + srcpath = path || this.getCurrentPath(); if (localStorage) { localStorage.alohaOerCopyBuffer = buffer; } if (localStorage) { localStorage.alohaOerCopySrcPath = srcpath; } + if (localStorage) { + localStorage.alohaOerCopyContentType = content_type; + } this.copybutton.disable(); this.pastebutton.enable(); return typeof (_base = this.pastebutton).flash === "function" ? _base.flash() : void 0; }, copySection: function($el) { - var e, headings, html, level, path, selector, _i, _len; - headings = ['h1', 'h2', 'h3']; - level = headings.indexOf($el[0].nodeName.toLowerCase()); - selector = headings.slice(0, level + 1).join(','); - if ($el.addBack) { - $el = $el.nextUntil(selector).addBack(); - } else { - $el = $el.nextUntil(selector).andSelf(); - } - html = ''; - for (_i = 0, _len = $el.length; _i < _len; _i++) { - e = $el[_i]; - html += jQuery(e).outerHtml(); - } - path = this.getCurrentPath(); - if (path !== null) { - return this.buffer(html, path); - } else { - return this.buffer(html); + var content, evt, + _this = this; + content = getSection($el); + evt = $.Event('copy'); + evt.oerContent = content; + evt.clipboardData = { + setData: function(t, c) { + return _this.buffer(c, t); + } + }; + Aloha.activeEditable.obj.trigger(evt); + if (!evt.isDefaultPrevented()) { + return this.buffer(content); } }, init: function() { @@ -86,9 +108,21 @@ this.pastebutton = UI.adopt('paste', Button, { tooltip: 'Paste', click: function(e) { - var $elements, dstpath, range; + var $elements, dstpath, evt, range; e.preventDefault(); - range = Aloha.Selection.getRangeObject(); + evt = $.Event('paste'); + evt.clipboardData = { + getData: function(t) { + if (t === plugin.getContentType()) { + return plugin.getBuffer(); + } + return null; + } + }; + Aloha.activeEditable.obj.trigger(evt); + if (evt.isDefaultPrevented()) { + return; + } $elements = jQuery(plugin.getBuffer()); dstpath = plugin.getCurrentPath(); if (dstpath !== null) { @@ -112,6 +146,7 @@ }); } } + range = Aloha.Selection.getRangeObject(); return GENTICS.Utils.Dom.insertIntoDOM($elements, range, Aloha.activeEditable.obj); } }); diff --git a/src/plugins/oer/math/css/math.css b/src/plugins/oer/math/css/math.css index c6be96dc91..19ccd64258 100644 --- a/src/plugins/oer/math/css/math.css +++ b/src/plugins/oer/math/css/math.css @@ -102,6 +102,6 @@ math, background-image: url(../img/remove-02.png); } -button.done { +button.done, button.copy { float: right; } diff --git a/src/plugins/oer/math/lib/math-plugin.coffee b/src/plugins/oer/math/lib/math-plugin.coffee index 3abb693ed8..606bb7dedc 100644 --- a/src/plugins/oer/math/lib/math-plugin.coffee +++ b/src/plugins/oer/math/lib/math-plugin.coffee @@ -37,7 +37,7 @@ # -define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', 'css!../../../oer/math/css/math.css' ], (Aloha, Plugin, jQuery, Popover, UI) -> +define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', 'copy/copy-plugin', 'css!../../../oer/math/css/math.css' ], (Aloha, Plugin, jQuery, Popover, UI, Copy) -> EDITOR_HTML = '''
\n \n
\n \n