From 8858c8f5ddfb0ff8a171d5377cf6a9bdf07a1bcb Mon Sep 17 00:00:00 2001 From: Fred Chasen Date: Thu, 7 Feb 2013 13:24:26 -0800 Subject: [PATCH] added in missing file and fixed events error --- fpjs/render/events.js | 2 +- fpjs/render/transculsions.js | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 fpjs/render/transculsions.js diff --git a/fpjs/render/events.js b/fpjs/render/events.js index f3d75f9..e3a68c2 100644 --- a/fpjs/render/events.js +++ b/fpjs/render/events.js @@ -66,5 +66,5 @@ FP.Events.prototype.listenUntil = function(OnEvt, OffEvt, func, bindto){ this.deafen(OffEvt, unlisten); } - this.listen(OffEvt, unlisten); + this.listen(OffEvt, unlisten, this); } \ No newline at end of file diff --git a/fpjs/render/transculsions.js b/fpjs/render/transculsions.js new file mode 100644 index 0000000..e483cb7 --- /dev/null +++ b/fpjs/render/transculsions.js @@ -0,0 +1,54 @@ +FP.Hooks.register("beforeChapterDisplay").transculsions = function(callback, chapter){ + + var trans = chapter.doc.querySelectorAll('[transclusion]'), + items = Array.prototype.slice.call(trans);; + + items.forEach(function(item){ + var src = item.getAttribute("ref"), + iframe = document.createElement('iframe'), + orginal_width = item.getAttribute("width"), + orginal_height = item.getAttribute("height"), + parent = item.parentNode, + width = orginal_width, + height = orginal_height, + ratio; + + + function size() { + width = orginal_width; + height = orginal_height; + + if(width > chapter.colWidth){ + ratio = chapter.colWidth / width; + + width = chapter.colWidth; + height = height * ratio; + } + + iframe.width = width; + iframe.height = height; + } + + + size(); + + //-- resize event + + + chapter.book.listenUntil("book:resized", "book:chapterDestroy", size); + + iframe.src = src; + + // + parent.replaceChild(iframe, item); + + + }); + + + + + if(callback) callback(); + + +}