From 7071d6d9089250cb5cd51949595de6a439edf026 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Thu, 27 Apr 2006 19:45:00 +0000 Subject: [PATCH] Deleted a bunch of js code and trying another (the last) way to resize the iframe properly. Tests at home 100% reliable. I hope it'll work ok remotely... Depending of results we'll decide the final system. --- mod/resource/type/ims/javascript.php | 20 ++- mod/resource/type/ims/resize.js | 225 +-------------------------- 2 files changed, 19 insertions(+), 226 deletions(-) diff --git a/mod/resource/type/ims/javascript.php b/mod/resource/type/ims/javascript.php index 99c90d952c..cc7517bc57 100644 --- a/mod/resource/type/ims/javascript.php +++ b/mod/resource/type/ims/javascript.php @@ -18,10 +18,24 @@ window.onresize = function() { resizeiframe($jsarg); }; - addDOMLoadEvent(function() { - resizeiframe($jsarg); - }); window.name='ims-cp-page'; + + // Set Interval until ims-contentframe or ims-contentframe-no-nav is available + function waiting() { + var cf = document.getElementById('ims-contentframe'); + var cfnv = document.getElementById('ims-contentframe-no-nav'); + + if (cf || cfnv) { + if (cf) cf.style.display = 'block'; + if (cfnv) cf.style.display = 'block'; + resizeiframe($jsarg); + clearInterval(ourInterval); + return true; + } + return false; + } + + var ourInterval = setInterval('waiting()', 100); \n"; /// Load standard JavaScript diff --git a/mod/resource/type/ims/resize.js b/mod/resource/type/ims/resize.js index 48396c9329..aeb7d519eb 100644 --- a/mod/resource/type/ims/resize.js +++ b/mod/resource/type/ims/resize.js @@ -1,228 +1,7 @@ /* - * This script resizes everything to fit the window. Maybe a fixed iframe - * would be better? + * This script resizes everything to fit the iframe + * of the ims-cp resource type. Credits goes to Andrew Walker. */ - -// written by Dean Edwards, 2005 -// with input from Tino Zijdel - crisp@xs4all.nl -// http://dean.edwards.name/weblog/2005/10/add-event/ -function addEvent(element, type, handler) -{ - // Modification by Tanny O'Haley, http://tanny.ica.com to add the - // DOMContentLoaded for all browsers. - if (type == "DOMContentLoaded" || type == "domload") - { - addDOMLoadEvent(handler); - return; - } - - if (element.addEventListener) - element.addEventListener(type, handler, false); - else - { - if (!handler.$$guid) handler.$$guid = addEvent.guid++; - if (!element.events) element.events = {}; - var handlers = element.events[type]; - if (!handlers) - { - handlers = element.events[type] = {}; - if (element['on' + type]) handlers[0] = element['on' + type]; - element['on' + type] = handleEvent; - } - - handlers[handler.$$guid] = handler; - } -} - -addEvent.guid = 1; - -function removeEvent(element, type, handler) -{ - if (element.removeEventListener) - element.removeEventListener(type, handler, false); - else if (element.events && element.events[type] && handler.$$guid) - delete element.events[type][handler.$$guid]; -} - -function handleEvent(event) -{ - event = event || fixEvent(window.event); - var returnValue = true; - var handlers = this.events[event.type]; - - for (var i in handlers) - { - if (!Object.prototype[i]) - { - this.$$handler = handlers[i]; - if (this.$$handler(event) === false) returnValue = false; - } - } - - if (this.$$handler) this.$$handler = null; - - return returnValue; -} - -function fixEvent(event) -{ - event.preventDefault = fixEvent.preventDefault; - event.stopPropagation = fixEvent.stopPropagation; - return event; -} -fixEvent.preventDefault = function() -{ - this.returnValue = false; -} -fixEvent.stopPropagation = function() -{ - this.cancelBubble = true; -} - -// This little snippet fixes the problem that the onload attribute on the body-element will overwrite -// previous attached events on the window object for the onload event -if (!window.addEventListener) -{ - document.onreadystatechange = function() - { - if (window.onload && window.onload != handleEvent) - { - addEvent(window, 'load', window.onload); - window.onload = handleEvent; - } - } -} - -// End Dean Edwards addEvent. - - -// DF1.1 :: domFunction -// ***************************************************** -// DOM scripting by brothercake -- http://www.brothercake.com/ -// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html -//****************************************************** - -//DOM-ready watcher -function domFunction(f, a) -{ - //initialise the counter - var n = 0; - - //start the timer - var t = setInterval(function() - { - //continue flag indicates whether to continue to the next iteration - //assume that we are going unless specified otherwise - var c = true; - - //increase the counter - n++; - - //if DOM methods are supported, and the body element exists - //(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1] - //in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section) - if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)) - { - //set the continue flag to false - //because other things being equal, we're not going to continue - c = false; - - //but ... if the arguments object is there - if(typeof a == 'object') - { - //iterate through the object - for(var i in a) - { - //if its value is "id" and the element with the given ID doesn't exist - //or its value is "tag" and the specified collection has no members - if - ( - (a[i] == 'id' && document.getElementById(i) == null) - || - (a[i] == 'tag' && document.getElementsByTagName(i).length < 1) - ) - { - //set the continue flag back to true - //because a specific element or collection doesn't exist - c = true; - - //no need to finish this loop - break; - } - } - } - - //if we're not continuing - //we can call the argument function and clear the timer - if(!c) { f(); clearInterval(t); } - } - - //if the timer has reached 60 (so timeout after 15 seconds) - //in practise, I've never seen this take longer than 7 iterations [in kde 3 - //in second place was IE6, which takes 2 or 3 iterations roughly 5% of the time] - if(n >= 60) - { - //clear the timer - clearInterval(t); - } - - }, 250); -}; - - -// Here are my functions for adding the DOMContentLoaded event to browsers other -// than Mozilla. - -// Array of DOMContentLoaded event handlers. -window.onDOMLoadEvents = new Array(); - -// Function that adds DOMContentLoaded listeners to the array. -function addDOMLoadEvent(listener) { - window.onDOMLoadEvents[window.onDOMLoadEvents.length]=listener; -} - -// Function to process the DOMContentLoaded events array. -function DOMContentLoadedInit() { - // quit if this function has already been called - if (arguments.callee.done) return; - - // flag this function so we don't do the same thing twice - arguments.callee.done = true; - - // iterates through array of registered functions - for (var i=0; i