thingspeak/public/assets/application.js

2 lines
60 KiB
JavaScript
Raw Normal View History

function reloadCharts(){return-1===navigator.userAgent.toLowerCase().indexOf("firefox")?!1:void $('.ui-widget-content [aria-expanded="false"]').find("iframe").each(function(){var e=$(this).attr("src");-1!==e.indexOf("charts")&&($(this).hide(),$(this).attr("src",e),$(this).show())})}function openDialogCenter(e){e.dialog("open");var t=getDimensions(e.parent());e.dialog({position:[t[0],t[1]]})}function getDimensions(e){var t=new Array(2);return t[0]=$(window).width()/2-e.width()/2,t[1]=$(window).height()/2-e.height()/2,t}function updateChart(e,t,n,r,i,a){var n=n,r=r,o=$("#iframe"+e).attr("default_src");o||(o=$("#iframe"+e).attr("src")),src=o.split("?")[0],("bar"===$("#type_"+e).val()||"column"===$("#type_"+e).val())&&0==$("#timescale_"+e).val().length&&0==$("#average_"+e).val().length&&0==$("#median_"+e).val().length&&0==$("#sum_"+e).val().length&&$("#timescale_"+e).val(30);var s=[];$(".chart_options"+e).each(function(){var e=$(this).val(),t=$(this).attr("id"),n=t.split("_")[0];e.length>0&&s.push([n,e])});for(var l="";s.length>0;){var u=s.pop();"width"==u[0]&&(n=parseInt(u[1])),"height"==u[0]&&(r=parseInt(u[1])),("type"!=u[0]||"line"!=u[1])&&(l+="&"+u[0]+"="+encodeURIComponent(u[1]))}l.length>0&&(src+="?"+l.substring(1)),t&&e>0&&a?$.update("/channels/"+i+"/charts/"+e,{newOptions:{options:l}}):t&&e>0&&$.update("/channels/"+i+"/charts/"+e,{options:l}),$("#embed"+e).val('<iframe width="'+n+'" height="'+r+'" style="border: 1px solid #cccccc;" src="'+src+'"></iframe>'),$("#iframe"+e).attr("src",src),$("#iframe"+e).attr("width",n),$("#iframe"+e).attr("height",r)}function updateSelectValues(){selectedValue=$(this).val(),$(".mutuallyexclusive"+index).each(function(){$(this).val("")}),$(this).val(selectedValue)}function setupChartForm(e){return function(t,n){n.length>0&&$("#"+n.split("=")[0]+"_"+e).val(decodeURIComponent(n.split("=")[1]))}}function setupColumns(e,t){$(sortColumnSetup(e,t)),$(".column").disableSelection()}function createWindowsWithData(e,t,n,r){for(var i in e){var a=e[i].window,o=a.window_type;colId=a.col,title=a.title;var s=a.html;"chart"===a.window_type&&$("body").append("<div id='chartConfig"+a.id+"'></div>");var l=addWindow(r,colId,a.id,o,title,s);l.each(decoratePortlet(t)),l.find(".ui-toggle").click(uiToggleClick),l.find(".ui-view").click(uiViewClick(n)),l.find(".ui-edit").click(uiEditClick(n)),l.find(".ui-close").click(uiCloseClick(n))}}function addWindow(e,t,n,r,i,a){if($("#"+e+"_dialog"+t).append('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" id="portlet_'+n+'"><div class="portlet-header window_type window_type-'+r+' ui-widget-header ui-corner-all">'+i+'</div><div class="portlet-content">'+a+"</div>"),$("#portlet_"+n).length>1)throw"Portlet count doesn't match what's expected";return $("#portlet_"+n)}function sortColumnSetup(e,t){$(".column").sortable({opacity:.6,helper:function(){return $("<div class='ui-widget-header'>Drop to re-position</div>")},connectWith:".column",update:updatePortletPositions(e,t)})}function getPortletArray(e){var t=new Array,n=e.split("&");for(i in n)val=n[i].split("=")[1],t.push(val);return t}function uiToggleClick(){$(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick"),$(this).parents(".portlet:first").find(".portlet-content").toggle()}!function(e,t){e.rails!==t&&e.error("jquery-ujs has already been loaded!");var n,r=e(document);e.rails=n={linkClickSelector:"a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]",buttonClickSelector:"button[data-remote]",inputChangeSelector:"select[data-remote], input[data-remote], textarea[data-remote]",formSubmitSelector:"form",formInputClickSelector:"form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])",disableSelector:"input[data-disable-with], button[data-disable-with], textarea[data-disable-with]",enableSelector:"input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled",requiredInputSelector:"input[name][required]:not([disabled]),textarea[name][required]:not([disabled])",file
2014-10-10 17:26:42 +02:00
}function makeSortText(e){return"((a["+e+"] < b["+e+"]) ? -1 : ((a["+e+"] > b["+e+"]) ? 1 : 0));"}function makeSortTextDesc(e){return"((b["+e+"] < a["+e+"]) ? -1 : ((b["+e+"] > a["+e+"]) ? 1 : 0));"}function makeSortNumeric(e){return"a["+e+"]-b["+e+"];"}function makeSortNumericDesc(e){return"b["+e+"]-a["+e+"];"}function sortText(e,t){return table.config.sortLocaleCompare?e.localeCompare(t):t>e?-1:e>t?1:0}function sortTextDesc(e,t){return table.config.sortLocaleCompare?t.localeCompare(e):e>t?-1:t>e?1:0}function sortNumeric(e,t){return e-t}function sortNumericDesc(e,t){return t-e}function getCachedSortType(e,t){return e[t].type}var parsers=[],widgets=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",cssChildRow:"expand-child",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,sortLocaleCompare:!0,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:!1,cancelSelection:!0,sortList:[],headerList:[],dateFormat:"us",decimal:"/.|,/g",onRenderHeader:null,selectorHeaders:"thead th",debug:!1},this.benchmark=benchmark,this.construct=function(e){return this.each(function(){if(this.tHead&&this.tBodies){var t,n,r,i;this.config={},i=$.extend(this.config,$.tablesorter.defaults,e),t=$(this),$.data(this,"tablesorter",i),n=buildHeaders(this),this.config.parsers=buildParserCache(this,n),r=buildCache(this);var a=[i.cssDesc,i.cssAsc];fixColumnWidth(this),n.click(function(e){var o=t[0].tBodies[0]&&t[0].tBodies[0].rows.length||0;if(!this.sortDisabled&&o>0){t.trigger("sortStart");var s=($(this),this.column);if(this.order=this.count++%2,this.lockedOrder&&(this.order=this.lockedOrder),e[i.sortMultiSortKey])if(isValueInArray(s,i.sortList))for(var l=0;l<i.sortList.length;l++){var u=i.sortList[l],c=i.headerList[u[0]];u[0]==s&&(c.count=u[1],c.count++,u[1]=c.count%2)}else i.sortList.push([s,this.order]);else{if(i.sortList=[],null!=i.sortForce)for(var d=i.sortForce,l=0;l<d.length;l++)d[l][0]!=s&&i.sortList.push(d[l]);i.sortList.push([s,this.order])}return setTimeout(function(){setHeadersCss(t[0],n,i.sortList,a),appendToTable(t[0],multisort(t[0],i.sortList,r))},1),!1}}).mousedown(function(){return i.cancelSelection?(this.onselectstart=function(){return!1},!1):void 0}),t.bind("update",function(){var e=this;setTimeout(function(){e.config.parsers=buildParserCache(e,n),r=buildCache(e)},1)}).bind("updateCell",function(e,t){var n=this.config,i=[t.parentNode.rowIndex-1,t.cellIndex];r.normalized[i[0]][i[1]]=n.parsers[i[1]].format(getElementText(n,t),t)}).bind("sorton",function(e,t){$(this).trigger("sortStart"),i.sortList=t;var o=i.sortList;updateHeaderSortCount(this,o),setHeadersCss(this,n,o,a),appendToTable(this,multisort(this,o,r))}).bind("appendCache",function(){appendToTable(this,r)}).bind("applyWidgetId",function(e,t){getWidgetById(t).format(this)}).bind("applyWidgets",function(){applyWidget(this)}),$.metadata&&$(this).metadata()&&$(this).metadata().sortlist&&(i.sortList=$(this).metadata().sortlist),i.sortList.length>0&&t.trigger("sorton",[i.sortList]),applyWidget(this)}})},this.addParser=function(e){for(var t=parsers.length,n=!0,r=0;t>r;r++)parsers[r].id.toLowerCase()==e.id.toLowerCase()&&(n=!1);n&&parsers.push(e)},this.addWidget=function(e){widgets.push(e)},this.formatFloat=function(e){var t=parseFloat(e);return isNaN(t)?0:t},this.formatInt=function(e){var t=parseInt(e);return isNaN(t)?0:t},this.isDigit=function(e){return/^[-+]?\d*$/.test($.trim(e.replace(/[,.']/g,"")))},this.clearTableBody=function(e){function t(){for(;this.firstChild;)this.removeChild(this.firstChild)}$.browser.msie?t.apply(e.tBodies[0]):e.tBodies[0].innerHTML=""}}}),$.fn.extend({tablesorter:$.tablesorter.construct});var ts=$.tablesorter;ts.addParser({id:"text",is:function(){return!0},format:function(e){return $.trim(e.toLocaleLowerCase())},type:"text"}),ts.addParser({id:"digit",is:function(e,t){var n=t.config;return $.tablesorter.isDigit(e,n)},format:function(e){return $.tablesorter.formatFloat(e)},type:"numeric"}),ts.addParser({id:"currency",is:function(e){return/^[\xc2\xa3