From acd71633c1aa1ca1ed64052be8e3275a32d1b0ab Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Fri, 11 Oct 2013 16:40:31 +0200 Subject: [PATCH 01/16] Special copy/paste handler for math. If there is math in the content we're copying, use a different custom content-type. When pasting, if the incoming data is our custom content, insert it directly and avoid the browser sanitising it. --- src/plugins/oer/math/lib/math-plugin.coffee | 25 +++++++++++++++++++++ src/plugins/oer/math/lib/math-plugin.js | 17 ++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/plugins/oer/math/lib/math-plugin.coffee b/src/plugins/oer/math/lib/math-plugin.coffee index 77b1a4c794..ddb7912529 100644 --- a/src/plugins/oer/math/lib/math-plugin.coffee +++ b/src/plugins/oer/math/lib/math-plugin.coffee @@ -138,6 +138,31 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' if editable.obj.is(':not(.aloha-root-editable)') return + # Bind copy and paste handlers. When a user copies content with math, place + # it on the clipboard with a different content type. This will prevent the + # cleanup that the browser does on namespaces. Use this alternative content + # type again when pasting. Prevent the browser default. This will only work + # in browsers that support event.clipboardData, chrome and safari to date. + editable.obj.on 'copy', (e) -> + content = Aloha.getSelection().getRangeAt(0).cloneContents() + $content = $('
').append(content) + # If there is math among the content we're copying, treat it specially. + # Check that we also have a script tag in our selection, that occurs + # towards the end of the math and ensures we have the whole of it. + # The idea is to only do custom copy/paste if we need it, and let the + # browser handle other content. + if $content.has('span.math-element').length and $content.has('script').length + e.preventDefault() + e.originalEvent.clipboardData.setData 'text/oerpub-content', $content.html() + + editable.obj.on 'paste', (e) -> + content = e.originalEvent.clipboardData.getData('text/oerpub-content') + if content + e.preventDefault() + # Using insertHTML here allows pasted content to be cleaned up by the + # contenthandler plugin. + Aloha.execCommand('insertHTML', false, content) + # Bind ctrl+m to math insert/mathify editable.obj.bind 'keydown', 'ctrl+m', (evt) -> insertMath() diff --git a/src/plugins/oer/math/lib/math-plugin.js b/src/plugins/oer/math/lib/math-plugin.js index 792b8b6648..d3d6089061 100644 --- a/src/plugins/oer/math/lib/math-plugin.js +++ b/src/plugins/oer/math/lib/math-plugin.js @@ -77,6 +77,23 @@ if (editable.obj.is(':not(.aloha-root-editable)')) { return; } + editable.obj.on('copy', function(e) { + var $content, content; + content = Aloha.getSelection().getRangeAt(0).cloneContents(); + $content = $('
').append(content); + if ($content.has('span.math-element').length && $content.has('script').length) { + e.preventDefault(); + return e.originalEvent.clipboardData.setData('text/oerpub-content', $content.html()); + } + }); + editable.obj.on('paste', function(e) { + var content; + content = e.originalEvent.clipboardData.getData('text/oerpub-content'); + if (content) { + e.preventDefault(); + return Aloha.execCommand('insertHTML', false, content); + } + }); editable.obj.bind('keydown', 'ctrl+m', function(evt) { insertMath(); return evt.preventDefault(); From 3b7b27db7edba05f9093056aa9f7012ed7a62c8e Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Mon, 14 Oct 2013 14:23:59 +0200 Subject: [PATCH 02/16] Add a copy command to mathjax context menu. This hooks into the Copy plugin, allowing math to be copied on its own. --- src/plugins/oer/math/lib/math-plugin.coffee | 9 ++++++++- src/plugins/oer/math/lib/math-plugin.js | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/oer/math/lib/math-plugin.coffee b/src/plugins/oer/math/lib/math-plugin.coffee index ddb7912529..dd908ee0ba 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 = '''
@@ -484,6 +484,13 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' UI.adopt 'insertMath', null, click: () -> insertMath() + # Add a copy option to the mathjax menu + MathJax.Callback.Queue MathJax.Hub.Register.StartupHook "MathMenu Ready", () -> + copyCommand = MathJax.Menu.ITEM.COMMAND "Copy Math", (e,f,g) -> + $script = jQuery(document.getElementById(MathJax.Menu.jax.inputID)) + Copy.buffer $script.parent().parent().outerHtml() + MathJax.Menu.menu.items.unshift copyCommand + ob = selector: '.math-element' populator: buildEditor diff --git a/src/plugins/oer/math/lib/math-plugin.js b/src/plugins/oer/math/lib/math-plugin.js index d3d6089061..45e0c06ede 100644 --- a/src/plugins/oer/math/lib/math-plugin.js +++ b/src/plugins/oer/math/lib/math-plugin.js @@ -2,7 +2,7 @@ (function() { var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - define(['aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', 'css!../../../oer/math/css/math.css'], function(Aloha, Plugin, jQuery, Popover, UI) { + define(['aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', 'copy/copy-plugin', 'css!../../../oer/math/css/math.css'], function(Aloha, Plugin, jQuery, Popover, UI, Copy) { var $_editor, EDITOR_HTML, LANGUAGES, MATHML_ANNOTATION_MIME_ENCODINGS, MATHML_ANNOTATION_NONMIME_ENCODINGS, TOOLTIP_TEMPLATE, addAnnotation, buildEditor, cleanupFormula, findFormula, getEncoding, getMathFor, insertMath, insertMathInto, makeCloseIcon, ob, placeCursorAfter, squirrelMath, triggerMathJax; EDITOR_HTML = '
\n
\n

