From 8156930208c0a7d9a967528ca7dfbb5c7c8a4772 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 26 Jan 2015 01:44:40 +0000 Subject: [PATCH 1/5] clean support for image hook --- src/static/js/contentcollector.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index 1f0620fef..ca193f73e 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -458,6 +458,20 @@ function makeContentCollector(collectStyles, abrowser, apool, domInterface, clas else { var tname = (dom.nodeTagName(node) || "").toLowerCase(); + + // Images shouldn't be defined as empty. + if (tname == "img"){ + isEmpty = false; + hooks.callAll('collectContentImage', { + cc: cc, + state: state, + tname: tname, + styl: styl, + cls: cls, + node: node + }); + } + if (tname == "br") { this.breakLine = true; From 18121a15071f775d6605719088ea147bb4cd1d14 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 26 Jan 2015 02:32:58 +0000 Subject: [PATCH 2/5] much cleaner --- src/static/js/contentcollector.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index ca193f73e..c0964c4a1 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -461,15 +461,14 @@ function makeContentCollector(collectStyles, abrowser, apool, domInterface, clas // Images shouldn't be defined as empty. if (tname == "img"){ - isEmpty = false; - hooks.callAll('collectContentImage', { + var context = hooks.callAll('collectContentImage', { cc: cc, state: state, tname: tname, styl: styl, cls: cls, node: node - }); + }); } if (tname == "br") From c4f1189ebdc92f0da286c3939995f1564d5497dd Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 26 Jan 2015 02:39:43 +0000 Subject: [PATCH 3/5] even cleaner --- src/static/js/contentcollector.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index c0964c4a1..2c8eefbfc 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -459,7 +459,6 @@ function makeContentCollector(collectStyles, abrowser, apool, domInterface, clas { var tname = (dom.nodeTagName(node) || "").toLowerCase(); - // Images shouldn't be defined as empty. if (tname == "img"){ var context = hooks.callAll('collectContentImage', { cc: cc, @@ -470,8 +469,7 @@ function makeContentCollector(collectStyles, abrowser, apool, domInterface, clas node: node }); } - - if (tname == "br") + else if (tname == "br") { this.breakLine = true; var tvalue = dom.nodeAttr(node, 'value'); From 2c3ce30fedf10e4bbdeeef6bd042a32dae0abd6e Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 26 Jan 2015 02:42:48 +0000 Subject: [PATCH 4/5] docs --- doc/api/hooks_client-side.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.md index ca429a075..384085053 100644 --- a/doc/api/hooks_client-side.md +++ b/doc/api/hooks_client-side.md @@ -203,6 +203,28 @@ Things in context: This hook is called before the content of a node is collected by the usual methods. The cc object can be used to do a bunch of things that modify the content of the pad. See, for example, the heading1 plugin for etherpad original. +## collectContentImage +Called from: src/static/js/contentcollector.js + +Things in context: + +1. cc - the contentcollector object +2. state - the current state of the change being made +3. tname - the tag name of this node currently being processed +4. style - the style applied to the node (probably CSS) +5. cls - the HTML class string of the node + +This hook is called before the content of an image node is collected by the usual methods. The cc object can be used to do a bunch of things that modify the content of the pad. + +Example: + +``` +exports.collectContentImage = function(name, context){ + context.state.lineAttributes.img = context.node.outerHTML; +} + +``` + ## collectContentPost Called from: src/static/js/contentcollector.js From b8ac349b530a317675ac7bda5180c02248685f31 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 26 Jan 2015 16:07:46 +0000 Subject: [PATCH 5/5] Update hooks_client-side.md --- doc/api/hooks_client-side.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.md index 384085053..8e2d3da79 100644 --- a/doc/api/hooks_client-side.md +++ b/doc/api/hooks_client-side.md @@ -213,6 +213,7 @@ Things in context: 3. tname - the tag name of this node currently being processed 4. style - the style applied to the node (probably CSS) 5. cls - the HTML class string of the node +6. node - the node being modified This hook is called before the content of an image node is collected by the usual methods. The cc object can be used to do a bunch of things that modify the content of the pad.