Index: lams_central/web/includes/javascript/pedagogicalPlanner.js =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/javascript/pedagogicalPlanner.js,v diff -u -r1.22 -r1.23 --- lams_central/web/includes/javascript/pedagogicalPlanner.js 5 Dec 2010 19:44:27 -0000 1.22 +++ lams_central/web/includes/javascript/pedagogicalPlanner.js 12 Dec 2010 14:17:12 -0000 1.23 @@ -7,13 +7,17 @@ var actionAfterCompleted; //What action should be called if all activities were saved successfully var startPreviewUrl; //Url to start preview var learningDesignId; //ID of the design to open + var initialActivityHeight = null; + var activityMetadataFields = [ 'Collapsed', 'Expanded', 'Hidden' ]; + var initialExpandAttempts = []; var ACTION_SAVE_AS_SEQUENCE = 0; //After successful submit save learning design in user's personal folder var ACTION_PREVIEW = 1; //After successful submit start preview var ACTION_OPEN_AUTHOR = 2; //After successful submit open full authoring var ACTION_EXPORT = 3; //After successful submit export the learning design var END_HEAD_REGEX_PATTERN = new RegExp('activityCallRetrievedID){ //clear old data @@ -118,8 +137,8 @@ } // reeavaluate script initializing the CKEditor instance - if (activity.contentWindow.initializeCKEditor){ - activity.contentWindow.initializeCKEditor(); + if (activity.contentWindow.reinitializeCKEditorInstances){ + activity.contentWindow.reinitializeCKEditorInstances(); } } } @@ -235,16 +254,36 @@ $('#activity'+id).hide('slow', function () { $('#activity'+action+'Span'+id).show('slow'); }); + $('#activityCollapsed'+id).val('true'); } - function expandActivity(id, action){ + function uncollapseActivity(id, action){ $('#activity'+action+'Span'+id).hide('slow', function () { $('#activity'+id).show('slow', function (){ $('.collapsible'+id).show(); }); }); + $('#activityCollapsed'+id).val('false'); } + + + function expandActivity(id){ + var activity = $('#activity'+id); + var currentHeight = activity.height(); + var targetHeight = activity[0].contentDocument.height; + var expanded = 'true'; + if (initialActivityHeight == null){ + initialActivityHeight = currentHeight; + } else if (initialActivityHeight != currentHeight) { + targetHeight = initialActivityHeight; + expanded = 'false'; + } + + $('#activityExpanded'+id).val(expanded); + activity.height(targetHeight); + } + function openActivityAuthor(id, url, title) { collapseActivity(id, 'Edit'); @@ -253,11 +292,34 @@ if (wd.closed) { clearTimeout(watchClose); $('#activity'+id)[0].contentWindow.location.reload(true); - expandActivity(id, 'Edit'); + uncollapseActivity(id, 'Edit'); } }, 500); if (window.focus) { wd.window.focus(); } - } \ No newline at end of file + } + + function initialDelayedExpand(id){ + initialExpandAttempts[id] = 0; + + /* we can not just expand it as soon as document is loaded + CKEditor is loaded asynchronously and stretches the iframe afterwards + Below is one (not the best) solution - periodically check if iframe grew: + if yes, adjust the hieght; if no, eventually stop */ + + var watchLoaded = setInterval(function() { + var activity = $('#activity'+id); + var currentHeight = activity.height(); + var targetHeight = activity[0].contentDocument.height; + if (targetHeight > currentHeight) { + initialExpandAttempts[id] = 0; + expandActivity(id); + } else if (initialExpandAttempts[id] > INITIAL_EXPAND_MAX_ATTEMPTS){ + clearTimeout(watchLoaded); + } else { + initialExpandAttempts[id] += 1; + } + }, 2000); + } \ No newline at end of file