Code Sample: Show, Hide and Modify Panels on Views


/**
       [CREATED BY] William Kreider | madhatt30
       [LANG CAT'S] JQuery, Javascript

       This function will get all of the div tags and create a key:value pair in the style of 
	PHP with the selctor for the dictionary being either id, name or h4. Which means you can
	modify the Panels by either of the selectors.
*/
var elems;
var divKeyPairs = {};
var view = "DetailView";

function getPanelArrays() {
	var panelID = "";
	var panelName = "";
	var panelH4Text = "";
	var loc;
	
	elems = document.getElementsByTagName("div");
	
	for (var i = 0, n = elems.length; i < n; ++i) {
		panelID = elems[i].id;
		if (panelID.toString().substr(0, 12) == "detailpanel_") {
			panelName = panelID.toString();
			panelH4Text = String($("#" + panelName).find("h4").text());
			loc = panelH4Text.search("document.getElementById");
			// Grab only the text and nothing else
			panelH4Text = panelH4Text.substr(0, loc);
			// Trim the whitespace
			panelH4Text = panelH4Text.trim();
			divKeyPairs[panelH4Text] = {"id":panelID, "name":panelName, "h4":panelH4Text};
		}	
	}
}

You are free to use this code if you find it useful. Enjoy!

2 Likes