/*
Title: hideTopCancelSave.js
Description: Hides the top toolbar (a duplicate of the buttom toolbar) found on form web pages
Assumptions:
(1) All toolbars reside in either a "ms-formtoolbar" class or "ms-toolbar" class element
(2) The first occurrence of the the toolbar and the last occurence of it in the page, have identical input values
(3) The toolbar, denotes with one of the aforementioned classes can be styles with "display:none"
*/
$(document).ready(function() {
var toolBars; // all toolbars in document
var toolBar1_inputs; //represents the first toolbar DOM element found
var toolBar2_inputs; //represents the last toolbar DOM element found
var lastToolBarIndex; //represents the index number of the last tool bar found
/*get all form toolbars
*/
// get toolbars with class .ms-formtoolbar
toolBars = document.querySelectorAll(".ms-formtoolbar");
// if no toolBars with class .ms-formtoolbar, get toolBars with class .ms-toolbar
if ( toolBars == null || toolBars.length == 0)
toolBars = document.querySelectorAll(".ms-toolbar");
//get the index number of the last toolbar in the document
lastToolBarIndex = toolBars.length-1;
//if there is more than one tool bar, make sure the last one isnt hidden, then hide the first one
// do this if there is only 2 toolBars or if there are more than 2
if (toolBars != null && toolBars.length >= 2 && toolBars[lastToolBarIndex ].style.display != "none"){
/* check to make sure the first toolbar contains the exact same titled input buttons as the bottom toolbar
*/
//start by getting all inputs for first and last toolbars
toolBar1_inputs = toolBars[0].querySelectorAll(".ms-formtoolbar input");
toolBar2_inputs = toolBars[ lastToolBarIndex ].querySelectorAll(".ms-formtoolbar input");
//make sure the toolbars contain the same number of inputs
if ( toolBar1_inputs.length == toolBar2_inputs.length ) {
// make sure each input in the first toolBar corresponds with those in the bottm toolBar
for ( var i=0; i < toolBar1_inputs.length; i++ )
if( toolBar1_inputs[i].value != toolBar2_inputs[i].value )
return;
}
else
return;
} // end if ( toolBars != null && toolBars.length == 2 && toolBars[1].hidden == false ) ....
else
return;
// set first toolbar not to display
toolBars[0].style.display = "none";
}); // end $(document).ready(function()