From: <var...@us...> - 2016-05-25 16:21:25
|
Revision: 9855 http://sourceforge.net/p/phpwiki/code/9855 Author: vargenau Date: 2016-05-25 16:21:23 +0000 (Wed, 25 May 2016) Log Message: ----------- Use jquery.autoheight.js plugin for Transclude plugin Modified Paths: -------------- trunk/lib/WikiTheme.php trunk/lib/plugin/Transclude.php Added Paths: ----------- trunk/themes/default/jquery.autoheight.js Modified: trunk/lib/WikiTheme.php =================================================================== --- trunk/lib/WikiTheme.php 2016-05-25 12:30:10 UTC (rev 9854) +++ trunk/lib/WikiTheme.php 2016-05-25 16:21:23 UTC (rev 9855) @@ -262,6 +262,7 @@ $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("jquery-2.2.4.min.js")))); $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("jquery.tablesorter.min.js")))); } + $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("jquery.autoheight.js")))); // by pixels if ((is_object($request) // guard against unittests and $request->getPref('doubleClickEdit')) Modified: trunk/lib/plugin/Transclude.php =================================================================== --- trunk/lib/plugin/Transclude.php 2016-05-25 12:30:10 UTC (rev 9854) +++ trunk/lib/plugin/Transclude.php 2016-05-25 16:21:23 UTC (rev 9855) @@ -102,8 +102,7 @@ 'height' => $height, 'marginwidth' => 0, 'marginheight' => 0, - 'class' => 'transclude', - "onload" => "adjust_iframe_height(this);"); + 'class' => 'autoHeight transclude'); $noframe_msg[] = fmt("See: %s", HTML::a(array('href' => $src), $src)); @@ -117,47 +116,10 @@ */ if ($quiet) { - return HTML($this->_js(), $iframe); + return $iframe; } else { return HTML(HTML::p(array('class' => 'transclusion-title'), - fmt("Transcluded from %s", LinkURL($src))), - $this->_js(), $iframe); + fmt("Transcluded from %s", LinkURL($src))), $iframe); } } - - /** - * Produce our javascript. - * - * This is used to resize the iframe to fit the content. - * Currently it only works if the transcluded document comes - * from the same server as the wiki server. - */ - private function _js() - { - static $seen = false; - - if ($seen) - return ''; - $seen = true; - - return JavaScript(' - function adjust_iframe_height(frame) { - var content = frame.contentDocument; - try { - frame.height = content.height + 2 * frame.marginHeight; - } - catch (e) { - // Cannot get content.height unless transcluded doc - // is from the same server... - return; - } - } - - window.addEventListener("resize", function() { - f = this.document.body.getElementsByTagName("iframe"); - for (var i = 0; i < f.length; i++) - adjust_iframe_height(f[i]); - }, false); - '); - } } Added: trunk/themes/default/jquery.autoheight.js =================================================================== --- trunk/themes/default/jquery.autoheight.js (rev 0) +++ trunk/themes/default/jquery.autoheight.js 2016-05-25 16:21:23 UTC (rev 9855) @@ -0,0 +1,33 @@ +function doIframe(){ + o = document.getElementsByTagName('iframe'); + for(i=0;i<o.length;i++){ + if (/\bautoHeight\b/.test(o[i].className)){ + setHeight(o[i]); + addEvent(o[i],'load', doIframe); + } + } +} + +function setHeight(e){ + if(e.contentDocument){ + e.height = e.contentDocument.body.offsetHeight + 35; + } else { + e.height = e.contentWindow.document.body.scrollHeight; + } +} + +function addEvent(obj, evType, fn){ + if(obj.addEventListener) { + obj.addEventListener(evType, fn,false); + return true; + } else if (obj.attachEvent){ + var r = obj.attachEvent("on"+evType, fn); + return r; + } else { + return false; + } +} + +if (document.getElementById && document.createTextNode){ + addEvent(window,'load', doIframe); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |