Skip to content

Commit

Permalink
Image deletion in HTML compose mode no longer requires polling
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Dec 5, 2014
1 parent 1703ac2 commit c7bc361
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 71 deletions.
62 changes: 0 additions & 62 deletions imp/js/ckeditor/imagepoll.js

This file was deleted.

70 changes: 70 additions & 0 deletions imp/js/ckeditor/images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* CKEditor 3 doesn't support onchange event for content body.
* Instead, need to track attached images to detect deletions, since this may
* influence attachment limits.
*
* @author Michael Slusarz <slusarz@horde.org>
* @copyright 2014 Horde LLC
* @license GPL-2 (http://www.horde.org/licenses/gpl)
*/

var ImpCkeditorImgs = {};
// 'related_attr' property set in IMP_Script_Package_ComposeBase

(function (ob) {
var active = [];

function checkRemove(ev)
{
var del = [],
n = ev.editor.name;

active[n].each(function(a) {
if (!a.parentNode) {
del.push(a);
}
});

ob.remove(ev.editor, del);
};

ob.add = function(editor, elt)
{
var n = editor.name;

if (!active[n]) {
active[n] = [];
editor.on('afterUndoImage', checkRemove);
}

active[n].push(elt);
};

ob.remove = function(editor, elts)
{
var ids = [],
n = editor.name;

if (!elts.size()) {
return;
}

elts.invoke('getAttribute', ob.related_attr).compact().each(function(r) {
var s = r.split(';', 2);
ids.push(s[1]);
});

ImpCompose.attachlist.removeAttach(ids, true);

// Array.without() doesn't support array input.
active[n] = active[n].findAll(function(v) {
return !elts.include(v);
});

if (!active[n].size()) {
delete active[n];
editor.removeListener('afterUndoImage', checkRemove);
}
};

}(ImpCkeditorImgs));
4 changes: 2 additions & 2 deletions imp/js/ckeditor/imageupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ document.observe('dom:loaded', function() {

definition.dialog.on('cancel', function(ev2) {
if (rf.attrdata) {
IMP_Ckeditor_Imagepoll.remove([
ImpCkeditorImgs.remove(ev.editor, [
new CKEDITOR.dom.element('IMG').writeAttribute(rf.attrdata)
]);
}
Expand All @@ -59,7 +59,7 @@ document.observe('dom:loaded', function() {
var elt = new CKEDITOR.dom.element(ev2.sender.imageElement.$);
if (elt.isVisible()) {
elt.setAttributes(rf.attrdata);
IMP_Ckeditor_Imagepoll.add(elt.$);
ImpCkeditorImgs.add(ev.editor, elt.$);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions imp/js/ckeditor/pasteattachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CKEDITOR.plugins.add('pasteattachment', {
elt.setAttribute(r.img.related[0], r.img.related[1]);
elt.setAttribute('height', elt.height);
elt.setAttribute('width', elt.width);
IMP_Ckeditor_Imagepoll.add(elt);
ImpCkeditorImgs.add(editor, elt);
} else {
elt.parentNode.removeChild(elt);
}
Expand Down Expand Up @@ -148,7 +148,7 @@ CKEDITOR.plugins.add('pasteattachment', {
if (data.size() != 2) {
/* IE 10 doesn't support pasting images, so don't try
* to copy HTML IMG source. */
if (span.hasAttribute(IMP_Ckeditor_Imagepoll.related_attr)) {
if (span.hasAttribute(ImpCkeditorImgs.related_attr)) {
ev.data.html = '';
}
return;
Expand Down
4 changes: 2 additions & 2 deletions imp/lib/Script/Package/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function __construct()
case $registry::VIEW_BASIC:
case $registry::VIEW_DYNAMIC:
$this->_files[] = new Horde_Script_File_JsDir('ckeditor/imageupload.js', 'imp');
$this->_files[] = new Horde_Script_File_JsDir('ckeditor/imagepoll.js', 'imp');
$this->_files[] = new Horde_Script_File_JsDir('ckeditor/images.js', 'imp');
$page_output->addInlineJsVars(array(
'IMP_Ckeditor_Imagepoll.related_attr' => IMP_Compose::RELATED_ATTR
'ImpCkeditorImgs.related_attr' => IMP_Compose::RELATED_ATTR
));

$js = new Horde_Script_File_JsDir('ckeditor/pasteattachment.js', 'imp');
Expand Down
6 changes: 3 additions & 3 deletions imp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2014-12-04</date>
<date>2014-12-05</date>
<version>
<release>7.0.0</release>
<api>7.0.0</api>
Expand Down Expand Up @@ -97,7 +97,7 @@
</dir> <!-- /docs -->
<dir name="js">
<dir name="ckeditor">
<file name="imagepoll.js" role="horde" />
<file name="images.js" role="horde" />
<file name="imageupload.js" role="horde" />
<file name="pasteattachment.js" role="horde" />
<file name="pasteignore.js" role="horde" />
Expand Down Expand Up @@ -1529,7 +1529,7 @@
<install as="imp/js/smartmobile.js" name="js/smartmobile.js" />
<install as="imp/js/viewport.js" name="js/viewport.js" />
<install as="imp/js/viewport_utils.js" name="js/viewport_utils.js" />
<install as="imp/js/ckeditor/imagepoll.js" name="js/ckeditor/imagepoll.js" />
<install as="imp/js/ckeditor/images.js" name="js/ckeditor/images.js" />
<install as="imp/js/ckeditor/imageupload.js" name="js/ckeditor/imageupload.js" />
<install as="imp/js/ckeditor/pasteattachment.js" name="js/ckeditor/pasteattachment.js" />
<install as="imp/js/ckeditor/pasteignore.js" name="js/ckeditor/pasteignore.js" />
Expand Down

0 comments on commit c7bc361

Please sign in to comment.