UNPKG

bootstrap-help-manager

Version:

Plugin and management console to create and manage help icons and content across an entire site.

5 lines 2.85 kB
/** * Bootstrap-Help-Manager v 0.5.2 * https://github.com/psalmody/Bootstrap-Help-Manager */ var BHM=function(Vertebrate,$,my){return my.helper=Vertebrate.Model.Extend({attributes:{id:-1,field_selecter:"",title:"",large:!1,html:"",page_ids:""}}),my.page=Vertebrate.Model.Extend({attributes:{id:-1,url:""}}),my.helpers=Vertebrate.Collection.Extend({model:my.helper}),my.pages=Vertebrate.Collection.Extend({model:my.page}),my.cp=new my.pages,my.ch=new my.helpers,my}(Vertebrate,jQuery,BHM||{}),BHM=function(my){var cache={};return my.tmpl=function tmpl(str,data){var fn=/\W/.test(str)?new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+str.replace(/[\r\t\n]/g," ").split("<%").join(" ").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split(" ").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');"):cache[str]=cache[str]||tmpl(document.getElementById(str).innerHTML);return data?fn(data):fn},my}(BHM||{}),BHM=function(Vertebrate,$,my){return my.ch=BHM.ch||{},my.ch.render=function(){var coll=this;$.each(coll.models,function(){var a=this.get(),el=$(a.field_selecter),tag=el.prop("tagName"),inputgroup=$("<div></div>",{"class":"input-group"});switch(tag){case"BUTTON":var btngroup=$("<div></div>",{"class":"btn-group"});el.wrap(btngroup),el.closest(".btn-group").append(BHM.tmpl($("#templateBHMButtonGroup").html(),{id:a.id})),el.hasClass("btn-block")&&el.removeClass("btn-block");break;case"INPUT":el.wrap(inputgroup),el.closest(".input-group").append(BHM.tmpl($("#templateBHMInputGroup").html(),{id:a.id}));break;case"SELECT":el.wrap(inputgroup),el.after(BHM.tmpl($("#templateBHMInputGroup").html(),{id:a.id}));break;case"TEXTAREA":el.closest(".form-group").find("label").length?el.closest(".form-group").find("label").append(BHM.tmpl($("#templateBHMHelper").html(),{id:a.id})):el.closest(".form-group").prepend(BHM.tmpl($("#templateBHMHelper").html(),{id:a.id}));break;default:el.append(BHM.tmpl($("#templateBHMHelper").html(),{id:a.id}))}})},my}(Vertebrate,jQuery,BHM||{});!function($,BHM){$.fn.BHMClient=function(options){this.settings=$.extend({},{templateurl:"",helpersurl:"",pagesurl:"",indexpage:""},options),BHM.ch.url=this.settings.clienturl,BHM.ch.set("pathname",window.location.pathname),BHM.ch.set("indexpage",this.settings.indexpage);var self=this;window.location.pathname;BHM.ch.fetch(function(){$.get(self.settings.templateurl,function(data){$("body").append(data),BHM.ch.render()})}),$("body").on("click",".bhm-helper",function(){var id=$(this).data("bhm-helper"),help=BHM.ch.find(id,"id"),islarge="1"==help.get("large")?"modal-lg":"",modal=$(BHM.tmpl($("#templatebhmEditHtmlModal").html(),{title:help.get("title"),html:help.get("html"),large:islarge}));modal.modal().on("hidden.bs.modal",function(){modal.remove()})})}}(jQuery,BHM);