joomla_test/modules/mod_roktabs/admin/icons.js

24 lines
4.1 KiB
JavaScript
Raw Permalink Normal View History

2020-01-02 22:20:31 +07:00
var RokTabsIcons=new Class({Implements:[Options,Events],initialize:function(){this.Path=SitePath+"/";this.selects=$$(".icons select");this.pathEl=document.id("jform_params_tabs_iconpath");
if(this.pathEl){this.pathEl.addEvent("keyup",function(){this.Path=SitePath+"/"+this.pathEl.value;this.Path=this.Path.replace("__template__",TemplatePath);
this.Path=this.Path.replace("__module__",ModulePath);if(this.Path[this.Path.length-1]!="/"){this.Path+="/";}}.bind(this));this.Path=SitePath+"/"+this.pathEl.value;
this.Path=this.Path.replace("__template__",TemplatePath);this.Path=this.Path.replace("__module__",ModulePath);if(this.Path[this.Path.length-1]!="/"){this.Path+="/";
}}this.selects.each(function(b){this.selectEvent(b,this);},this);this.adds=$$(".icons .controls .add");this.removes=$$(".icons .controls .remove");var a=this;
this.adds.each(function(b){b.addEvent("click",function(){a.add(this);});});this.removes.each(function(b){b.addEvent("click",function(){a.remove(this);});
});},selectEvent:function(a,c){var e=a.options[a.selectedIndex].value;var f=a.getPrevious();var d=this;if(f.getElement("img")){f.getElement("img").src=c.Path+e;
}else{new Asset.image(c.Path+e).inject(f);}if(e=="__none__"){f.getElement("img").setStyle("display","none");}else{f.getElement("img").setStyle("display","block");
}a.getElements("option").addEvents({mouseenter:function(){if(this.value=="__none__"){f.getElement("img").setStyle("display","none");}else{f.getElement("img").setStyle("display","block");
}f.getElement("img").src=c.Path+this.value;},mouseleave:function(){if(this.value=="__none__"){f.getElement("img").setStyle("display","none");}else{f.getElement("img").setStyle("display","block");
}f.getElement("img").src=c.Path+e;}});a.addEvent("change",function(){e=a.options[a.selectedIndex].value;if(e=="__none__"){f.getElement("img").setStyle("display","none");
}else{f.getElement("img").setStyle("display","block");}f.getElement("img").src=c.Path+e;var g=[];d.selects.each(function(h){g.push(h.value);});document.id("jform_params_tabs_icon").value=g.join(",");
});if(typeof jQuery!="undefiend"&&typeof jQuery.fn.chosen!="undefined"){jQuery(a).chosen().change(function(){e=a.options[a.selectedIndex].value;if(e=="__none__"){f.getElement("img").setStyle("display","none");
}else{f.getElement("img").setStyle("display","block");}f.getElement("img").src=c.Path+e;var g=[];d.selects.each(function(h){g.push(h.value);});document.id("jform_params_tabs_icon").value=g.join(",");
});var b=a.getNext(".chzn-container").getElements(".chzn-results li");if(b&&b.length){b.addEvents({mouseenter:function(){var g=this.getParent("ul").getElements("li").indexOf(this),h=a.getElements("option")[g].value;
if(h=="__none__"){f.getElement("img").setStyle("display","none");}else{f.getElement("img").setStyle("display","block");}f.getElement("img").src=c.Path+h;
},mouseleave:function(){var g=this.getParent("ul").getElements("li").indexOf(this),h=a.getElements("option")[g].value;if(h=="__none__"){f.getElement("img").setStyle("display","none");
}else{f.getElement("img").setStyle("display","block");}f.getElement("img").src=c.Path+e;}});}}},add:function(c){var d=c.getParent().getParent();var f=d.clone(true).inject(d,"after");
var b=f.getElement("select");var e=f.getElement(".add");var a=f.getElement(".remove").setStyle("display","block");e.addEvent("click",function(){this.add(e);
}.bind(this));a.addEvent("click",function(){this.remove(a);}.bind(this));this.selectEvent(b,this);this.rearrange();},remove:function(a){var b=a.getParent().getParent();
b.empty().dispose();this.rearrange();},rearrange:function(){this.removes=$$(".icons .controls .add");this.adds=$$(".icons .controls .remove");this.selects=$$(".icons select");
var a=[];this.selects.each(function(b,d){var e=b.getPrevious();var c=e.getPrevious();e.className="preview_tabs_icon"+(d+1)+" icons_previews";c.set("html","Tab "+(d+1)+": ");
a.push(b.value);});if(this.selects.length==1){this.selects[0].getNext(".controls").getElement(".remove").setStyle("display","none");}else{this.selects[0].getNext(".controls").getElement(".remove").setStyle("display","block");
}document.id("jform_params_tabs_icon").value=a.join(",");}});