Skip to content

Instantly share code, notes, and snippets.

@Danny-Engelman
Last active February 18, 2018 09:34
Show Gist options
  • Save Danny-Engelman/7c0047e93e8b8b9096257711576e5dbc to your computer and use it in GitHub Desktop.
Save Danny-Engelman/7c0047e93e8b8b9096257711576e5dbc to your computer and use it in GitHub Desktop.
SharePoint DIV manager manages show/hide/style for [selector] DIVs
console.clear();
function DIVManager( selector , numbers){
var manager=this;
function DIV(element){
var div=this;
div.state=element.style.display!=='none';
div.style=function(key,value){
console.log(key,value);
element.style[key]=value;
div.state=element.style.display!=='none';
}
div.show = div.style.bind(this,'display','block')
div.hide = div.style.bind(this,'display','none')
div.toggle=function(){
div.state ? div.hide() : div.show();
div.state=!div.state;
}
}
manager.divs=[];
manager.numbers=[];
document.querySelectorAll(selector).forEach(function(element,nr){
manager.numbers.push(nr);
manager.divs.push(new DIV(element));
});
function action (){
var args = Array.prototype.slice.call(arguments);
if(args.lenght===1)args=manager.numbers;
console.log(arguments.length,args);
manager.divs.forEach(function(element,nr){
console.log(nr,element);
if(args.indexOf(nr)>-1) element[args[0]]();
});
}
manager.show=action.bind(this,'show');
manager.hide=action.bind(this,'hide');
manager.toggle=action.bind(this,'toggle');
}
var wpM=new DIVManager("div[webpartid]");
wpM.hide(1,3,5);
wpM.toggle(1);
var searchBox=wpM.divs[0];
searchBox.style('zoom',3);
searchBox.style('backgroundColor','pink');
searchBox.style('opacity',.7);
var rotation=0;
window.setInterval(function(){
searchBox.style( 'transform',String.format("rotate({0}deg)",rotation++ ));
}, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment