1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
|
|
(function($,window,document,undefined){var pluginName="jarvisWidgets";function Plugin(element,options){this.obj=$(element);this.o=$.extend({},$.fn[pluginName].defaults,options);this.objId=this.obj.attr("id");this.pwCtrls=".jarviswidget-ctrls";this.widget=this.obj.find(this.o.widgets);this.toggleClass=this.o.toggleClass.split("|");this.editClass=this.o.editClass.split("|");this.fullscreenClass=this.o.fullscreenClass.split("|");this.customClass=this.o.customClass.split("|");this.init()}Plugin.prototype={_settings:function(){var self=this;storage=!!function(){var result,uid=+new Date;try{localStorage.setItem(uid,uid);result=localStorage.getItem(uid)==uid;localStorage.removeItem(uid);return result}catch(e){}}()&&localStorage;if(storage&&self.o.localStorage){if(self.o.ajaxnav===true){widget_url=location.hash.replace(/^#/,"");keySettings="Plugin_settings_"+widget_url+"_"+self.objId;getKeySettings=localStorage.getItem(keySettings);keyPosition="Plugin_position_"+widget_url+"_"+self.objId;getKeyPosition=localStorage.getItem(keyPosition)}else{keySettings="jarvisWidgets_settings_"+location.pathname+"_"+self.objId;getKeySettings=localStorage.getItem(keySettings);keyPosition="jarvisWidgets_position_"+location.pathname+"_"+self.objId;getKeyPosition=localStorage.getItem(keyPosition)}}if(("ontouchstart" in window)||window.DocumentTouch&&document instanceof DocumentTouch){clickEvent="touchstart"}else{clickEvent="click"}},_runLoaderWidget:function(elm){var self=this;if(self.o.indicator===true){elm.parents(self.o.widgets).find(".jarviswidget-loader").stop(true,true).fadeIn(100).delay(self.o.indicatorTime).fadeOut(100)}},_getPastTimestamp:function(t){var self=this;var da=new Date(t);tsMonth=da.getMonth()+1;tsDay=da.getDate();tsYear=da.getFullYear();tsHours=da.getHours();tsMinutes=da.getMinutes();tsSeconds=da.getUTCSeconds();if(tsMonth<10){var tsMonth="0"+tsMonth}if(tsDay<10){var tsDay="0"+tsDay}if(tsHours<10){var tsHours="0"+tsHours}if(tsMinutes<10){var tsMinutes="0"+tsMinutes}if(tsSeconds<10){var tsSeconds="0"+tsSeconds}var format=self.o.timestampFormat.replace(/%d%/g,tsDay).replace(/%m%/g,tsMonth).replace(/%y%/g,tsYear).replace(/%h%/g,tsHours).replace(/%i%/g,tsMinutes).replace(/%s%/g,tsSeconds);return format},_loadAjaxFile:function(awidget,file,loader){var self=this;awidget.find(".widget-body").load(file,function(response,status,xhr){var $this=$(this);if(status=="error"){$this.html('<h4 class="alert alert-danger">'+self.o.labelError+"<b> "+xhr.status+" "+xhr.statusText+"</b></h4>")}if(status=="success"){var aPalceholder=awidget.find(self.o.timestampPlaceholder);if(aPalceholder.length){aPalceholder.html(self._getPastTimestamp(new Date()))}if(typeof self.o.afterLoad=="function"){self.o.afterLoad.call(this,awidget)}}});self._runLoaderWidget(loader)},_saveSettingsWidget:function(){var self=this;self._settings();if(storage&&self.o.localStorage){var storeSettings=[];self.obj.find(self.o.widgets).each(function(){var storeSettingsStr={};storeSettingsStr.id=$(this).attr("id");storeSettingsStr.style=$(this).attr("data-widget-attstyle");storeSettingsStr.title=$(this).children("header").children("h2").text();storeSettingsStr.hidden=($(this).is(":hidden")?1:0);storeSettingsStr.collapsed=($(this).hasClass("jarviswidget-collapsed")?1:0);storeSettings.push(storeSettingsStr)});var storeSettingsObj=JSON.stringify({widget:storeSettings});if(getKeySettings!=storeSettingsObj){localStorage.setItem(keySettings,storeSettingsObj)}}if(typeof self.o.onSave=="function"){self.o.onSave.call(this,null,storeSettingsObj)}},_savePositionWidget:function(){var self=this;self._settings();if(storage&&self.o.localStorage){var mainArr=[];self.obj.find(self.o.grid+".sortable-grid").each(function(){var subArr=[];$(this).children(self.o.widgets).each(function(){var subObj={};subObj.id=$(this).attr("id");subArr.push(subObj)});var out={section:subArr};mainArr.push(out)});var storePositionObj=JSON.stringify({grid:mainArr});if(getKeyPosition!=storePositionObj){localStorage.setItem(keyPosition,storePositionObj,null)}}if(typeof self.o.onSave=="function"){self.o.onSave.call(this,stor
|