We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21872
    • 95 Posts
    I need a way for a script to know for certain that all other scripts in the Resource Editor view have finished before it runs.

    After creating a new resource with a rich text area TV, I opened the Edit Resource view in a new tab and tested the code below in Firebug. It worked fine.
    var row = jQuery('.mceEditor', document.getElementById('tmplvars')).parents('tr'),
    	rowH = row.children('td').eq(0).text().trim(),
    	rowC = row.children('td').eq(1).html();
    jQuery('.mceEditor', document.getElementById('tmplvars')).parents('tr').remove();
    jQuery('#tmplvars').prev('.sectionHeader').before('<div class="sectionHeader">\n<h2>'+rowH+'</h2>\n</div><div class="sectionBody">\n'+rowC+'</div>');


    But when I try adding it into managerManager’s output, or into the mutate_content.dynamic.php view, it fails and creates a new section head with no label and a new section body with ’null’ as the content. Furthermore, the row containing the rich text editor remains in place, all of which suggests the script is executing before the page has finished loading. Adding the javascript to the bottom of the page so that it appears just before the footer in the generated markup and waiting for the document load event to fire doesn’t make any difference.

    The code above looks for a second rich text editor occurring within the Template Variables section and if it finds it grabs the caption as text and the editor markup, removes the row from the table, and inserts a new section between Resource Content and Template Variables. (if you want to try execute: jQuery(’.sectionBody .tmplvars’).attr(’id’,’tmplvars’); in Firebug, then execute the code above.)


    updated: I found a less than satisfying solution. Also, I realize this should probably be posted elsewhere; now it should probably just be deleted.

    The solution isn’t very satisfying, but modifying managerManager’s cleanup to include a short delay followed by an anonymous callback function that contains the code below, and then hiding the loadingmask element seems to do the trick. In other words, in mm.inc.php I added this code around line 407:

    		// Whatever happens, hide the loading mask
    		$j("#loadingmask").animate({fakeproperty: 1}, 10, function(){
    			var row = jQuery(".mceEditor", document.getElementById("tmplvars")).parents("tr"),
    				rowH = row.children("td").eq(0).text().trim(),
    				rowC = row.children("td").eq(1).html();
    				jQuery(".mceEditor", document.getElementById("tmplvars")).parents("tr").remove();
    				jQuery("#tmplvars").prev(".sectionHeader").before("<div class=\"sectionHeader\">\n<h2>"+rowH+"</h2>\n</div><div class=\"sectionBody\">\n"+rowC+"</div>");
    		}).hide();
    	}