\n \n
\n \n
'; $_editor = jQuery(EDITOR_HTML); @@ -401,6 +401,15 @@ return insertMath(); } }); + MathJax.Callback.Queue(MathJax.Hub.Register.StartupHook("MathMenu Ready", function() { + var copyCommand; + copyCommand = MathJax.Menu.ITEM.COMMAND("Copy Math", function(e, f, g) { + var $script; + $script = jQuery(document.getElementById(MathJax.Menu.jax.inputID)); + return Copy.buffer($script.parent().parent().outerHtml()); + }); + return MathJax.Menu.menu.items.unshift(copyCommand); + })); ob = { selector: '.math-element', populator: buildEditor, From 06a74d721a7de09a40f16188d5a13ff8948c61ab Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Mon, 14 Oct 2013 14:51:49 +0200 Subject: [PATCH 03/16] Integrate copy with internal copy buffer. This means that copying something to the system clipboard also duplicates it to our internal buffer. The math plugin might not be the best place to put this, but it certainly needs it the most. --- src/plugins/oer/math/lib/math-plugin.coffee | 3 +++ src/plugins/oer/math/lib/math-plugin.js | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/oer/math/lib/math-plugin.coffee b/src/plugins/oer/math/lib/math-plugin.coffee index dd908ee0ba..458639d2b0 100644 --- a/src/plugins/oer/math/lib/math-plugin.coffee +++ b/src/plugins/oer/math/lib/math-plugin.coffee @@ -155,6 +155,9 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' e.preventDefault() e.originalEvent.clipboardData.setData 'text/oerpub-content', $content.html() + # Also buffer it in our local copy buffer + Copy.buffer $content.html(), Copy.getCurrentPath() + editable.obj.on 'paste', (e) -> content = e.originalEvent.clipboardData.getData('text/oerpub-content') if content diff --git a/src/plugins/oer/math/lib/math-plugin.js b/src/plugins/oer/math/lib/math-plugin.js index 45e0c06ede..ce44695be2 100644 --- a/src/plugins/oer/math/lib/math-plugin.js +++ b/src/plugins/oer/math/lib/math-plugin.js @@ -83,8 +83,9 @@ $content = $('
').append(content); if ($content.has('span.math-element').length && $content.has('script').length) { e.preventDefault(); - return e.originalEvent.clipboardData.setData('text/oerpub-content', $content.html()); + e.originalEvent.clipboardData.setData('text/oerpub-content', $content.html()); } + return Copy.buffer($content.html(), Copy.getCurrentPath()); }); editable.obj.on('paste', function(e) { var content; From 6c3a6e563b635a3a62d939ceafe810efb6f314ed Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Tue, 15 Oct 2013 12:05:21 +0200 Subject: [PATCH 04/16] When pasting, retypeset math to get back context menu. Also, use range machinery to insert pasted content. This is necessary because InsertHtml breaks if any inserted content has no style property (math elements doesn't), and insertIntoDOM pastes the content AFTER the selected paragraph, when pasting content on a new line. This does the right thing by pasting it inside the paragraph, or any other place your cursor might be. --- src/plugins/oer/math/lib/math-plugin.coffee | 26 ++++++++++++++++++--- src/plugins/oer/math/lib/math-plugin.js | 23 ++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/plugins/oer/math/lib/math-plugin.coffee b/src/plugins/oer/math/lib/math-plugin.coffee index 458639d2b0..383c346f0c 100644 --- a/src/plugins/oer/math/lib/math-plugin.coffee +++ b/src/plugins/oer/math/lib/math-plugin.coffee @@ -162,9 +162,29 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' content = e.originalEvent.clipboardData.getData('text/oerpub-content') if content e.preventDefault() - # Using insertHTML here allows pasted content to be cleaned up by the - # contenthandler plugin. - Aloha.execCommand('insertHTML', false, content) + $content = jQuery( + '
') + .append(content).hide() + + # Remove ids, new ones will be assigned + $content.find('*[id]').removeAttr('id') + + # Paste content into editor + range = Aloha.getSelection().getRangeAt(0) + range.insertNode($content.get(0)) + + # Re-typeset math, because we need our context menu back + math = [] + $content.find('.math-element').each (idx, el) -> + deferred = $.Deferred() + math.push(deferred) + triggerMathJax jQuery(el), () -> deferred.resolve() + + # When we're done typesetting, show the content and unwrap it. + $.when.apply($content, math).done -> + $content.each () -> + $$$ = jQuery(@) + $$$.replaceWith $$$.contents() # Bind ctrl+m to math insert/mathify editable.obj.bind 'keydown', 'ctrl+m', (evt) -> diff --git a/src/plugins/oer/math/lib/math-plugin.js b/src/plugins/oer/math/lib/math-plugin.js index ce44695be2..27af0cdc65 100644 --- a/src/plugins/oer/math/lib/math-plugin.js +++ b/src/plugins/oer/math/lib/math-plugin.js @@ -88,11 +88,30 @@ return Copy.buffer($content.html(), Copy.getCurrentPath()); }); editable.obj.on('paste', function(e) { - var content; + var $content, content, math, range; content = e.originalEvent.clipboardData.getData('text/oerpub-content'); if (content) { e.preventDefault(); - return Aloha.execCommand('insertHTML', false, content); + $content = jQuery('
').append(content).hide(); + $content.find('*[id]').removeAttr('id'); + range = Aloha.getSelection().getRangeAt(0); + range.insertNode($content.get(0)); + math = []; + $content.find('.math-element').each(function(idx, el) { + var deferred; + deferred = $.Deferred(); + math.push(deferred); + return triggerMathJax(jQuery(el), function() { + return deferred.resolve(); + }); + }); + return $.when.apply($content, math).done(function() { + return $content.each(function() { + var $$$; + $$$ = jQuery(this); + return $$$.replaceWith($$$.contents()); + }); + }); } }); editable.obj.bind('keydown', 'ctrl+m', function(evt) { From 8d00b74a9f6a44f44e2a76004c3e47205a34e2a8 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Thu, 10 Oct 2013 13:44:58 +0200 Subject: [PATCH 05/16] Repair css so warning icon shows again. --- src/plugins/oer/assorted/css/image.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/oer/assorted/css/image.css b/src/plugins/oer/assorted/css/image.css index 2e11535459..7ee3fcdfdf 100644 --- a/src/plugins/oer/assorted/css/image.css +++ b/src/plugins/oer/assorted/css/image.css @@ -119,11 +119,13 @@ figure.aloha-oer-block .image-wrapper .image-edit.passive { } i.icon-warning { + display: inline-block; background-image: url(../img/warning-01.png); background-position: 0 0; margin-right: 4px; margin-left: 4px; width: 16px; + height: 16px; } .warning-text { From e8b414424197436da6fc8e7de246a6f9af17fc06 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Thu, 10 Oct 2013 14:57:30 +0200 Subject: [PATCH 06/16] Improve styling of warning icon --- src/plugins/oer/assorted/css/image.css | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/oer/assorted/css/image.css b/src/plugins/oer/assorted/css/image.css index 7ee3fcdfdf..84bde9a848 100644 --- a/src/plugins/oer/assorted/css/image.css +++ b/src/plugins/oer/assorted/css/image.css @@ -60,9 +60,10 @@ figure.aloha-oer-block .image-wrapper .image-edit { left: 100%; padding: 2px 10px 2px 5px; border-radius: 0 4px 4px 0; - width: 100px; + width: 20em; top: -8px; word-wrap: break-word; + line-height: 16px; } figure.aloha-oer-block .image-wrapper .image-edit:hover { @@ -73,7 +74,6 @@ figure.aloha-oer-block .image-wrapper .image-edit:not(.passive):hover { border: 1px dotted #1B86D2; background-color: #D9E7F1; z-index: 400; - width: 100px; word-wrap: break-word; } @@ -121,11 +121,13 @@ figure.aloha-oer-block .image-wrapper .image-edit.passive { i.icon-warning { display: inline-block; background-image: url(../img/warning-01.png); - background-position: 0 0; + background-position: 0 bottom; + background-repeat: no-repeat; margin-right: 4px; margin-left: 4px; width: 16px; height: 16px; + vertical-align: bottom; } .warning-text { From 58e78fd04a0b1828232e649788d5b826337a72f8 Mon Sep 17 00:00:00 2001 From: Max Starkenburg Date: Thu, 10 Oct 2013 18:07:10 -0500 Subject: [PATCH 07/16] Improve styling of type/label switcher - Bootstrappy style with span (or a). - First dropdown text should now appear directly on top of the label text. - Made a few adjustments in the coffee files to fix bugs or to make things consistent --- .../oer/definition/css/definition-plugin.css | 2 +- .../oer/example/lib/example-plugin.coffee | 2 +- src/plugins/oer/example/lib/example-plugin.js | 2 +- .../oer/multipart/lib/multipart-plugin.coffee | 2 +- .../oer/multipart/lib/multipart-plugin.js | 2 +- src/plugins/oer/note/lib/note-plugin.coffee | 2 +- src/plugins/oer/note/lib/note-plugin.js | 2 +- .../css/semanticblock-plugin.css | 62 ++++++++++++++----- 8 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/plugins/oer/definition/css/definition-plugin.css b/src/plugins/oer/definition/css/definition-plugin.css index 9df4e3a6af..7c79c3c5d0 100644 --- a/src/plugins/oer/definition/css/definition-plugin.css +++ b/src/plugins/oer/definition/css/definition-plugin.css @@ -17,7 +17,7 @@ dl.definition.aloha-oer-block { } .aloha-oer-block.definition .term-wrapper:before { - content: "\25A0 Definition"; + content: "\25A0 Definition"; font-weight: bold; margin: 5px 10px 0 5px; color: #369; diff --git a/src/plugins/oer/example/lib/example-plugin.coffee b/src/plugins/oer/example/lib/example-plugin.coffee index 976a380721..d3df85f6d1 100644 --- a/src/plugins/oer/example/lib/example-plugin.coffee +++ b/src/plugins/oer/example/lib/example-plugin.coffee @@ -10,7 +10,7 @@ define [ TYPE_CONTAINER = jQuery ''' - + diff --git a/src/plugins/oer/example/lib/example-plugin.js b/src/plugins/oer/example/lib/example-plugin.js index 6ef8ac0ec4..83deb08fba 100644 --- a/src/plugins/oer/example/lib/example-plugin.js +++ b/src/plugins/oer/example/lib/example-plugin.js @@ -2,7 +2,7 @@ (function() { define(['aloha', 'aloha/plugin', 'jquery', 'aloha/ephemera', 'ui/ui', 'ui/button', 'semanticblock/semanticblock-plugin', 'css!example/css/example-plugin.css'], function(Aloha, Plugin, jQuery, Ephemera, UI, Button, semanticBlock) { var TYPE_CONTAINER, exampleishClasses, types; - TYPE_CONTAINER = jQuery('\n \n \n'); + TYPE_CONTAINER = jQuery('\n \n \n'); exampleishClasses = {}; types = []; return Plugin.create('example', { diff --git a/src/plugins/oer/multipart/lib/multipart-plugin.coffee b/src/plugins/oer/multipart/lib/multipart-plugin.coffee index d811cde0bf..8bfb91283a 100644 --- a/src/plugins/oer/multipart/lib/multipart-plugin.coffee +++ b/src/plugins/oer/multipart/lib/multipart-plugin.coffee @@ -92,6 +92,6 @@ define [ $el.parents('.type-container').find('.dropdown-menu li').each (i, li) => jQuery(li).removeClass('checked') - $el.parents('li').first().addclass('checked') + $el.parents('li').first().addClass('checked') ) }) diff --git a/src/plugins/oer/multipart/lib/multipart-plugin.js b/src/plugins/oer/multipart/lib/multipart-plugin.js index 7c01889f44..05c0940a19 100644 --- a/src/plugins/oer/multipart/lib/multipart-plugin.js +++ b/src/plugins/oer/multipart/lib/multipart-plugin.js @@ -60,7 +60,7 @@ $el.parents('.type-container').find('.dropdown-menu li').each(function(i, li) { return jQuery(li).removeClass('checked'); }); - return $el.parents('li').first().addclass('checked'); + return $el.parents('li').first().addClass('checked'); }); } }); diff --git a/src/plugins/oer/note/lib/note-plugin.coffee b/src/plugins/oer/note/lib/note-plugin.coffee index 0a04244f49..28c0abe2f1 100644 --- a/src/plugins/oer/note/lib/note-plugin.coffee +++ b/src/plugins/oer/note/lib/note-plugin.coffee @@ -71,7 +71,7 @@ define [ $option = jQuery('
  • ') $option.appendTo(typeContainer.find('.dropdown-menu')) $option = $option.children('span') - $option.text(dropType.label.toUpperCase()) + $option.text(dropType.label) typeContainer.find('.type').on 'click', => jQuery.each types, (i, dropType) => if $element.attr('data-type') == dropType.type diff --git a/src/plugins/oer/note/lib/note-plugin.js b/src/plugins/oer/note/lib/note-plugin.js index cf991fb4f3..742b810c2b 100644 --- a/src/plugins/oer/note/lib/note-plugin.js +++ b/src/plugins/oer/note/lib/note-plugin.js @@ -43,7 +43,7 @@ $option = jQuery('
  • '); $option.appendTo(typeContainer.find('.dropdown-menu')); $option = $option.children('span'); - $option.text(dropType.label.toUpperCase()); + $option.text(dropType.label); typeContainer.find('.type').on('click', function() { return jQuery.each(types, function(i, dropType) { if ($element.attr('data-type') === dropType.type) { diff --git a/src/plugins/oer/semanticblock/css/semanticblock-plugin.css b/src/plugins/oer/semanticblock/css/semanticblock-plugin.css index bd2fb12435..f961da6fe8 100644 --- a/src/plugins/oer/semanticblock/css/semanticblock-plugin.css +++ b/src/plugins/oer/semanticblock/css/semanticblock-plugin.css @@ -153,39 +153,73 @@ border-left-color: #ccc; } -.aloha-oer-block .type:before { +/* Put a bullet/square before the element label/type. Include "li *" (dropdown code) so that the check mark shares styling ... specifics will be overriden later */ +.aloha-oer-block .type:before , .aloha-oer-block .type-container li *:before{ content: "\25A0"; - margin-right: 3px; + vertical-align: top; + font-size: .9em; + display: inline-block; + /* The following helps to account for size/weight differences of other marks (arrow, checkmark) without things jumping around so much */ + width: 11px; } -.semantic-container > * > .type-container .type:before { +.focused .aloha-oer-block .dropdown .type:before { + /* Change to arrow when hovering block */ content: "\25BE"; - margin-right: 3px; + /* Make adjustments so that arrow feels like same size/positioning as square */ + font-size: 1.5em; + margin-left: -2px; + margin-right: 2px; } .semantic-container .type-container { margin-bottom: 10px; + position: relative; + padding: 5px 10px; + display: inline; } -.aloha-oer-block .type { +.aloha-oer-block .type , .aloha-oer-block .type-container li *{ font-weight: bold; - margin: 5px 10px 0 5px; - color: #369; + color: #369 !important; /* Important if * is an due to ID-based declaration in oerpub-content.less */ text-decoration: none; } .aloha-oer-block .type-container ul.dropdown-menu { - margin: -1.5em 0 0 0 !important; + /* Put the dropdown exactly on top of current type (-1px for the dropdown's borders) */ + position: absolute; + top: -1px; + left: -1px; + margin: 0; + padding: 0; } -.aloha-oer-block .type-container li { - list-style-type: none !important; +.aloha-oer-block .type-container li *{ + padding: 5px 10px; + line-height: normal; + display: block; + cursor: pointer; } -.aloha-oer-block .type-container li.checked a:before { - content: "\2713"; - margin: 0 3px 0 -14px; +.aloha-oer-block .type-container li *:hover{ + color: #ffffff !important; /* Important if * is an due to ID-based declaration in oerpub-content.less */ + background-color: #0081c2; + background-image: -moz-linear-gradient(top, #0088cc, #0077b3); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3)); + background-image: -webkit-linear-gradient(top, #0088cc, #0077b3); + background-image: -o-linear-gradient(top, #0088cc, #0077b3); + background-image: linear-gradient(to bottom, #0088cc, #0077b3); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0); +} +.aloha-oer-block .type-container li *:before { + content: ""; /* nothing if not the selected one */ +} +.aloha-oer-block .type-container li.checked *:before { + content: "\2713"; /* checkmark if the selected one */ + margin-left: -4px; + margin-right: 4px; + font-size: 1em; } - .aloha-oer-block .title { font-size: 1em; } From 9676476cb2bcf6f6c60986f582355749c680d051 Mon Sep 17 00:00:00 2001 From: Max Starkenburg Date: Fri, 11 Oct 2013 10:51:26 -0500 Subject: [PATCH 08/16] arrow was too big in others' computers Dunno why arrow character is really small in my machine/OS/browser. This still looks small on my machine, but is "good enough", and looks much better on Tom's and probably Kathi's. --- src/plugins/oer/semanticblock/css/semanticblock-plugin.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/oer/semanticblock/css/semanticblock-plugin.css b/src/plugins/oer/semanticblock/css/semanticblock-plugin.css index f961da6fe8..4283f4bdbb 100644 --- a/src/plugins/oer/semanticblock/css/semanticblock-plugin.css +++ b/src/plugins/oer/semanticblock/css/semanticblock-plugin.css @@ -167,9 +167,9 @@ /* Change to arrow when hovering block */ content: "\25BE"; /* Make adjustments so that arrow feels like same size/positioning as square */ - font-size: 1.5em; - margin-left: -2px; - margin-right: 2px; + font-size: 1.1em; + margin-left: -1px; + margin-right: 1px; } .semantic-container .type-container { From b6a739b1de3468612c57ea6d6990b990cb852961 Mon Sep 17 00:00:00 2001 From: Max Starkenburg Date: Fri, 11 Oct 2013 10:14:42 -0500 Subject: [PATCH 09/16] prevent link popover from always wrapping Decided to still let it wrap if close to the edge. That popover still needs attention re: the icons, but it's better for now. The change to the .coffee file was made to prevent extra spacing from getting underlined, but I couldn't figure out a way to comment that section of the file, so noting it here. --- src/plugins/oer/assorted/css/link.css | 19 +++++++++---------- src/plugins/oer/assorted/lib/link.coffee | 3 +-- src/plugins/oer/assorted/lib/link.js | 5 ++--- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/plugins/oer/assorted/css/link.css b/src/plugins/oer/assorted/css/link.css index b34ce184e7..f8379147f5 100644 --- a/src/plugins/oer/assorted/css/link.css +++ b/src/plugins/oer/assorted/css/link.css @@ -45,6 +45,7 @@ ul.nav.nav-tabs { .link-popover { width: auto; min-width: 236px; /* bootstrap's default popover width */ + max-width: none; /* override bootstrap default so that the link options don't wrap */ } .link-popover-details .edit-link, @@ -53,17 +54,14 @@ ul.nav.nav-tabs { white-space: nowrap; } - -.edit-link, -.delete-link, -.visit-link { +.aloha.popover .link-popover-details button, .visit-link{ padding: 0 10px; } -/* Add a border (separator) only around the 1st 2 buttons */ -.edit-link, -.delete-link { - border-right: 1px solid black; +/* Add a separator after the 1st 2 buttons */ +.aloha.popover button.edit-link, +.aloha.popover button.delete-link { + border-right: 1px solid #bbb; } i.icon-edit-link { @@ -76,8 +74,9 @@ i.icon-delete-link { background-image: url(../img/delete-link.png); background-position: 0 0; } - i.icon-external-link { +/* commenting out for now since it's conflicting with .icon-external-link:before's image background-image: url(../img/external-link.png); background-position: 0 0; -} +*/ +} \ No newline at end of file diff --git a/src/plugins/oer/assorted/lib/link.coffee b/src/plugins/oer/assorted/lib/link.coffee index 3aa176b0e9..ce5cb005ef 100644 --- a/src/plugins/oer/assorted/lib/link.coffee +++ b/src/plugins/oer/assorted/lib/link.coffee @@ -69,8 +69,7 @@ define [ - - +
    ''' diff --git a/src/plugins/oer/assorted/lib/link.js b/src/plugins/oer/assorted/lib/link.js index 84158e78e6..c61f7d42d4 100644 --- a/src/plugins/oer/assorted/lib/link.js +++ b/src/plugins/oer/assorted/lib/link.js @@ -1,10 +1,9 @@ -// Generated by CoffeeScript 1.5.0 +// Generated by CoffeeScript 1.6.3 (function() { - define(['aloha', 'jquery', 'overlay/overlay-plugin', 'ui/ui', 'aloha/console', 'aloha/ephemera', 'css!assorted/css/link.css'], function(Aloha, jQuery, Popover, UI, console, Ephemera) { var DETAILS_HTML, DIALOG_HTML, getContainerAnchor, populator, selector, shortString, shortUrl, showModalDialog, unlink; DIALOG_HTML = ''; - DETAILS_HTML = '\n \n \n \n \n \n \n\n
    '; + DETAILS_HTML = '\n \n \n \n \n \n\n
    '; Ephemera.attributes('data-original-title'); showModalDialog = function($el) { var a, appendOption, dialog, figuresAndTables, href, linkContents, linkExternal, linkInput, linkInputId, linkInternal, linkSave, massageUrlInput, orgElements, root, From b218c2a4912c4b1fb764674625e862d9643108cc Mon Sep 17 00:00:00 2001 From: Max Starkenburg Date: Tue, 15 Oct 2013 01:06:52 -0500 Subject: [PATCH 10/16] use actual label instead of literal "this element" - "Advanced options for this [element]" instead of "advanced options." - "Copy [element]" instead of "Copy element" I also removed some periods because they bugged me, but if somebody really wants them, I won't fight it. --- .../semanticblock/lib/semanticblock-plugin.coffee | 12 +++++++----- .../oer/semanticblock/lib/semanticblock-plugin.js | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/plugins/oer/semanticblock/lib/semanticblock-plugin.coffee b/src/plugins/oer/semanticblock/lib/semanticblock-plugin.coffee index 1dee6a8a74..24419a520a 100644 --- a/src/plugins/oer/semanticblock/lib/semanticblock-plugin.coffee +++ b/src/plugins/oer/semanticblock/lib/semanticblock-plugin.coffee @@ -27,13 +27,13 @@ define ['aloha', 'block/blockmanager', 'aloha/plugin', 'aloha/pluginmanager', 'j blockTemplate = jQuery('
    ') topControls = jQuery(''' ''') blockControls = jQuery('''
    - - + +
    ''') blockDragHelper = jQuery('''
    @@ -194,8 +194,10 @@ define ['aloha', 'block/blockmanager', 'aloha/plugin', 'aloha/pluginmanager', 'j controls = blockControls.clone() top = topControls.clone() label = blockIdentifier($element) - controls.find('.semantic-delete').attr('title', "Remove this #{label}.") - top.find('.copy').attr('title', "Copy #{label}.") + controls.find('.semantic-delete').attr('title', "Remove this #{label}") + controls.find('.semantic-settings').attr('title', "Advanced options for this #{label}") + top.find('.copy').attr('title', "Copy this #{label}") + top.find('.copy').contents().last().replaceWith(" Copy #{label}") if type == null $element.wrap(blockTemplate).parent().append(controls).prepend(top).alohaBlock() else diff --git a/src/plugins/oer/semanticblock/lib/semanticblock-plugin.js b/src/plugins/oer/semanticblock/lib/semanticblock-plugin.js index 1fa1c613be..e204a3ebc2 100644 --- a/src/plugins/oer/semanticblock/lib/semanticblock-plugin.js +++ b/src/plugins/oer/semanticblock/lib/semanticblock-plugin.js @@ -9,8 +9,8 @@ } DIALOG_HTML = ''; blockTemplate = jQuery('
    '); - topControls = jQuery('
    '); - blockControls = jQuery('
    \n \n \n
    '); + topControls = jQuery('
    '); + blockControls = jQuery('
    \n \n \n
    '); blockDragHelper = jQuery('
    \n
    \n
    Drag me to the desired location in the document
    \n
    '); registeredTypes = []; copyBuffer = null; @@ -206,8 +206,10 @@ controls = blockControls.clone(); top = topControls.clone(); label = blockIdentifier($element); - controls.find('.semantic-delete').attr('title', "Remove this " + label + "."); - top.find('.copy').attr('title', "Copy " + label + "."); + controls.find('.semantic-delete').attr('title', "Remove this " + label); + controls.find('.semantic-settings').attr('title', "Advanced options for this " + label); + top.find('.copy').attr('title', "Copy this " + label); + top.find('.copy').contents().last().replaceWith(" Copy " + label); if (type === null) { $element.wrap(blockTemplate).parent().append(controls).prepend(top).alohaBlock(); } else { From 6d8cac525a625b706312ab3ea1973a270c6498b8 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Wed, 16 Oct 2013 10:40:51 +0200 Subject: [PATCH 11/16] No need to pass path to copy plugin buffer method anymore, it will now do this automatically. --- src/plugins/oer/copy/lib/copy-plugin.coffee | 8 ++------ src/plugins/oer/copy/lib/copy-plugin.js | 14 ++++---------- src/plugins/oer/math/lib/math-plugin.coffee | 2 +- src/plugins/oer/math/lib/math-plugin.js | 2 +- .../semanticblock/lib/semanticblock-plugin.coffee | 2 +- .../oer/semanticblock/lib/semanticblock-plugin.js | 2 +- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/plugins/oer/copy/lib/copy-plugin.coffee b/src/plugins/oer/copy/lib/copy-plugin.coffee index 8f65faeb0b..e1d6e5bfcb 100644 --- a/src/plugins/oer/copy/lib/copy-plugin.coffee +++ b/src/plugins/oer/copy/lib/copy-plugin.coffee @@ -29,7 +29,7 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa buffer: (content, path) -> buffer = content buffer = buffer.replace /id="[^"]+"/, '' - srcpath = path + srcpath = path or @getCurrentPath() localStorage.alohaOerCopyBuffer = buffer if localStorage localStorage.alohaOerCopySrcPath = srcpath if localStorage @@ -56,11 +56,7 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa html = '' html += jQuery(e).outerHtml() for e in $el - path = @getCurrentPath() - if path != null - @buffer html, path - else - @buffer html + @buffer html init: -> plugin = @ diff --git a/src/plugins/oer/copy/lib/copy-plugin.js b/src/plugins/oer/copy/lib/copy-plugin.js index dbac070859..3920aba516 100644 --- a/src/plugins/oer/copy/lib/copy-plugin.js +++ b/src/plugins/oer/copy/lib/copy-plugin.js @@ -1,6 +1,5 @@ -// 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; buffer = ''; @@ -30,7 +29,7 @@ var _base; buffer = content; buffer = buffer.replace(/id="[^"]+"/, ''); - srcpath = path; + srcpath = path || this.getCurrentPath(); if (localStorage) { localStorage.alohaOerCopyBuffer = buffer; } @@ -42,7 +41,7 @@ return typeof (_base = this.pastebutton).flash === "function" ? _base.flash() : void 0; }, copySection: function($el) { - var e, headings, html, level, path, selector, _i, _len; + 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(','); @@ -56,12 +55,7 @@ e = $el[_i]; html += jQuery(e).outerHtml(); } - path = this.getCurrentPath(); - if (path !== null) { - return this.buffer(html, path); - } else { - return this.buffer(html); - } + return this.buffer(html); }, init: function() { var addCopyUi, focusHeading, plugin, diff --git a/src/plugins/oer/math/lib/math-plugin.coffee b/src/plugins/oer/math/lib/math-plugin.coffee index 383c346f0c..4bda0a2a37 100644 --- a/src/plugins/oer/math/lib/math-plugin.coffee +++ b/src/plugins/oer/math/lib/math-plugin.coffee @@ -156,7 +156,7 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' e.originalEvent.clipboardData.setData 'text/oerpub-content', $content.html() # Also buffer it in our local copy buffer - Copy.buffer $content.html(), Copy.getCurrentPath() + Copy.buffer $content.html() editable.obj.on 'paste', (e) -> content = e.originalEvent.clipboardData.getData('text/oerpub-content') diff --git a/src/plugins/oer/math/lib/math-plugin.js b/src/plugins/oer/math/lib/math-plugin.js index 27af0cdc65..9de6b529b2 100644 --- a/src/plugins/oer/math/lib/math-plugin.js +++ b/src/plugins/oer/math/lib/math-plugin.js @@ -85,7 +85,7 @@ e.preventDefault(); e.originalEvent.clipboardData.setData('text/oerpub-content', $content.html()); } - return Copy.buffer($content.html(), Copy.getCurrentPath()); + return Copy.buffer($content.html()); }); editable.obj.on('paste', function(e) { var $content, content, math, range; diff --git a/src/plugins/oer/semanticblock/lib/semanticblock-plugin.coffee b/src/plugins/oer/semanticblock/lib/semanticblock-plugin.coffee index 24419a520a..ab97ac3ee8 100644 --- a/src/plugins/oer/semanticblock/lib/semanticblock-plugin.coffee +++ b/src/plugins/oer/semanticblock/lib/semanticblock-plugin.coffee @@ -86,7 +86,7 @@ define ['aloha', 'block/blockmanager', 'aloha/plugin', 'aloha/pluginmanager', 'j callback: (e) -> # grab the content of the block that was just clicked $element = jQuery(this).parents('.semantic-container').first() - Copy.buffer $element.outerHtml(), Copy.getCurrentPath() + Copy.buffer $element.outerHtml() , name: 'mouseover' selector: '.semantic-container .semantic-controls-top .copy' diff --git a/src/plugins/oer/semanticblock/lib/semanticblock-plugin.js b/src/plugins/oer/semanticblock/lib/semanticblock-plugin.js index e204a3ebc2..3a7d03f71f 100644 --- a/src/plugins/oer/semanticblock/lib/semanticblock-plugin.js +++ b/src/plugins/oer/semanticblock/lib/semanticblock-plugin.js @@ -68,7 +68,7 @@ callback: function(e) { var $element; $element = jQuery(this).parents('.semantic-container').first(); - return Copy.buffer($element.outerHtml(), Copy.getCurrentPath()); + return Copy.buffer($element.outerHtml()); } }, { name: 'mouseover', From aea39012d44c1e5fef7c9861fe381447a5ff5c55 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Wed, 16 Oct 2013 10:54:52 +0200 Subject: [PATCH 12/16] Take a content-type option to buffer, similar to real clipboard. This defaults to text/html. --- src/plugins/oer/copy/lib/copy-plugin.coffee | 11 ++++++++++- src/plugins/oer/copy/lib/copy-plugin.js | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/plugins/oer/copy/lib/copy-plugin.coffee b/src/plugins/oer/copy/lib/copy-plugin.coffee index e1d6e5bfcb..5935249c2f 100644 --- a/src/plugins/oer/copy/lib/copy-plugin.coffee +++ b/src/plugins/oer/copy/lib/copy-plugin.coffee @@ -2,6 +2,7 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa buffer = '' srcpath = null + content_type = null Plugin.create 'copy', getCurrentPath: -> @@ -26,13 +27,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="[^"]+"/, '' + 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 diff --git a/src/plugins/oer/copy/lib/copy-plugin.js b/src/plugins/oer/copy/lib/copy-plugin.js index 3920aba516..184a6947ab 100644 --- a/src/plugins/oer/copy/lib/copy-plugin.js +++ b/src/plugins/oer/copy/lib/copy-plugin.js @@ -1,9 +1,10 @@ // 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, srcpath; buffer = ''; srcpath = null; + content_type = null; return Plugin.create('copy', { getCurrentPath: function() { if (this.settings.path) { @@ -25,10 +26,18 @@ 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="[^"]+"/, ''); + content_type = type || 'text/html'; srcpath = path || this.getCurrentPath(); if (localStorage) { localStorage.alohaOerCopyBuffer = buffer; @@ -36,6 +45,9 @@ 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; From 89be7226e92dcfe4f5b2674f8991459f2e3937c8 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Wed, 16 Oct 2013 11:02:30 +0200 Subject: [PATCH 13/16] Specify custom content type when duplicating copy to local buffer. --- src/plugins/oer/math/lib/math-plugin.coffee | 10 +++++----- src/plugins/oer/math/lib/math-plugin.js | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/plugins/oer/math/lib/math-plugin.coffee b/src/plugins/oer/math/lib/math-plugin.coffee index 4bda0a2a37..6be4e44ee1 100644 --- a/src/plugins/oer/math/lib/math-plugin.coffee +++ b/src/plugins/oer/math/lib/math-plugin.coffee @@ -150,13 +150,13 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' # Check that we also have a script tag in our selection, that occurs # towards the end of the math and ensures we have the whole of it. # The idea is to only do custom copy/paste if we need it, and let the - # browser handle other content. + # browser handle other content. Also buffer it in our local copy buffer. if $content.has('span.math-element').length and $content.has('script').length e.preventDefault() e.originalEvent.clipboardData.setData 'text/oerpub-content', $content.html() - - # Also buffer it in our local copy buffer - Copy.buffer $content.html() + Copy.buffer $content.html(), 'text/oerpub-content' + else + Copy.buffer $content.html() editable.obj.on 'paste', (e) -> content = e.originalEvent.clipboardData.getData('text/oerpub-content') @@ -511,7 +511,7 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' MathJax.Callback.Queue MathJax.Hub.Register.StartupHook "MathMenu Ready", () -> copyCommand = MathJax.Menu.ITEM.COMMAND "Copy Math", (e,f,g) -> $script = jQuery(document.getElementById(MathJax.Menu.jax.inputID)) - Copy.buffer $script.parent().parent().outerHtml() + Copy.buffer $script.parent().parent().outerHtml(), 'text/oerpub-content' MathJax.Menu.menu.items.unshift copyCommand ob = diff --git a/src/plugins/oer/math/lib/math-plugin.js b/src/plugins/oer/math/lib/math-plugin.js index 9de6b529b2..720908765c 100644 --- a/src/plugins/oer/math/lib/math-plugin.js +++ b/src/plugins/oer/math/lib/math-plugin.js @@ -84,8 +84,10 @@ if ($content.has('span.math-element').length && $content.has('script').length) { e.preventDefault(); e.originalEvent.clipboardData.setData('text/oerpub-content', $content.html()); + return Copy.buffer($content.html(), 'text/oerpub-content'); + } else { + return Copy.buffer($content.html()); } - return Copy.buffer($content.html()); }); editable.obj.on('paste', function(e) { var $content, content, math, range; @@ -426,7 +428,7 @@ copyCommand = MathJax.Menu.ITEM.COMMAND("Copy Math", function(e, f, g) { var $script; $script = jQuery(document.getElementById(MathJax.Menu.jax.inputID)); - return Copy.buffer($script.parent().parent().outerHtml()); + return Copy.buffer($script.parent().parent().outerHtml(), 'text/oerpub-content'); }); return MathJax.Menu.menu.items.unshift(copyCommand); })); From cfc6e84dd6823de427268b0ec356f116b7668b0e Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Wed, 16 Oct 2013 11:25:51 +0200 Subject: [PATCH 14/16] copy/paste handlers slightly modified to allow other code to trigger them. --- src/plugins/oer/math/lib/math-plugin.coffee | 9 +++++---- src/plugins/oer/math/lib/math-plugin.js | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/plugins/oer/math/lib/math-plugin.coffee b/src/plugins/oer/math/lib/math-plugin.coffee index 6be4e44ee1..d0589c16f8 100644 --- a/src/plugins/oer/math/lib/math-plugin.coffee +++ b/src/plugins/oer/math/lib/math-plugin.coffee @@ -144,7 +144,7 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' # type again when pasting. Prevent the browser default. This will only work # in browsers that support event.clipboardData, chrome and safari to date. editable.obj.on 'copy', (e) -> - content = Aloha.getSelection().getRangeAt(0).cloneContents() + content = e.oerContent or Aloha.getSelection().getRangeAt(0).cloneContents() $content = $('
    ').append(content) # If there is math among the content we're copying, treat it specially. # Check that we also have a script tag in our selection, that occurs @@ -153,13 +153,14 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' # browser handle other content. Also buffer it in our local copy buffer. if $content.has('span.math-element').length and $content.has('script').length e.preventDefault() - e.originalEvent.clipboardData.setData 'text/oerpub-content', $content.html() - Copy.buffer $content.html(), 'text/oerpub-content' + clipboard = e.clipboardData or e.originalEvent.clipboardData + clipboard.setData 'text/oerpub-content', $content.html() else Copy.buffer $content.html() editable.obj.on 'paste', (e) -> - content = e.originalEvent.clipboardData.getData('text/oerpub-content') + clipboard = e.clipboardData or e.originalEvent.clipboardData + content = clipboard.getData('text/oerpub-content') if content e.preventDefault() $content = jQuery( diff --git a/src/plugins/oer/math/lib/math-plugin.js b/src/plugins/oer/math/lib/math-plugin.js index 720908765c..6125814322 100644 --- a/src/plugins/oer/math/lib/math-plugin.js +++ b/src/plugins/oer/math/lib/math-plugin.js @@ -78,20 +78,21 @@ return; } editable.obj.on('copy', function(e) { - var $content, content; - content = Aloha.getSelection().getRangeAt(0).cloneContents(); + var $content, clipboard, content; + content = e.oerContent || Aloha.getSelection().getRangeAt(0).cloneContents(); $content = $('
    ').append(content); if ($content.has('span.math-element').length && $content.has('script').length) { e.preventDefault(); - e.originalEvent.clipboardData.setData('text/oerpub-content', $content.html()); - return Copy.buffer($content.html(), 'text/oerpub-content'); + clipboard = e.clipboardData || e.originalEvent.clipboardData; + return clipboard.setData('text/oerpub-content', $content.html()); } else { return Copy.buffer($content.html()); } }); editable.obj.on('paste', function(e) { - var $content, content, math, range; - content = e.originalEvent.clipboardData.getData('text/oerpub-content'); + var $content, clipboard, content, math, range; + clipboard = e.clipboardData || e.originalEvent.clipboardData; + content = clipboard.getData('text/oerpub-content'); if (content) { e.preventDefault(); $content = jQuery('
    ').append(content).hide(); From 947af9dc8d722d0533fa5c6e95e1a92a82bbdea1 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Wed, 16 Oct 2013 12:42:59 +0200 Subject: [PATCH 15/16] Copy plugin delegates copy/paste via events This allows the math plugin to handle pastes, even when the copy plugin is doing it. --- src/plugins/oer/copy/lib/copy-plugin.coffee | 54 +++++++++++++----- src/plugins/oer/copy/lib/copy-plugin.js | 63 +++++++++++++++------ 2 files changed, 85 insertions(+), 32 deletions(-) diff --git a/src/plugins/oer/copy/lib/copy-plugin.coffee b/src/plugins/oer/copy/lib/copy-plugin.coffee index 5935249c2f..a06e818ced 100644 --- a/src/plugins/oer/copy/lib/copy-plugin.coffee +++ b/src/plugins/oer/copy/lib/copy-plugin.coffee @@ -4,6 +4,22 @@ define ['aloha', 'aloha/plugin', 'jquery', 'ui/ui', 'ui/button', 'PubSub', './pa 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: -> # When copy/pasting html, the images contained therein might have @@ -51,21 +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 + content = getSection($el) - @buffer html + # 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 = @ @@ -94,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() @@ -116,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 184a6947ab..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.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, content_type, 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) { @@ -53,21 +70,20 @@ return typeof (_base = this.pastebutton).flash === "function" ? _base.flash() : void 0; }, copySection: 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(); + 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); } - return this.buffer(html); }, init: function() { var addCopyUi, focusHeading, plugin, @@ -92,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) { @@ -118,6 +146,7 @@ }); } } + range = Aloha.Selection.getRangeObject(); return GENTICS.Utils.Dom.insertIntoDOM($elements, range, Aloha.activeEditable.obj); } }); From 278e6c6bd00b98d088d15d9d9c8fd9d472346352 Mon Sep 17 00:00:00 2001 From: Izak Burger Date: Wed, 16 Oct 2013 13:01:22 +0200 Subject: [PATCH 16/16] Add a copy button to the math popover --- src/plugins/oer/math/css/math.css | 2 +- src/plugins/oer/math/lib/math-plugin.coffee | 3 +++ src/plugins/oer/math/lib/math-plugin.js | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) 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 d0589c16f8..fe4f912034 100644 --- a/src/plugins/oer/math/lib/math-plugin.coffee +++ b/src/plugins/oer/math/lib/math-plugin.coffee @@ -61,6 +61,7 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' Plain text +
    ''' @@ -329,6 +330,8 @@ define [ 'aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', ' $editor.find('.remove').on 'click', => $span.trigger 'hide-popover' cleanupFormula($editor, $span, true) + $editor.find('.copy').on 'click', => + Copy.buffer $span.outerHtml(), 'text/oerpub-content' $formula = $editor.find('.formula') diff --git a/src/plugins/oer/math/lib/math-plugin.js b/src/plugins/oer/math/lib/math-plugin.js index 6125814322..475cfd9de9 100644 --- a/src/plugins/oer/math/lib/math-plugin.js +++ b/src/plugins/oer/math/lib/math-plugin.js @@ -4,7 +4,7 @@ define(['aloha', 'aloha/plugin', 'jquery', 'overlay/overlay-plugin', 'ui/ui', 'copy/copy-plugin', 'css!../../../oer/math/css/math.css'], function(Aloha, Plugin, jQuery, Popover, UI, Copy) { var $_editor, EDITOR_HTML, LANGUAGES, MATHML_ANNOTATION_MIME_ENCODINGS, MATHML_ANNOTATION_NONMIME_ENCODINGS, TOOLTIP_TEMPLATE, addAnnotation, buildEditor, cleanupFormula, findFormula, getEncoding, getMathFor, insertMath, insertMathInto, makeCloseIcon, ob, placeCursorAfter, squirrelMath, triggerMathJax; - EDITOR_HTML = '
    \n
    \n

    \n \n
    \n \n
    '; + EDITOR_HTML = '
    \n
    \n

    \n \n
    \n \n
    '; $_editor = jQuery(EDITOR_HTML); LANGUAGES = { 'math/asciimath': { @@ -249,6 +249,9 @@ $span.trigger('hide-popover'); return cleanupFormula($editor, $span, true); }); + $editor.find('.copy').on('click', function() { + return Copy.buffer($span.outerHtml(), 'text/oerpub-content'); + }); $formula = $editor.find('.formula'); mimeType = $span.find('script[type]').attr('type') || 'math/tex'; mimeType = mimeType.split(';')[0];