t===e.name)&&a.push(e.name)})})}),_.each(a,function(e){n.processCalculatedSetting(e)})}},this.callValueFunction=function(t){return t.call(void 0,e.datasourceData)},this.processSizeChange=function(){!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.onSizeChanged)&&n.widgetInstance.onSizeChanged()},this.processCalculatedSetting=function(e){if(_.isFunction(n.calculatedSettingScripts[e])){var t=void 0;try{t=n.callValueFunction(n.calculatedSettingScripts[e])}catch(a){var i=n.settings()[e];a instanceof ReferenceError&&/^\w+$/.test(i)&&(t=i)}if(!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.onCalculatedValueChanged)&&!_.isUndefined(t))try{n.widgetInstance.onCalculatedValueChanged(e,t)}catch(e){console.log(e.toString())}}},this.updateCalculatedSettings=function(){if(n.datasourceRefreshNotifications={},n.calculatedSettingScripts={},!_.isUndefined(n.type())){var e=t[n.type()].settings,i=new RegExp('datasources\\[\\"(\\w+)\\"\\](\\[\\"[\\"\\]\\[\\w\\.\\/]+\\"])?',"g"),a=n.settings();_.each(e,function(e){if("calculated"==e.type){var t=a[e.name];if(!_.isUndefined(t)){var s,o;_.isArray(t)&&(t="["+t.join(",")+"]"),(t.match(/;/g)||[]).length<=1&&-1==t.indexOf("return")&&(t="return "+t);try{s=new Function("datasources",t)}catch(t){var r=a[e.name].replace(/"/g,'\\"').replace(/[\r\n]/g," \\\n");s=new Function("datasources",'return "'+r+'";')}for(n.calculatedSettingScripts[e.name]=s,n.processCalculatedSetting(e.name);o=i.exec(t);){var d=o[1],l=n.datasourceRefreshNotifications[d];_.isUndefined(l)&&(l=[{name:e.name,value:[]}],n.datasourceRefreshNotifications[d]=l);var c=l.find(t=>t.name===e.name);_.isUndefined(c)&&(c={name:e.name,value:[]},l.push(c)),_.isUndefined(o[2])&&(o[2]=""),c.value.push(o[2])}}}})}},this._heightUpdate=ko.observable(),this.height=ko.computed({read:function(){return n._heightUpdate(),!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.getHeight)?n.widgetInstance.getHeight():1}}),this.shouldRender=ko.observable(!1),this.render=function(e){n.shouldRender(!1),!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.render)&&(n.widgetInstance.render(e),n.updateCalculatedSettings())},this.dispose=function(){!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.onDispose)&&n.widgetInstance.onDispose()},this.serialize=function(){return{title:n.title(),type:n.type(),settings:n.settings()}},this.deserialize=function(e){n.title(e.title),n.settings(e.settings),n.type(e.type)}}DatasourceModel=function(e,t){var n=this;function i(){_.isUndefined(n.datasourceInstance)||(_.isFunction(n.datasourceInstance.onDispose)&&n.datasourceInstance.onDispose(),n.datasourceInstance=void 0)}this.name=ko.observable(),this.latestData=ko.observable({}),this.settings=ko.observable({}),this.settings.subscribe(function(e){!_.isUndefined(n.datasourceInstance)&&_.isFunction(n.datasourceInstance.onSettingsChanged)&&n.datasourceInstance.onSettingsChanged(e)}),this.updateCallback=function(t){e.processDatasourceUpdate(n,t),Object.assign(n.latestData(),t);var i=new Date;n.last_updated(i.toLocaleTimeString(void 0,{hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3}))},this.type=ko.observable(),this.type.subscribe(function(e){if(i(),e in t&&_.isFunction(t[e].newInstance)){var a=t[e];function s(){a.newInstance(n.settings(),function(e){n.datasourceInstance=e,e.updateNow()},n.updateCallback)}a.external_scripts&&a.external_scripts.length>0?head.js(a.external_scripts.slice(0),s):s()}}),this.last_updated=ko.observable("never"),this.last_error=ko.observable(),this.serialize=function(){return{name:n.name(),type:n.type(),settings:n.settings()}},this.deserialize=function(e){n.settings(e.settings),n.name(e.name),n.type(e.type)},this.getDataRepresentation=function(e){return new Function("data","try { return "+e+"} catch (e) { return undefined };").call(void 0,n.latestData())},this.updateNow=function(){!_.isUndefined(n.datasourceInstance)&&_.isFunction(n.datasourceInstance.updateNow)&&n.datasourceInstance.updateNow()},this.dispose=function(){i()}},DeveloperConsole=function(e){return{showDeveloperConsole:function(){!function(){var t=[],n=$("
"),i=$('ADD
'),a=$('');a.append($('Plugin Script URL '));var s=$(" ");function o(e){var n=$(" "),i=$(''),a=$(' '),o=$(' ').click(function(e){t=_.without(t,a),n.remove()});t.push(a),e&&a.val(e),i.append(o),s.append(n.append($(" ").append(a)).append($('').append(i)))}a.append(s),n.append($("Here you can add references to other scripts to load datasource or widget plugins.
")).append(a).append(i).append('To learn how to build plugins for freeboard, please visit http://freeboard.github.io/freeboard/docs/plugin_example.html
'),_.each(e.plugins(),function(e){o(e)}),i.click(function(e){o()}),new DialogBox(n,"Developer Console","OK",null,function(){_.each(e.plugins(),function(e){$('script[src^="'+e+'"]').remove()}),e.plugins.removeAll(),_.each(t,function(t){var n=t.val();n&&n.length>0&&(e.addPluginSource(n),head.js(n+"?"+Date.now()))})})}()}}},JSEditor=function(){function e(e){e}return{displayJSEditor:function(e,t){!function(e,t){var n='// Example: Convert temp from C to F and truncate to 2 decimal places.\n// return (datasources["MyDatasource"].sensor.tempInF * 1.8 + 32).toFixed(2);';e||(e=n);var i=$('
'),a=$('
'),s=$(''),o=$('');i.append([o,a,s]),$("body").append(i);var r=CodeMirror(a.get(0),{value:e,mode:"javascript",theme:"ambiance",indentUnit:4,lineNumbers:!0,matchBrackets:!0,autoCloseBrackets:!0}),d=$('Close ').click(function(){if(t){var e=r.getValue();e===n&&(e=""),t(e),i.remove()}});s.append(d)}(e,t)},setAssetRoot:function(t){e(t)}}},PluginEditor=function(e,t){function n(e,t){var n=$('
').html(t);$("#setting-value-container-"+e).append(n)}function i(n,i,a,s,o){var r=$("");a.multi_input?r.change(function(){var e=[];$(n).find("textarea").each(function(){var t=$(this).val();t&&(e=e.concat(t))}),i.settings[a.name]=e}):r.change(function(){i.settings[a.name]=$(this).val()}),s&&r.val(s),t.createValueEditor(r);var d=$(''),l=$('
');l.append(r).append(d);var c=$('DATASOURCE ').mousedown(function(e){e.preventDefault(),$(r).val("").focus().insertAtCaret('datasources["').trigger("freeboard-eval")});d.append(c);var u=$('.JS EDITOR ').mousedown(function(t){t.preventDefault(),e.displayJSEditor(r.val(),function(e){r.val(e),r.change()})});if(d.append(u),o){var p=$(' ').mousedown(function(e){e.preventDefault(),l.remove(),$(n).find("textarea:first").change()});d.prepend(p)}$(n).append(l)}function a(e,t,a,s,o){var r,d={type:a,settings:{}};function l(e,t){var n=$('
').appendTo(c);return n.append(''+t+"
"),$('
').appendTo(n)}var c=$("
"),u=$('
').hide();function p(e,t,n){_.each(e,function(e){!_.isUndefined(e.default_value)&&_.isUndefined(s[e.name])&&(s[e.name]=e.default_value);var a=e.name;_.isUndefined(e.display_name)||(a=e.display_name);var o=l(e.name,a);switch(e.type){case"array":{var r=$('
').appendTo(o),c=$('').appendTo(r),u=$(" ").hide().appendTo(c),p=$(" ").appendTo(u),f=$(" ").appendTo(c),h=[];function g(){d.settings[e.name].length>0?u.show():u.hide()}function m(t){var n=$(" ").appendTo(f),i={};_.isArray(d.settings[e.name])||(d.settings[e.name]=[]),d.settings[e.name].push(i),_.each(e.settings,function(e){var a=$(" ").appendTo(n),s="";_.isUndefined(t[e.name])||(s=t[e.name]),i[e.name]=s,$(' ').appendTo(a).val(s).change(function(){i[e.name]=$(this).val()})}),n.append($(' ').append($('').append($(" ").append($(' ').click(function(){var t=d.settings[e.name].indexOf(i);-1!=t&&(d.settings[e.name].splice(t,1),n.remove(),g())}))))),r.scrollTop(r[0].scrollHeight),g()}_.each(e.settings,function(e){var t=e.name;_.isUndefined(e.display_name)||(t=e.display_name),$(""+t+" ").appendTo(p)}),e.name in s&&(h=s[e.name]),$('ADD
').appendTo(o).click(function(){var t={};_.each(e.settings,function(e){t[e.name]=""}),m(t)}),_.each(h,function(e,t){m(e)});break}case"boolean":d.settings[e.name]=s[e.name];var v=$('').appendTo(o),y=$(' ').prependTo(v).change(function(){d.settings[e.name]=this.checked});e.name in s&&y.prop("checked",s[e.name]);break;case"option":var w=s[e.name];y=$(" ").appendTo($('
').appendTo(o)).change(function(){d.settings[e.name]=$(this).val()});_.each(e.options,function(e){var t,n;_.isObject(e)?(t=e.name,n=e.value):t=e,_.isUndefined(n)&&(n=t),_.isUndefined(w)&&(w=n),$(" ").text(t).attr("value",n).appendTo(y)}),d.settings[e.name]=w,e.name in s&&y.val(s[e.name]);break;default:if(d.settings[e.name]=s[e.name],"calculated"==e.type){if(e.name in s){var b=s[e.name];if(e.multi_input&&_.isArray(b))for(var x=!1,C=0;CADD ').mousedown(function(t){t.preventDefault(),i(o,d,e,null,!0)});$(o).siblings(".form-label").append(S)}}else{y=$(' ').appendTo(o).change(function(){"number"==e.type?d.settings[e.name]=Number($(this).val()):d.settings[e.name]=$(this).val()});if(e.name in s&&y.val(s[e.name]),t&&e.typeahead_data_field&&y.addClass("typeahead_data_field-"+e.typeahead_data_field),t&&e.typeahead_field){var k=[];y.keyup(function(e){e.which>=65&&e.which<=91&&y.trigger("change")}),$(y).autocomplete({source:k,select:function(e,t){y.val(t.item.value),y.trigger("change")}}),y.change(function(i){var a=y.val(),s=_.template(t)({input:a});$.get(s,function(t){if(n&&(t=t[n]),t=_.select(t,function(t){return t[e.typeahead_field][0]==a[0]}),k=_.map(t,function(t){return t[e.typeahead_field]}),$(y).autocomplete("option","source",k),1==t.length)for(var i in t=t[0])if(t.hasOwnProperty(i)){var s=$(_.template("input.typeahead_data_field-<%= field %>")({field:i}));s&&(s.val(t[i]),s.val()!=y.val()&&s.trigger("change"))}})})}}}_.isUndefined(e.suffix)||o.append($(''+e.suffix+"
")),_.isUndefined(e.description)||o.append($(''+e.description+"
"))})}c.append(u),new DialogBox(c,e,"Save","Cancel",function(){$(".validation-error").remove();for(var e=0;e0)return n(t.name,i),!0}}var a;_.isFunction(o)&&o(d)});var f,h=_.keys(t);if(h.length>1){var g=l("plugin-types","Type");(f=$(" ").appendTo($('
').appendTo(g))).append($("Select a type... ").attr("value","undefined")),_.each(t,function(e){f.append($(" ").text(e.display_name).attr("value",e.type_name))}),f.change(function(){d.type=$(this).val(),d.settings={},$("#setting-row-instance-name").length?$("#setting-row-instance-name").nextAll().remove():$("#setting-row-plugin-types").nextAll().remove(),r=t[f.val()],_.isUndefined(r)?($("#setting-row-instance-name").hide(),$("#dialog-ok").hide()):($("#setting-row-instance-name").show(),r.description&&r.description.length>0?u.html(r.description).show():u.hide(),$("#dialog-ok").show(),p(r.settings,r.typeahead_source,r.typeahead_data_segment))})}else 1==h.length&&(r=t[h[0]],d.type=r.type_name,d.settings={},p(r.settings));f&&(_.isUndefined(a)?($("#setting-row-instance-name").hide(),$("#dialog-ok").hide()):($("#dialog-ok").show(),f.val(a).trigger("change")))}return{createPluginEditor:function(e,t,n,i,s,o){a(e,t,n,i,s)}}},ValueEditor=function(e){var t=new RegExp('.*datasources\\["([^"]*)("\\])?(.*)$'),n=null,i=0,a=[],s=null,o={ANY:"any",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean"};function r(e,t){return!(!_.isArray(e)&&!_.isObject(e))||d(e,t)}function d(e,t){switch(t){case o.ANY:return!0;case o.ARRAY:return _.isArray(e);case o.OBJECT:return _.isObject(e);case o.STRING:return _.isString(e);case o.NUMBER:return _.isNumber(e);case o.BOOLEAN:return _.isBoolean(e)}}function l(e,t){$(e).parent().find(".validation-error").remove(),d(s,t)||$(e).parent().append("This field expects an expression that evaluates to type "+t+".
")}function c(o,d){var c=$(o).val().substring(0,$(o).getCaretPosition());if(function(e,n,i){var o=t.exec(e),d=[];if(o)if(""==o[1])_.each(n,function(e){d.push({value:e.name(),entity:void 0,precede_char:"",follow_char:'"]'})});else if(""!=o[1]&&_.isUndefined(o[2])){var l=o[1];_.each(n,function(e){var t=e.name();t!=l&&0==t.indexOf(l)&&d.push({value:t,entity:void 0,precede_char:"",follow_char:'"]'})})}else{var c=_.find(n,function(e){return e.name()===o[1]});if(!_.isUndefined(c)){var u="data",p="";if(!_.isUndefined(o[2])){var f=o[3].lastIndexOf("]")+1;u+=o[3].substring(0,f),p=(p=(p=o[3].substring(f,o[3].length)).replace(/^[\[\"]*/,"")).replace(/[\"\]]*$/,"")}var h=c.getDataRepresentation(u);if(s=h,_.isArray(h)){for(var g=0;g0){n||(n=$('').insertAfter(o).width($(o).outerWidth()-2).css("left",$(o).position().left).css("top",$(o).position().top+$(o).outerHeight()-1)),n.empty(),n.scrollTop(0);var u=!0;i=0,_.each(a,function(e,t){var a=function(e,t,a,o){var r=a.value;a.preview&&(r=r+""+a.preview+" ");return $(""+r+" ").appendTo(n).mouseenter(function(){$(this).trigger("freeboard-select")}).mousedown(function(e){$(this).trigger("freeboard-insertValue"),e.preventDefault()}).data("freeboard-optionIndex",o).data("freeboard-optionValue",a.value).bind("freeboard-insertValue",function(){var n=a.value;n=a.precede_char+n+a.follow_char;var i=t.lastIndexOf("]");-1!=i?$(e).replaceTextAt(i+1,$(e).val().length,n):$(e).insertAtCaret(n),s=a.entity,$(e).triggerHandler("mouseup")}).bind("freeboard-select",function(){$(this).parent().find("li.selected").removeClass("selected"),$(this).addClass("selected"),i=$(this).data("freeboard-optionIndex")})}(o,c,e,t);u&&($(a).addClass("selected"),u=!1)})}else l(o,d),$(o).next("ul#value-selector").remove(),n=null,i=-1}function u(e,t){$(e).addClass("calculated-value-input").bind("keyup mouseup freeboard-eval",function(i){!n||"keyup"!=i.type||38!=i.keyCode&&40!=i.keyCode&&13!=i.keyCode?c(e,t):i.preventDefault()}).focus(function(){$(e).css({"z-index":3001}),function(e){var t=($(e).val().match(/\n/g)||[]).length,n=Math.min(200,20*(t+1));$(e).css({height:n+"px"})}(e)}).focusout(function(){l(e,t),$(e).css({height:"","z-index":3e3}),$(e).next("ul#value-selector").remove(),n=null,i=-1}).bind("keydown",function(e){if(n)if(38==e.keyCode||40==e.keyCode){e.preventDefault();var t=$(n).find("li");38==e.keyCode?i--:40==e.keyCode&&i++,i<0?i=t.size()-1:i>=t.size()&&(i=0);var a=$(t).eq(i);a.trigger("freeboard-select"),$(n).scrollTop($(a).position().top)}else 13==e.keyCode&&(e.preventDefault(),-1!=i&&$(n).find("li").eq(i).trigger("freeboard-insertValue"))})}return{createValueEditor:function(e,t){u(e,t||o.ANY)},EXPECTED_TYPE:o}},function(e){var t=window.MutationObserver||window.WebKitMutationObserver;e.fn.attrchange=function(n){var i={trackValues:!1,callback:e.noop};if("function"==typeof n?i.callback=n:e.extend(i,n),i.trackValues&&e(this).each(function(t,n){for(var i,a={},s=(t=0,n.attributes),o=s.length;t=0){i.style||(i.style={});var a=n.attributeName.split(".");n.attributeName=a[0],n.oldValue=i.style[a[1]],n.newValue=a[1]+":"+this.prop("style")[e.camelCase(a[1])],i.style[a[1]]=n.newValue}else n.oldValue=i[n.attributeName],n.newValue=this.attr(n.attributeName),i[n.attributeName]=n.newValue;this.data("attr-old-value",i)}}.call(e(this),i.trackValues,t),i.callback.call(this,t)}):this}}(jQuery),function(e){e.eventEmitter={_JQInit:function(){this._JQ=e(this)},emit:function(e,t){!this._JQ&&this._JQInit(),this._JQ.trigger(e,t)},once:function(e,t){!this._JQ&&this._JQInit(),this._JQ.one(e,t)},on:function(e,t){!this._JQ&&this._JQInit(),this._JQ.bind(e,t)},off:function(e,t){!this._JQ&&this._JQInit(),this._JQ.unbind(e,t)}}}(jQuery);var freeboard=function(){var e={},t={},n=new FreeboardUI(10,300,3),i=new FreeboardModel(e,t,n),a=new JSEditor,s=new ValueEditor(i),o=new PluginEditor(a,s),r=new DeveloperConsole(i),d={values:{"font-family":'"HelveticaNeue-UltraLight", "Helvetica Neue Ultra Light", "Helvetica Neue", sans-serif',color:"#d3d4d4","font-weight":100}};return ko.bindingHandlers.pluginEditor={init:function(a,s,r,d,l){var c=ko.unwrap(s()),u={},p=void 0,f="";"datasource"==c.type?(u=e,f="Datasource"):"widget"==c.type?(u=t,f="Widget"):"pane"==c.type&&(f="Pane"),$(a).click(function(s){if("delete"==c.operation){new DialogBox($("Are you sure you want to delete this "+f+"?
"),"Confirm Delete","Yes","No",function(){"datasource"==c.type?i.deleteDatasource(d):"widget"==c.type?i.deleteWidget(d):"pane"==c.type&&i.deletePane(d)})}else{var r=void 0;"datasource"==c.type?"add"==c.operation?p={}:(r=d.type(),(p=d.settings()).name=d.name()):"widget"==c.type?"add"==c.operation?p={}:(r=d.type(),p=d.settings()):"pane"==c.type&&(p={},"edit"==c.operation&&(p.title=d.title(),p.col_width=d.col_width()),u={settings:{settings:[{name:"title",display_name:"Title",type:"text"},{name:"col_width",display_name:"Columns",type:"integer",default_value:1,required:!0}]}}),o.createPluginEditor(f,u,r,p,function(s){if("add"==c.operation){if("datasource"==c.type){var o=new DatasourceModel(i,e);i.addDatasource(o),o.name(s.settings.name),delete s.settings.name,o.settings(s.settings),o.type(s.type)}else if("widget"==c.type){(o=new WidgetModel(i,t)).settings(s.settings),o.type(s.type),d.widgets.push(o),n.attachWidgetEditIcons(a)}}else"edit"==c.operation&&("pane"==c.type?(d.title(s.settings.title),d.col_width(s.settings.col_width),n.processResize(!1)):("datasource"==c.type&&(d.name(s.settings.name),delete s.settings.name),d.type(s.type),d.settings(s.settings)))})}})}},ko.virtualElements.allowedBindings.datasourceTypeSettings=!0,ko.bindingHandlers.datasourceTypeSettings={update:function(e,t,n,i,a){processPluginSettings(e,t,n,i,a)}},ko.bindingHandlers.pane={init:function(e,t,a,s,o){i.isEditing()&&$(e).css({cursor:"pointer"}),n.addPane(e,s,o.$root.isEditing())},update:function(e,t,a,s,o){-1==i.panes.indexOf(s)&&n.removePane(e),n.updatePane(e,s)}},ko.bindingHandlers.widget={init:function(e,t,a,s,o){i.isEditing()&&n.attachWidgetEditIcons($(e).parent())},update:function(e,t,n,i,a){i.shouldRender()&&($(e).empty(),i.render(e))}},$(function(){var e;function t(){n.processResize(!0)}n.showLoadingIndicator(!0),$(window).resize(function(){clearTimeout(e),e=setTimeout(t,500)})}),{initialize:function(e,t){ko.applyBindings(i);var a=function(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^]*)").exec(location.search);return null==t?"":decodeURIComponent(t[1].replace(/\+/g," "))}("load");""!=a?$.ajax({url:a,success:function(e){i.loadDashboard(e),_.isFunction(t)&&t()}}):(i.allow_edit(e),i.setEditing(e),n.showLoadingIndicator(!1),_.isFunction(t)&&t(),freeboard.emit("initialized"))},newDashboard:function(){i.loadDashboard({allow_edit:!0})},loadDashboard:function(e,t){i.loadDashboard(e,t)},serialize:function(){return i.serialize()},setEditing:function(e,t){i.setEditing(e,t)},isEditing:function(){return i.isEditing()},loadDatasourcePlugin:function(t){_.isUndefined(t.display_name)&&(t.display_name=t.type_name),t.settings.unshift({name:"name",display_name:"Name",type:"text",required:!0}),i.addPluginSource(t.source),e[t.type_name]=t,i._datasourceTypes.valueHasMutated()},resize:function(){n.processResize(!0)},loadWidgetPlugin:function(e){_.isUndefined(e.display_name)&&(e.display_name=e.type_name),i.addPluginSource(e.source),t[e.type_name]=e,i._widgetTypes.valueHasMutated()},setAssetRoot:function(e){a.setAssetRoot(e)},addStyle:function(e,t){var n=e+"{"+t+"}",i=$("style#fb-styles");0==i.length&&(i=$(''),$("head").append(i)),i[0].styleSheet?i[0].styleSheet.cssText+=n:i.text(i.text()+n)},showLoadingIndicator:function(e){n.showLoadingIndicator(e)},showDialog:function(e,t,n,i,a){new DialogBox(e,t,n,i,a)},getDatasourceSettings:function(e){var t=i.datasources(),n=_.find(t,function(t){return t.name()===e});return n?n.settings():null},setDatasourceSettings:function(e,t){var n=i.datasources(),a=_.find(n,function(t){return t.name()===e});if(a){var s=_.defaults(t,a.settings());a.settings(s)}else console.log("Datasource not found")},getStyleString:function(e){var t="";return _.each(d[e],function(e,n){t=t+n+":"+e+";"}),t},getStyleObject:function(e){return d[e]},showDeveloperConsole:function(){r.showDeveloperConsole()}}}();$.extend(freeboard,jQuery.eventEmitter),function(){freeboard.loadDatasourcePlugin({type_name:"JSON",settings:[{name:"url",display_name:"URL",type:"text"},{name:"use_thingproxy",display_name:"Try thingproxy",description:'A direct JSON connection will be tried first, if that fails, a JSONP connection will be tried. If that fails, you can use thingproxy, which can solve many connection problems to APIs. More information .',type:"boolean",default_value:!0},{name:"refresh",display_name:"Refresh Every",type:"number",suffix:"seconds",default_value:5},{name:"method",display_name:"Method",type:"option",options:[{name:"GET",value:"GET"},{name:"POST",value:"POST"},{name:"PUT",value:"PUT"},{name:"DELETE",value:"DELETE"}]},{name:"body",display_name:"Body",type:"text",description:"The body of the request. Normally only used if method is POST"},{name:"headers",display_name:"Headers",type:"array",settings:[{name:"name",display_name:"Name",type:"text"},{name:"value",display_name:"Value",type:"text"}]}],newInstance:function(e,t,n){t(new function(e,t){var n=this,i=null,a=e,s=0,o=!1;function r(e){i&&clearInterval(i),i=setInterval(function(){n.updateNow()},e)}r(1e3*a.refresh),this.updateNow=function(){if(!(s>1&&!a.use_thingproxy||s>2)){var e=a.url;2==s&&a.use_thingproxy&&(e=("https:"==location.protocol?"https:":"http:")+"//thingproxy.freeboard.io/fetch/"+encodeURI(a.url));var i=a.body;if(i)try{i=JSON.parse(i)}catch(e){}$.ajax({url:e,dataType:1==s?"JSONP":"JSON",type:a.method||"GET",data:i,beforeSend:function(e){try{_.each(a.headers,function(t){var n=t.name,i=t.value;_.isUndefined(n)||_.isUndefined(i)||e.setRequestHeader(n,i)})}catch(e){}},success:function(e){o=!0,t(e)},error:function(e,t,i){o||(s++,n.updateNow())}})}},this.onDispose=function(){clearInterval(i),i=null},this.onSettingsChanged=function(e){o=!1,s=0,r(1e3*(a=e).refresh),n.updateNow()}}(e,n))}});freeboard.loadDatasourcePlugin({type_name:"openweathermap",display_name:"Open Weather Map API",settings:[{name:"api_key",display_name:"API Key",type:"text",description:"Your personal API Key from Open Weather Map"},{name:"location",display_name:"Location",type:"text",description:"Example: London, UK"},{name:"units",display_name:"Units",type:"option",default:"imperial",options:[{name:"Imperial",value:"imperial"},{name:"Metric",value:"metric"}]},{name:"refresh",display_name:"Refresh Every",type:"number",suffix:"seconds",default_value:5}],newInstance:function(e,t,n){t(new function(e,t){var n=this,i=null,a=e;function s(e){i&&clearInterval(i),i=setInterval(function(){n.updateNow()},e)}s(1e3*a.refresh),this.updateNow=function(){$.ajax({url:"http://api.openweathermap.org/data/2.5/weather?APPID="+a.api_key+"&q="+encodeURIComponent(a.location)+"&units="+a.units,dataType:"JSONP",success:function(e){var n,i={place_name:e.name,sunrise:new Date(1e3*e.sys.sunrise).toLocaleTimeString(),sunset:new Date(1e3*e.sys.sunset).toLocaleTimeString(),conditions:(n=e.weather[0].description,n.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()})),current_temp:e.main.temp,high_temp:e.main.temp_max,low_temp:e.main.temp_min,pressure:e.main.pressure,humidity:e.main.humidity,wind_speed:e.wind.speed,wind_direction:e.wind.deg};t(i)},error:function(e,t,n){}})},this.onDispose=function(){clearInterval(i),i=null},this.onSettingsChanged=function(e){a=e,n.updateNow(),s(1e3*a.refresh)}}(e,n))}});freeboard.loadDatasourcePlugin({type_name:"dweet_io",display_name:"Dweet.io",external_scripts:["http://dweet.io/client/dweet.io.min.js"],settings:[{name:"thing_id",display_name:"Thing Name",description:"Example: salty-dog-1",type:"text"}],newInstance:function(e,t,n){t(new function(e,t){var n=e;function i(e){t(e)}this.updateNow=function(){dweetio.get_latest_dweet_for(n.thing_id,function(e,t){e||i(t[0].content)})},this.onDispose=function(){},this.onSettingsChanged=function(e){dweetio.stop_listening_for(n.thing_id),n=e,dweetio.listen_for(n.thing_id,function(e){i(e.content)})},this.onSettingsChanged(e)}(e,n))}});freeboard.loadDatasourcePlugin({type_name:"playback",display_name:"Playback",settings:[{name:"datafile",display_name:"Data File URL",type:"text",description:"A link to a JSON array of data."},{name:"is_jsonp",display_name:"Is JSONP",type:"boolean"},{name:"loop",display_name:"Loop",type:"boolean",description:"Rewind and loop when finished"},{name:"refresh",display_name:"Refresh Every",type:"number",suffix:"seconds",default_value:5}],newInstance:function(e,t,n){t(new function(e,t){var n,i=this,a=e,s=[],o=0;function r(){s.length>0?(o=s.length&&a.loop&&(o=0),o=e&&s[n].shift(),s[n].push(Number(t)),(void 0===o||tr)&&(r=t)};_.isArray(i)?_.each(i,d):d(i,0),$(n).data().values=s,$(n).data().valueMin=o,$(n).data().valueMax=r;var l='● {{y}}',c=!1;_.each(s,function(e,i){$(n).sparkline(e,{type:"line",composite:c,height:"100%",width:"100%",fillColor:!1,lineColor:t[i%t.length],lineWidth:2,spotRadius:3,spotColor:!1,minSpotColor:"#78AB49",maxSpotColor:"#78AB49",highlightSpotColor:"#9D3926",highlightLineColor:"#9D3926",chartRangeMin:o,chartRangeMax:r,tooltipFormat:a&&a[i]?l+" ("+a[i]+")":l}),c=!0})}var i=freeboard.getStyleString("values");freeboard.addStyle(".widget-big-text",i+"font-size:75px;"),freeboard.addStyle(".tw-display","width: 100%; height:100%; display:table; table-layout:fixed;"),freeboard.addStyle(".tw-tr","display:table-row;"),freeboard.addStyle(".tw-tg","display:table-row-group;"),freeboard.addStyle(".tw-tc","display:table-caption;"),freeboard.addStyle(".tw-td","display:table-cell;"),freeboard.addStyle(".tw-value",i+"overflow: hidden;display: inline-block;text-overflow: ellipsis;"),freeboard.addStyle(".tw-unit","display: inline-block;padding-left: 10px;padding-bottom: 1.1em;vertical-align: bottom;"),freeboard.addStyle(".tw-value-wrapper","position: relative;vertical-align: middle;height:100%;"),freeboard.addStyle(".tw-sparkline","height:20px;");var a=function(e){var t=e,i=$('
'),a=$(' '),s=$('
'),o=$('
'),r=$('
');function d(){_.isUndefined(t.units)||""==t.units?s.css("max-width","100%"):s.css("max-width",i.innerWidth()-o.outerWidth(!0)+"px")}this.render=function(e){$(e).empty(),$(i).append($('
').append(a)).append($('
').append($('
').append(s).append(o))).append($('
').append(r)),$(e).append(i),d()},this.onSettingsChanged=function(e){t=e;var n=!_.isUndefined(e.title)&&""!=e.title,i=!_.isUndefined(e.units)&&""!=e.units;e.sparkline?r.attr("style",null):(delete r.data().values,r.empty(),r.hide()),n?(a.html(_.isUndefined(e.title)?"":e.title),a.attr("style",null)):(a.empty(),a.hide()),i?(o.html(_.isUndefined(e.units)?"":e.units),o.attr("style",null)):(o.empty(),o.hide());var l=30;"big"==e.size&&(l=75,e.sparkline&&(l=60)),s.css({"font-size":l+"px"}),d()},this.onSizeChanged=function(){d()},this.onCalculatedValueChanged=function(e,i){"value"==e&&(t.animate?function(e,t,n){var i=$(t).text();if(i!=e)if($.isNumeric(e)&&$.isNumeric(i)){var a=e.toString().split("."),s=0;a.length>1&&(s=a[1].length);var o=0;(a=i.toString().split(".")).length>1&&(o=a[1].length),jQuery({transitionValue:Number(i),precisionValue:o}).animate({transitionValue:Number(e),precisionValue:s},{duration:n,step:function(){$(t).text(this.transitionValue.toFixed(this.precisionValue))},done:function(){$(t).text(e)}})}else $(t).text(e)}(i,s,500):s.text(i),t.sparkline&&n(r,i))},this.onDispose=function(){},this.getHeight=function(){return"big"==t.size||t.sparkline?2:1},this.onSettingsChanged(e)};freeboard.loadWidgetPlugin({type_name:"text_widget",display_name:"Text",external_scripts:["plugins/thirdparty/jquery.sparkline.min.js"],settings:[{name:"title",display_name:"Title",type:"text"},{name:"size",display_name:"Size",type:"option",options:[{name:"Regular",value:"regular"},{name:"Big",value:"big"}]},{name:"value",display_name:"Value",type:"calculated"},{name:"sparkline",display_name:"Include Sparkline",type:"boolean"},{name:"animate",display_name:"Animate Value Changes",type:"boolean",default_value:!0},{name:"units",display_name:"Units",type:"text"}],newInstance:function(e,t){t(new a(e))}});var s=0;freeboard.addStyle(".gauge-widget-wrapper","width: 100%;text-align: center;"),freeboard.addStyle(".gauge-widget","width:200px;height:160px;display:inline-block;");freeboard.loadWidgetPlugin({type_name:"gauge",display_name:"Gauge",external_scripts:["plugins/thirdparty/raphael.2.1.0.min.js","plugins/thirdparty/justgage.1.0.1.js"],settings:[{name:"title",display_name:"Title",type:"text"},{name:"value",display_name:"Value",type:"calculated"},{name:"units",display_name:"Units",type:"text"},{name:"min_value",display_name:"Minimum",type:"text",default_value:0},{name:"max_value",display_name:"Maximum",type:"text",default_value:100}],newInstance:function(e,t){t(new function(e){var t,n="gauge-"+s++,i=$(' '),a=$('
'),o=!1,r=e;function d(){o&&(a.empty(),t=new JustGage({id:n,value:_.isUndefined(r.min_value)?0:r.min_value,min:_.isUndefined(r.min_value)?0:r.min_value,max:_.isUndefined(r.max_value)?0:r.max_value,label:r.units,showInnerShadow:!1,valueFontColor:"#d3d4d4"}))}this.render=function(e){o=!0,$(e).append(i).append($('
').append(a)),d()},this.onSettingsChanged=function(e){e.min_value!=r.min_value||e.max_value!=r.max_value||e.units!=r.units?(r=e,d()):r=e,i.html(e.title)},this.onCalculatedValueChanged=function(e,n){_.isUndefined(t)||t.refresh(Number(n))},this.onDispose=function(){},this.getHeight=function(){return 3},this.onSettingsChanged(e)}(e))}}),freeboard.addStyle(".sparkline","width:100%;height: 75px;");var o=function(e){var i=$(' '),a=$('
'),s=$("
"),o=e;this.render=function(e){$(e).append(i).append(a).append(s)},this.onSettingsChanged=function(e){o=e,i.html(_.isUndefined(e.title)?"":e.title),e.include_legend&&function(e,n){for(var i=$("
"),a=0;a● "+o+"")}e.empty().append(i),freeboard.addStyle(".sparkline-legend","margin:5px;"),freeboard.addStyle(".sparkline-legend-value","color:white; font:10px arial,san serif; float:left; overflow:hidden; width:50%;"),freeboard.addStyle(".sparkline-legend-value span","font-weight:bold; padding-right:5px;")}(s,e.legend.split(","))},this.onCalculatedValueChanged=function(e,t){o.legend?n(a,t,o.legend.split(",")):n(a,t)},this.onDispose=function(){},this.getHeight=function(){var e=0;if(o.include_legend&&o.legend){var t=o.legend.split(",").length;t>4?e=.5*Math.floor((t-1)/4):t&&(e=.5)}return 2+e},this.onSettingsChanged(e)};freeboard.loadWidgetPlugin({type_name:"sparkline",display_name:"Sparkline",external_scripts:["plugins/thirdparty/jquery.sparkline.min.js"],settings:[{name:"title",display_name:"Title",type:"text"},{name:"value",display_name:"Value",type:"calculated",multi_input:"true"},{name:"include_legend",display_name:"Include Legend",type:"boolean"},{name:"legend",display_name:"Legend",type:"text",description:"Comma-separated for multiple sparklines"}],newInstance:function(e,t){t(new o(e))}}),freeboard.addStyle("div.pointer-value","position:absolute;height:95px;margin: auto;top: 0px;bottom: 0px;width: 100%;text-align:center;");freeboard.loadWidgetPlugin({type_name:"pointer",display_name:"Pointer",external_scripts:["plugins/thirdparty/raphael.2.1.0.min.js"],settings:[{name:"direction",display_name:"Direction",type:"calculated",description:"In degrees"},{name:"value_text",display_name:"Value Text",type:"calculated"},{name:"units",display_name:"Units",type:"text"}],newInstance:function(e,t){t(new function(e){var t,n,i,a,s=$('
'),o=$("
");this.render=function(e){i=$(e).width(),a=$(e).height();var r=Math.min(i,a)/2-6,d=(t=Raphael($(e).get()[0],i,a)).circle(i/2,a/2,r);d.attr("stroke","#FF9900"),d.attr("stroke-width",3),(n=t.path(function(e){if(!e||e.length<2)return[];var t=[];t.push(["m",e[0],e[1]]);for(var n=2;n').append(s).append(o))},this.onSettingsChanged=function(e){o.html(e.units)},this.onCalculatedValueChanged=function(e,t){"direction"==e?_.isUndefined(n)||n.animate({transform:"r"+t+","+i/2+","+a/2},250,"bounce"):"value_text"==e&&s.html(t)},this.onDispose=function(){},this.getHeight=function(){return 4},this.onSettingsChanged(e)}(e))}});freeboard.loadWidgetPlugin({type_name:"picture",display_name:"Picture",fill_size:!0,settings:[{name:"src",display_name:"Image URL",type:"calculated"},{type:"number",display_name:"Refresh every",name:"refresh",suffix:"seconds",description:"Leave blank if the image doesn't need to be refreshed"}],newInstance:function(e,t){t(new function(e){var t,n,i;function a(){n&&(clearInterval(n),n=null)}function s(){if(t&&i){var e=i+(-1==i.indexOf("?")?"?":"&")+Date.now();$(t).css({"background-image":"url("+e+")"})}}this.render=function(e){$(e).css({width:"100%",height:"100%","background-size":"cover","background-position":"center"}),t=e},this.onSettingsChanged=function(e){a(),e.refresh&&e.refresh>0&&(n=setInterval(s,1e3*Number(e.refresh)))},this.onCalculatedValueChanged=function(e,t){"src"==e&&(i=t),s()},this.onDispose=function(){a()},this.getHeight=function(){return 4},this.onSettingsChanged(e)}(e))}}),freeboard.addStyle(".indicator-light","border-radius:50%;width:22px;height:22px;border:2px solid #3d3d3d;margin-top:5px;float:left;background-color:#222;margin-right:10px;"),freeboard.addStyle(".indicator-light.on","background-color:#FFC773;box-shadow: 0px 0px 15px #FF9900;border-color:#FDF1DF;"),freeboard.addStyle(".indicator-text","margin-top:10px;");freeboard.loadWidgetPlugin({type_name:"indicator",display_name:"Indicator Light",settings:[{name:"title",display_name:"Title",type:"text"},{name:"value",display_name:"Value",type:"calculated"},{name:"on_text",display_name:"On Text",type:"calculated"},{name:"off_text",display_name:"Off Text",type:"calculated"}],newInstance:function(e,t){t(new function(e){var t,n,i=$(' '),a=$('
'),s=$('
'),o=e,r=!1;function d(){s.toggleClass("on",r),r?a.text(_.isUndefined(t)?_.isUndefined(o.on_text)?"":o.on_text:t):a.text(_.isUndefined(n)?_.isUndefined(o.off_text)?"":o.off_text:n)}this.render=function(e){$(e).append(i).append(s).append(a)},this.onSettingsChanged=function(e){o=e,i.html(_.isUndefined(e.title)?"":e.title),d()},this.onCalculatedValueChanged=function(e,i){"value"==e&&(r=Boolean(i)),"on_text"==e&&(t=i),"off_text"==e&&(n=i),d()},this.onDispose=function(){},this.getHeight=function(){return 1},this.onSettingsChanged(e)}(e))}}),freeboard.addStyle(".gm-style-cc a","text-shadow:none;");freeboard.loadWidgetPlugin({type_name:"google_map",display_name:"Google Map",fill_size:!0,settings:[{name:"lat",display_name:"Latitude",type:"calculated"},{name:"lon",display_name:"Longitude",type:"calculated"}],newInstance:function(e,t){t(new function(e){var t,n,i={};function a(){if(t&&n&&i.lat&&i.lon){var e=new google.maps.LatLng(i.lat,i.lon);n.setPosition(e),t.panTo(e)}}this.render=function(e){function i(){var i={zoom:13,center:new google.maps.LatLng(37.235,-115.811111),disableDefaultUI:!0,draggable:!1,styles:[{featureType:"water",elementType:"geometry",stylers:[{color:"#2a2a2a"}]},{featureType:"landscape",elementType:"geometry",stylers:[{color:"#000000"},{lightness:20}]},{featureType:"road.highway",elementType:"geometry.fill",stylers:[{color:"#000000"},{lightness:17}]},{featureType:"road.highway",elementType:"geometry.stroke",stylers:[{color:"#000000"},{lightness:29},{weight:.2}]},{featureType:"road.arterial",elementType:"geometry",stylers:[{color:"#000000"},{lightness:18}]},{featureType:"road.local",elementType:"geometry",stylers:[{color:"#000000"},{lightness:16}]},{featureType:"poi",elementType:"geometry",stylers:[{color:"#000000"},{lightness:21}]},{elementType:"labels.text.stroke",stylers:[{visibility:"on"},{color:"#000000"},{lightness:16}]},{elementType:"labels.text.fill",stylers:[{saturation:36},{color:"#000000"},{lightness:40}]},{elementType:"labels.icon",stylers:[{visibility:"off"}]},{featureType:"transit",elementType:"geometry",stylers:[{color:"#000000"},{lightness:19}]},{featureType:"administrative",elementType:"geometry.fill",stylers:[{color:"#000000"},{lightness:20}]},{featureType:"administrative",elementType:"geometry.stroke",stylers:[{color:"#000000"},{lightness:17},{weight:1.2}]}]};t=new google.maps.Map(e,i),google.maps.event.addDomListener(e,"mouseenter",function(e){e.cancelBubble=!0,t.hover||(t.hover=!0,t.setOptions({zoomControl:!0}))}),google.maps.event.addDomListener(e,"mouseleave",function(e){t.hover&&(t.setOptions({zoomControl:!1}),t.hover=!1)}),n=new google.maps.Marker({map:t}),a()}window.google&&window.google.maps?i():(window.gmap_initialize=i,head.js("https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=gmap_initialize"))},this.onSettingsChanged=function(e){},this.onCalculatedValueChanged=function(e,t){"lat"==e?i.lat=t:"lon"==e&&(i.lon=t),a()},this.onDispose=function(){},this.getHeight=function(){return 4},this.onSettingsChanged(e)}(e))}}),freeboard.addStyle(".html-widget","white-space:normal;width:100%;height:100%");freeboard.loadWidgetPlugin({type_name:"html",display_name:"HTML",fill_size:!0,settings:[{name:"html",display_name:"HTML",type:"calculated",description:"Can be literal HTML, or javascript that outputs HTML."},{name:"height",display_name:"Height Blocks",type:"number",default_value:4,description:"A height block is around 60 pixels"}],newInstance:function(e,t){t(new function(e){var t=$('
'),n=e;this.render=function(e){$(e).append(t)},this.onSettingsChanged=function(e){n=e},this.onCalculatedValueChanged=function(e,n){"html"==e&&t.html(n)},this.onDispose=function(){},this.getHeight=function(){return Number(n.height)},this.onSettingsChanged(e)}(e))}})}();
\ No newline at end of file
+function DialogBox(e,t,n,i,a){var s=$('
'),o=$('
');function r(){s.fadeOut(200,function(){$(this).remove()})}o.append('"),$("").appendTo(o).append(e);var d=$("").appendTo(o);n&&$(''+n+" ").appendTo(d).click(function(){var e=!1;_.isFunction(a)&&(e=a()),e||r()}),i&&$(''+i+" ").appendTo(d).click(function(){r()}),s.append(o),$("body").append(s),s.fadeIn(200)}function FreeboardModel(e,t,n){var i=this;this.version=0,this.isEditing=ko.observable(!1),this.allow_edit=ko.observable(!1),this.allow_edit.subscribe(function(e){e?$("#main-header").show():$("#main-header").hide()}),this.header_image=ko.observable(),this.plugins=ko.observableArray(),this.datasources=ko.observableArray(),this.panes=ko.observableArray(),this.datasourceData={},this.processDatasourceUpdate=function(e,t){var n=e.name(),a=function e(t,n,i){return _.isUndefined(n)&&(n=""),_.isUndefined(i)&&(i=[]),"object"!=typeof t?(i.push(n),i):(Object.keys(t).forEach(a=>{var s=n+'["'+a+'"]';"object"==typeof t[a]&&null!==t[a]?(e(t[a],s,i),n.length>0&&i.push(s)):i.push(s)}),i)}(t);"object"==typeof t?(_.isUndefined(i.datasourceData[n])&&(i.datasourceData[n]={}),Object.assign(i.datasourceData[n],t)):i.datasourceData[n]=t,_.each(i.panes(),function(e){_.each(e.widgets(),function(e){e.processDatasourceUpdate(n,a)})})},this._datasourceTypes=ko.observable(),this.datasourceTypes=ko.computed({read:function(){i._datasourceTypes();var t=[];return _.each(e,function(e){var n=e.type_name,i=n;_.isUndefined(e.display_name)||(i=e.display_name),t.push({name:n,display_name:i})}),t}}),this._widgetTypes=ko.observable(),this.widgetTypes=ko.computed({read:function(){i._widgetTypes();var e=[];return _.each(t,function(t){var n=t.type_name,i=n;_.isUndefined(t.display_name)||(i=t.display_name),e.push({name:n,display_name:i})}),e}}),this.addPluginSource=function(e){e&&-1==i.plugins.indexOf(e)&&i.plugins.push(e)},this.serialize=function(){var e=[];_.each(i.panes(),function(t){e.push(t.serialize())});var t=[];return _.each(i.datasources(),function(e){t.push(e.serialize())}),{version:1,header_image:i.header_image(),allow_edit:i.allow_edit(),plugins:i.plugins(),panes:e,datasources:t,columns:n.getUserColumns()}},this.deserialize=function(a,s){function o(){n.setUserColumns(a.columns),_.isUndefined(a.allow_edit)?i.allow_edit(!0):i.allow_edit(a.allow_edit),i.version=a.version||0,i.header_image(a.header_image),_.each(a.datasources,function(t){var n=new DatasourceModel(i,e);n.deserialize(t),i.addDatasource(n)});var o=_.sortBy(a.panes,function(e){return n.getPositionForScreenSize(e).row});_.each(o,function(e){var n=new PaneModel(i,t);n.deserialize(e),i.panes.push(n)}),i.allow_edit()&&0==i.panes().length&&i.setEditing(!0),_.isFunction(s)&&s(),n.processResize(!0)}i.clearDashboard(),_.each(a.plugins,function(e){i.addPluginSource(e)}),_.isArray(a.plugins)&&a.plugins.length>0?head.js(a.plugins,function(){o()}):o()},this.clearDashboard=function(){n.removeAllPanes(),_.each(i.datasources(),function(e){e.dispose()}),_.each(i.panes(),function(e){e.dispose()}),i.plugins.removeAll(),i.datasources.removeAll(),i.panes.removeAll()},this.loadDashboard=function(e,t){n.showLoadingIndicator(!0),i.deserialize(e,function(){n.showLoadingIndicator(!1),_.isFunction(t)&&t(),freeboard.emit("dashboard_loaded")})},this.loadDashboardFromLocalFile=function(){if(window.File&&window.FileReader&&window.FileList&&window.Blob){var e=document.createElement("input");e.type="file",$(e).on("change",function(e){var t=e.target.files;if(t&&t.length>0){var n=t[0],a=new FileReader;a.addEventListener("load",function(e){var t=e.target,n=JSON.parse(t.result);i.loadDashboard(n),i.setEditing(!1)}),a.readAsText(n)}}),$(e).trigger("click")}else alert("Unable to load a file in this browser.")},this.saveDashboardClicked=function(e,t){var n=$(t.currentTarget),i=n.data("siblings-shown")||!1;i?$(t.currentTarget).siblings("label").fadeOut("slow"):$(t.currentTarget).siblings("label").fadeIn("slow"),n.data("siblings-shown",!i)},this.saveDashboard=function(e,t){var n=$(t.currentTarget).data("pretty"),a=document.createElement("a");if(n)var s=new Blob([JSON.stringify(i.serialize(),null,"\t")],{type:"application/octet-stream"});else s=new Blob([JSON.stringify(i.serialize())],{type:"application/octet-stream"});document.body.appendChild(a),a.href=window.URL.createObjectURL(s),a.download="dashboard.json",a.target="_self",a.click()},this.addDatasource=function(e){i.datasourceData[e.name()]={},i.datasources.push(e)},this.deleteDatasource=function(e){delete i.datasourceData[e.name()],e.dispose(),i.datasources.remove(e)},this.createPane=function(){var e=new PaneModel(i,t);i.addPane(e)},this.addGridColumnLeft=function(){n.addGridColumnLeft()},this.addGridColumnRight=function(){n.addGridColumnRight()},this.subGridColumnLeft=function(){n.subGridColumnLeft()},this.subGridColumnRight=function(){n.subGridColumnRight()},this.addPane=function(e){i.panes.push(e)},this.deletePane=function(e){e.dispose(),i.panes.remove(e)},this.deleteWidget=function(e){ko.utils.arrayForEach(i.panes(),function(t){t.widgets.remove(e)}),e.dispose()},this.setEditing=function(e,t){if(i.allow_edit()||!e){i.isEditing(e),_.isUndefined(t)&&(t=!0);var a=t?250:0,s=$("#admin-bar").outerHeight();e?($("#toggle-header-icon").addClass("icon-chevron-up").removeClass("icon-wrench"),$(".gridster .gs_w").css({cursor:"pointer"}),$("#main-header").animate({top:"0px"},a),$("#board-content").animate({top:s+20+"px"},a),$("#main-header").data().shown=!0,n.attachWidgetEditIcons($(".sub-section")),n.enableGrid()):($("#toggle-header-icon").addClass("icon-wrench").removeClass("icon-chevron-up"),$(".gridster .gs_w").css({cursor:"default"}),$("#main-header").animate({top:"-"+s+"px"},a),$("#board-content").animate({top:"20"},a),$("#main-header").data().shown=!1,$(".sub-section").unbind(),n.disableGrid()),n.showPaneEditIcons(e,t)}},this.toggleEditing=function(){var e=!i.isEditing();i.setEditing(e)}}function FreeboardUI(e,t,n){var i,a=e+t+e,s=n,o=$('');function r(e){var t=u(),n=function(){};e&&(n=function(e){var n=ko.dataFor(this),a=v(n);$(this).attr("data-sizex",Math.min(n.col_width(),t,i.cols)).attr("data-row",a.row).attr("data-col",a.col),n.processSizeChange()}),p(Math.min(t,s)),f(n),c()}function d(e){p(i.cols+1)&&f(function(){var t,n=ko.dataFor(this),a=i.cols>1?i.cols-1:1,s=n.col[a],o=n.row[a];e?(leftPreviewCol=!0,t={row:o,col:s1?s-1:1}:t={row:o,col:s<=i.cols?s:i.cols};$(this).attr("data-sizex",Math.min(n.col_width(),i.cols)).attr("data-row",t.row).attr("data-col",t.col)}),c(),s=i.cols}function c(){var e=$(".column-tool"),t=$("#board-content").width(),s=Math.floor(t/a);i.cols<=n?e.addClass("min"):e.removeClass("min"),i.cols>=s?e.addClass("max"):e.removeClass("max")}function u(){var e=$("#board-content").width();return Math.floor(e/a)}function p(e){(void 0===e||et&&(e=t);var s=a*e+e;return $(".responsive-column-width").css("max-width",s),e!==i.cols}function f(n){var a=i.$el;a.find("> li").unbind().removeData(),$(".responsive-column-width").css("width",""),i.generate_grid_and_stylesheet(),a.find("> li").each(n),i.init(),$(".responsive-column-width").css("width",i.cols*t+i.cols*e*2)}function h(e,t,n){var a=i.cols;_.isUndefined(t)||(e.row[a]=t),_.isUndefined(n)||(e.col[a]=n)}function g(e,t){_.isUndefined(t)&&(t=!0);var n=t?250:0;e?($(".pane-tools").fadeIn(n),$("#column-tools").fadeIn(n)):($(".pane-tools").fadeOut(n),$("#column-tools").fadeOut(n))}function m(e,t){t?$(e).find(".sub-section-tools").fadeIn(250):$(e).find(".sub-section-tools").fadeOut(250)}function v(e){var t=i.cols;if(_.isNumber(e.row)&&_.isNumber(e.col)){var n={};n[t]=e.row,e.row=n,(n={})[t]=e.col,e.col=n}var a=1,s=1e3;for(var o in e.col){if(o==t)return{row:e.row[o],col:e.col[o]};if(e.col[o]>t)a=t;else{var r=t-o;r=1},this.widgetCanMoveDown=function(e){return n.widgets.indexOf(e)t===e.name)&&a.push(e.name)})})}),_.each(a,function(e){n.processCalculatedSetting(e)})}},this.callValueFunction=function(t){return t.call(void 0,e.datasourceData)},this.processSizeChange=function(){!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.onSizeChanged)&&n.widgetInstance.onSizeChanged()},this.processCalculatedSetting=function(e){if(_.isFunction(n.calculatedSettingScripts[e])){var t=void 0;try{t=n.callValueFunction(n.calculatedSettingScripts[e])}catch(a){var i=n.settings()[e];a instanceof ReferenceError&&/^\w+$/.test(i)&&(t=i)}if(!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.onCalculatedValueChanged)&&!_.isUndefined(t))try{n.widgetInstance.onCalculatedValueChanged(e,t)}catch(e){console.log(e.toString())}}},this.updateCalculatedSettings=function(){if(n.datasourceRefreshNotifications={},n.calculatedSettingScripts={},!_.isUndefined(n.type())){var e=t[n.type()].settings,i=new RegExp('datasources\\[\\"(\\w+)\\"\\](\\[\\"[\\"\\]\\[\\w\\.\\/]+\\"])?',"g"),a=n.settings();_.each(e,function(e){if("calculated"==e.type){var t=a[e.name];if(!_.isUndefined(t)){var s,o;_.isArray(t)&&(t="["+t.join(",")+"]"),(t.match(/;/g)||[]).length<=1&&-1==t.indexOf("return")&&(t="return "+t);try{s=new Function("datasources",t)}catch(t){var r=a[e.name].replace(/"/g,'\\"').replace(/[\r\n]/g," \\\n");s=new Function("datasources",'return "'+r+'";')}for(n.calculatedSettingScripts[e.name]=s,n.processCalculatedSetting(e.name);o=i.exec(t);){var d=o[1],l=n.datasourceRefreshNotifications[d];_.isUndefined(l)&&(l=[{name:e.name,value:[]}],n.datasourceRefreshNotifications[d]=l);var c=l.find(t=>t.name===e.name);_.isUndefined(c)&&(c={name:e.name,value:[]},l.push(c)),_.isUndefined(o[2])&&(o[2]=""),c.value.push(o[2])}}}})}},this._heightUpdate=ko.observable(),this.height=ko.computed({read:function(){return n._heightUpdate(),!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.getHeight)?n.widgetInstance.getHeight():1}}),this.shouldRender=ko.observable(!1),this.render=function(e){n.shouldRender(!1),!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.render)&&(n.widgetInstance.render(e),n.updateCalculatedSettings())},this.dispose=function(){!_.isUndefined(n.widgetInstance)&&_.isFunction(n.widgetInstance.onDispose)&&n.widgetInstance.onDispose()},this.serialize=function(){return{title:n.title(),type:n.type(),settings:n.settings()}},this.deserialize=function(e){n.title(e.title),n.settings(e.settings),n.type(e.type)}}DatasourceModel=function(e,t){var n=this;function i(){_.isUndefined(n.datasourceInstance)||(_.isFunction(n.datasourceInstance.onDispose)&&n.datasourceInstance.onDispose(),n.datasourceInstance=void 0)}this.name=ko.observable(),this.latestData=ko.observable({}),this.settings=ko.observable({}),this.settings.subscribe(function(e){!_.isUndefined(n.datasourceInstance)&&_.isFunction(n.datasourceInstance.onSettingsChanged)&&n.datasourceInstance.onSettingsChanged(e)}),this.updateCallback=function(t){e.processDatasourceUpdate(n,t),Object.assign(n.latestData(),t);var i=new Date;n.last_updated(i.toLocaleTimeString(void 0,{hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3}))},this.type=ko.observable(),this.type.subscribe(function(e){if(i(),e in t&&_.isFunction(t[e].newInstance)){var a=t[e];function s(){a.newInstance(n.settings(),function(e){n.datasourceInstance=e,e.updateNow()},n.updateCallback)}a.external_scripts&&a.external_scripts.length>0?head.js(a.external_scripts.slice(0),s):s()}}),this.last_updated=ko.observable("never"),this.last_error=ko.observable(),this.serialize=function(){return{name:n.name(),type:n.type(),settings:n.settings()}},this.deserialize=function(e){n.settings(e.settings),n.name(e.name),n.type(e.type)},this.getDataRepresentation=function(e){return new Function("data","try { return "+e+"} catch (e) { return undefined };").call(void 0,n.latestData())},this.updateNow=function(){!_.isUndefined(n.datasourceInstance)&&_.isFunction(n.datasourceInstance.updateNow)&&n.datasourceInstance.updateNow()},this.dispose=function(){i()}},DeveloperConsole=function(e){return{showDeveloperConsole:function(){!function(){var t=[],n=$("
"),i=$('ADD
'),a=$('');a.append($('Plugin Script URL '));var s=$(" ");function o(e){var n=$(" "),i=$(''),a=$(' '),o=$(' ').click(function(e){t=_.without(t,a),n.remove()});t.push(a),e&&a.val(e),i.append(o),s.append(n.append($(" ").append(a)).append($('').append(i)))}a.append(s),n.append($("Here you can add references to other scripts to load datasource or widget plugins.
")).append(a).append(i).append('To learn how to build plugins for freeboard, please visit http://freeboard.github.io/freeboard/docs/plugin_example.html
'),_.each(e.plugins(),function(e){o(e)}),i.click(function(e){o()}),new DialogBox(n,"Developer Console","OK",null,function(){_.each(e.plugins(),function(e){$('script[src^="'+e+'"]').remove()}),e.plugins.removeAll(),_.each(t,function(t){var n=t.val();n&&n.length>0&&(e.addPluginSource(n),head.js(n+"?"+Date.now()))})})}()}}},JSEditor=function(){function e(e){e}return{displayJSEditor:function(e,t){!function(e,t){var n='// Example: Convert temp from C to F and truncate to 2 decimal places.\n// return (datasources["MyDatasource"].sensor.tempInF * 1.8 + 32).toFixed(2);';e||(e=n);var i=$('
'),a=$('
'),s=$(''),o=$('');i.append([o,a,s]),$("body").append(i);var r=CodeMirror(a.get(0),{value:e,mode:"javascript",theme:"ambiance",indentUnit:4,lineNumbers:!0,matchBrackets:!0,autoCloseBrackets:!0}),d=$('Close ').click(function(){if(t){var e=r.getValue();e===n&&(e=""),t(e),i.remove()}});s.append(d)}(e,t)},setAssetRoot:function(t){e(t)}}},PluginEditor=function(e,t){function n(e,t){var n=$('
').html(t);$("#setting-value-container-"+e).append(n)}function i(n,i,a,s,o){var r=$("");a.multi_input?r.change(function(){var e=[];$(n).find("textarea").each(function(){var t=$(this).val();t&&(e=e.concat(t))}),i.settings[a.name]=e}):r.change(function(){i.settings[a.name]=$(this).val()}),s&&r.val(s),t.createValueEditor(r);var d=$(''),l=$('
');l.append(r).append(d);var c=$('DATASOURCE ').mousedown(function(e){e.preventDefault(),$(r).val("").focus().insertAtCaret('datasources["').trigger("freeboard-eval")});d.append(c);var u=$('.JS EDITOR ').mousedown(function(t){t.preventDefault(),e.displayJSEditor(r.val(),function(e){r.val(e),r.change()})});if(d.append(u),o){var p=$(' ').mousedown(function(e){e.preventDefault(),l.remove(),$(n).find("textarea:first").change()});d.prepend(p)}$(n).append(l)}function a(e,t,a,s,o){var r,d={type:a,settings:{}};function l(e,t){var n=$('
').appendTo(c);return n.append(''+t+"
"),$('
').appendTo(n)}var c=$("
"),u=$('
').hide();function p(e,t,n){_.each(e,function(e){!_.isUndefined(e.default_value)&&_.isUndefined(s[e.name])&&(s[e.name]=e.default_value);var a=e.name;_.isUndefined(e.display_name)||(a=e.display_name);var o=l(e.name,a);switch(e.type){case"array":{var r=$('
').appendTo(o),c=$('').appendTo(r),u=$(" ").hide().appendTo(c),p=$(" ").appendTo(u),f=$(" ").appendTo(c),h=[];function g(){d.settings[e.name].length>0?u.show():u.hide()}function m(t){var n=$(" ").appendTo(f),i={};_.isArray(d.settings[e.name])||(d.settings[e.name]=[]),d.settings[e.name].push(i),_.each(e.settings,function(e){var a=$(" ").appendTo(n),s="";_.isUndefined(t[e.name])||(s=t[e.name]),i[e.name]=s,$(' ').appendTo(a).val(s).change(function(){i[e.name]=$(this).val()})}),n.append($(' ').append($('').append($(" ").append($(' ').click(function(){var t=d.settings[e.name].indexOf(i);-1!=t&&(d.settings[e.name].splice(t,1),n.remove(),g())}))))),r.scrollTop(r[0].scrollHeight),g()}_.each(e.settings,function(e){var t=e.name;_.isUndefined(e.display_name)||(t=e.display_name),$(""+t+" ").appendTo(p)}),e.name in s&&(h=s[e.name]),$('ADD
').appendTo(o).click(function(){var t={};_.each(e.settings,function(e){t[e.name]=""}),m(t)}),_.each(h,function(e,t){m(e)});break}case"boolean":d.settings[e.name]=s[e.name];var v=$('').appendTo(o),y=$(' ').prependTo(v).change(function(){d.settings[e.name]=this.checked});e.name in s&&y.prop("checked",s[e.name]);break;case"option":var w=s[e.name];y=$(" ").appendTo($('
').appendTo(o)).change(function(){d.settings[e.name]=$(this).val()});_.each(e.options,function(e){var t,n;_.isObject(e)?(t=e.name,n=e.value):t=e,_.isUndefined(n)&&(n=t),_.isUndefined(w)&&(w=n),$(" ").text(t).attr("value",n).appendTo(y)}),d.settings[e.name]=w,e.name in s&&y.val(s[e.name]);break;default:if(d.settings[e.name]=s[e.name],"calculated"==e.type){if(e.name in s){var b=s[e.name];if(e.multi_input&&_.isArray(b))for(var x=!1,C=0;CADD ').mousedown(function(t){t.preventDefault(),i(o,d,e,null,!0)});$(o).siblings(".form-label").append(k)}}else{y=$(' ').appendTo(o).change(function(){"number"==e.type?d.settings[e.name]=Number($(this).val()):"integer"==e.type?d.settings[e.name]=parseInt($(this).val()):d.settings[e.name]=$(this).val()});if(e.name in s&&y.val(s[e.name]),t&&e.typeahead_data_field&&y.addClass("typeahead_data_field-"+e.typeahead_data_field),t&&e.typeahead_field){var S=[];y.keyup(function(e){e.which>=65&&e.which<=91&&y.trigger("change")}),$(y).autocomplete({source:S,select:function(e,t){y.val(t.item.value),y.trigger("change")}}),y.change(function(i){var a=y.val(),s=_.template(t)({input:a});$.get(s,function(t){if(n&&(t=t[n]),t=_.select(t,function(t){return t[e.typeahead_field][0]==a[0]}),S=_.map(t,function(t){return t[e.typeahead_field]}),$(y).autocomplete("option","source",S),1==t.length)for(var i in t=t[0])if(t.hasOwnProperty(i)){var s=$(_.template("input.typeahead_data_field-<%= field %>")({field:i}));s&&(s.val(t[i]),s.val()!=y.val()&&s.trigger("change"))}})})}}}_.isUndefined(e.suffix)||o.append($(''+e.suffix+"
")),_.isUndefined(e.description)||o.append($(''+e.description+"
"))})}c.append(u),new DialogBox(c,e,"Save","Cancel",function(){$(".validation-error").remove();for(var e=0;e0)return n(t.name,i),!0}}var a;_.isFunction(o)&&o(d)});var f,h=_.keys(t);if(h.length>1){var g=l("plugin-types","Type");(f=$(" ").appendTo($('
').appendTo(g))).append($("Select a type... ").attr("value","undefined")),_.each(t,function(e){f.append($(" ").text(e.display_name).attr("value",e.type_name))}),f.change(function(){d.type=$(this).val(),d.settings={},$("#setting-row-instance-name").length?$("#setting-row-instance-name").nextAll().remove():$("#setting-row-plugin-types").nextAll().remove(),r=t[f.val()],_.isUndefined(r)?($("#setting-row-instance-name").hide(),$("#dialog-ok").hide()):($("#setting-row-instance-name").show(),r.description&&r.description.length>0?u.html(r.description).show():u.hide(),$("#dialog-ok").show(),p(r.settings,r.typeahead_source,r.typeahead_data_segment))})}else 1==h.length&&(r=t[h[0]],d.type=r.type_name,d.settings={},p(r.settings));f&&(_.isUndefined(a)?($("#setting-row-instance-name").hide(),$("#dialog-ok").hide()):($("#dialog-ok").show(),f.val(a).trigger("change")))}return{createPluginEditor:function(e,t,n,i,s,o){a(e,t,n,i,s)}}},ValueEditor=function(e){var t=new RegExp('.*datasources\\["([^"]*)("\\])?(.*)$'),n=null,i=0,a=[],s=null,o={ANY:"any",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean"};function r(e,t){return!(!_.isArray(e)&&!_.isObject(e))||d(e,t)}function d(e,t){switch(t){case o.ANY:return!0;case o.ARRAY:return _.isArray(e);case o.OBJECT:return _.isObject(e);case o.STRING:return _.isString(e);case o.NUMBER:return _.isNumber(e);case o.BOOLEAN:return _.isBoolean(e)}}function l(e,t){$(e).parent().find(".validation-error").remove(),d(s,t)||$(e).parent().append("This field expects an expression that evaluates to type "+t+".
")}function c(o,d){var c=$(o).val().substring(0,$(o).getCaretPosition());if(function(e,n,i){var o=t.exec(e),d=[];if(o)if(""==o[1])_.each(n,function(e){d.push({value:e.name(),entity:void 0,precede_char:"",follow_char:'"]'})});else if(""!=o[1]&&_.isUndefined(o[2])){var l=o[1];_.each(n,function(e){var t=e.name();t!=l&&0==t.indexOf(l)&&d.push({value:t,entity:void 0,precede_char:"",follow_char:'"]'})})}else{var c=_.find(n,function(e){return e.name()===o[1]});if(!_.isUndefined(c)){var u="data",p="";if(!_.isUndefined(o[2])){var f=o[3].lastIndexOf("]")+1;u+=o[3].substring(0,f),p=(p=(p=o[3].substring(f,o[3].length)).replace(/^[\[\"]*/,"")).replace(/[\"\]]*$/,"")}var h=c.getDataRepresentation(u);if(s=h,_.isArray(h)){for(var g=0;g0){n||(n=$('').insertAfter(o).width($(o).outerWidth()-2).css("left",$(o).position().left).css("top",$(o).position().top+$(o).outerHeight()-1)),n.empty(),n.scrollTop(0);var u=!0;i=0,_.each(a,function(e,t){var a=function(e,t,a,o){var r=a.value;a.preview&&(r=r+""+a.preview+" ");return $(""+r+" ").appendTo(n).mouseenter(function(){$(this).trigger("freeboard-select")}).mousedown(function(e){$(this).trigger("freeboard-insertValue"),e.preventDefault()}).data("freeboard-optionIndex",o).data("freeboard-optionValue",a.value).bind("freeboard-insertValue",function(){var n=a.value;n=a.precede_char+n+a.follow_char;var i=t.lastIndexOf("]");-1!=i?$(e).replaceTextAt(i+1,$(e).val().length,n):$(e).insertAtCaret(n),s=a.entity,$(e).triggerHandler("mouseup")}).bind("freeboard-select",function(){$(this).parent().find("li.selected").removeClass("selected"),$(this).addClass("selected"),i=$(this).data("freeboard-optionIndex")})}(o,c,e,t);u&&($(a).addClass("selected"),u=!1)})}else l(o,d),$(o).next("ul#value-selector").remove(),n=null,i=-1}function u(e,t){$(e).addClass("calculated-value-input").bind("keyup mouseup freeboard-eval",function(i){!n||"keyup"!=i.type||38!=i.keyCode&&40!=i.keyCode&&13!=i.keyCode?c(e,t):i.preventDefault()}).focus(function(){$(e).css({"z-index":3001}),function(e){var t=($(e).val().match(/\n/g)||[]).length,n=Math.min(200,20*(t+1));$(e).css({height:n+"px"})}(e)}).focusout(function(){l(e,t),$(e).css({height:"","z-index":3e3}),$(e).next("ul#value-selector").remove(),n=null,i=-1}).bind("keydown",function(e){if(n)if(38==e.keyCode||40==e.keyCode){e.preventDefault();var t=$(n).find("li");38==e.keyCode?i--:40==e.keyCode&&i++,i<0?i=t.size()-1:i>=t.size()&&(i=0);var a=$(t).eq(i);a.trigger("freeboard-select"),$(n).scrollTop($(a).position().top)}else 13==e.keyCode&&(e.preventDefault(),-1!=i&&$(n).find("li").eq(i).trigger("freeboard-insertValue"))})}return{createValueEditor:function(e,t){u(e,t||o.ANY)},EXPECTED_TYPE:o}},function(e){var t=window.MutationObserver||window.WebKitMutationObserver;e.fn.attrchange=function(n){var i={trackValues:!1,callback:e.noop};if("function"==typeof n?i.callback=n:e.extend(i,n),i.trackValues&&e(this).each(function(t,n){for(var i,a={},s=(t=0,n.attributes),o=s.length;t=0){i.style||(i.style={});var a=n.attributeName.split(".");n.attributeName=a[0],n.oldValue=i.style[a[1]],n.newValue=a[1]+":"+this.prop("style")[e.camelCase(a[1])],i.style[a[1]]=n.newValue}else n.oldValue=i[n.attributeName],n.newValue=this.attr(n.attributeName),i[n.attributeName]=n.newValue;this.data("attr-old-value",i)}}.call(e(this),i.trackValues,t),i.callback.call(this,t)}):this}}(jQuery),function(e){e.eventEmitter={_JQInit:function(){this._JQ=e(this)},emit:function(e,t){!this._JQ&&this._JQInit(),this._JQ.trigger(e,t)},once:function(e,t){!this._JQ&&this._JQInit(),this._JQ.one(e,t)},on:function(e,t){!this._JQ&&this._JQInit(),this._JQ.bind(e,t)},off:function(e,t){!this._JQ&&this._JQInit(),this._JQ.unbind(e,t)}}}(jQuery);var freeboard=function(){var e={},t={},n=new FreeboardUI(10,300,3),i=new FreeboardModel(e,t,n),a=new JSEditor,s=new ValueEditor(i),o=new PluginEditor(a,s),r=new DeveloperConsole(i),d={values:{"font-family":'"HelveticaNeue-UltraLight", "Helvetica Neue Ultra Light", "Helvetica Neue", sans-serif',color:"#d3d4d4","font-weight":100}};return ko.bindingHandlers.pluginEditor={init:function(a,s,r,d,l){var c=ko.unwrap(s()),u={},p=void 0,f="";"datasource"==c.type?(u=e,f="Datasource"):"widget"==c.type?(u=t,f="Widget"):"pane"==c.type&&(f="Pane"),$(a).click(function(s){if("delete"==c.operation){new DialogBox($("Are you sure you want to delete this "+f+"?
"),"Confirm Delete","Yes","No",function(){"datasource"==c.type?i.deleteDatasource(d):"widget"==c.type?i.deleteWidget(d):"pane"==c.type&&i.deletePane(d)})}else{var r=void 0;"datasource"==c.type?"add"==c.operation?p={}:(r=d.type(),(p=d.settings()).name=d.name()):"widget"==c.type?"add"==c.operation?p={}:(r=d.type(),p=d.settings()):"pane"==c.type&&(p={},"edit"==c.operation&&(p.title=d.title(),p.col_width=d.col_width()),u={settings:{settings:[{name:"title",display_name:"Title",type:"text"},{name:"col_width",display_name:"Columns",type:"integer",default_value:1,required:!0}]}}),o.createPluginEditor(f,u,r,p,function(s){if("add"==c.operation){if("datasource"==c.type){var o=new DatasourceModel(i,e);i.addDatasource(o),o.name(s.settings.name),delete s.settings.name,o.settings(s.settings),o.type(s.type)}else if("widget"==c.type){(o=new WidgetModel(i,t)).settings(s.settings),o.type(s.type),d.widgets.push(o),n.attachWidgetEditIcons(a)}}else"edit"==c.operation&&("pane"==c.type?(d.title(s.settings.title),d.col_width(s.settings.col_width),n.processResize(!1)):("datasource"==c.type&&(d.name(s.settings.name),delete s.settings.name),d.type(s.type),d.settings(s.settings)))})}})}},ko.virtualElements.allowedBindings.datasourceTypeSettings=!0,ko.bindingHandlers.datasourceTypeSettings={update:function(e,t,n,i,a){processPluginSettings(e,t,n,i,a)}},ko.bindingHandlers.pane={init:function(e,t,a,s,o){i.isEditing()&&$(e).css({cursor:"pointer"}),n.addPane(e,s,o.$root.isEditing())},update:function(e,t,a,s,o){-1==i.panes.indexOf(s)&&n.removePane(e),n.updatePane(e,s)}},ko.bindingHandlers.widget={init:function(e,t,a,s,o){i.isEditing()&&n.attachWidgetEditIcons($(e).parent())},update:function(e,t,n,i,a){i.shouldRender()&&($(e).empty(),i.render(e))}},$(function(){var e;function t(){n.processResize(!0)}n.showLoadingIndicator(!0),$(window).resize(function(){clearTimeout(e),e=setTimeout(t,500)})}),{initialize:function(e,t){ko.applyBindings(i);var a=function(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^]*)").exec(location.search);return null==t?"":decodeURIComponent(t[1].replace(/\+/g," "))}("load");""!=a?$.ajax({url:a,success:function(e){i.loadDashboard(e),_.isFunction(t)&&t()}}):(i.allow_edit(e),i.setEditing(e),n.showLoadingIndicator(!1),_.isFunction(t)&&t(),freeboard.emit("initialized"))},newDashboard:function(){i.loadDashboard({allow_edit:!0})},loadDashboard:function(e,t){i.loadDashboard(e,t)},serialize:function(){return i.serialize()},setEditing:function(e,t){i.setEditing(e,t)},isEditing:function(){return i.isEditing()},loadDatasourcePlugin:function(t){_.isUndefined(t.display_name)&&(t.display_name=t.type_name),t.settings.unshift({name:"name",display_name:"Name",type:"text",required:!0}),i.addPluginSource(t.source),e[t.type_name]=t,i._datasourceTypes.valueHasMutated()},resize:function(){n.processResize(!0)},loadWidgetPlugin:function(e){_.isUndefined(e.display_name)&&(e.display_name=e.type_name),i.addPluginSource(e.source),t[e.type_name]=e,i._widgetTypes.valueHasMutated()},setAssetRoot:function(e){a.setAssetRoot(e)},addStyle:function(e,t){var n=e+"{"+t+"}",i=$("style#fb-styles");0==i.length&&(i=$(''),$("head").append(i)),i[0].styleSheet?i[0].styleSheet.cssText+=n:i.text(i.text()+n)},showLoadingIndicator:function(e){n.showLoadingIndicator(e)},showDialog:function(e,t,n,i,a){new DialogBox(e,t,n,i,a)},getDatasourceSettings:function(e){var t=i.datasources(),n=_.find(t,function(t){return t.name()===e});return n?n.settings():null},setDatasourceSettings:function(e,t){var n=i.datasources(),a=_.find(n,function(t){return t.name()===e});if(a){var s=_.defaults(t,a.settings());a.settings(s)}else console.log("Datasource not found")},getStyleString:function(e){var t="";return _.each(d[e],function(e,n){t=t+n+":"+e+";"}),t},getStyleObject:function(e){return d[e]},showDeveloperConsole:function(){r.showDeveloperConsole()}}}();$.extend(freeboard,jQuery.eventEmitter),function(){freeboard.loadDatasourcePlugin({type_name:"JSON",settings:[{name:"url",display_name:"URL",type:"text"},{name:"use_thingproxy",display_name:"Try thingproxy",description:'A direct JSON connection will be tried first, if that fails, a JSONP connection will be tried. If that fails, you can use thingproxy, which can solve many connection problems to APIs. More information .',type:"boolean",default_value:!0},{name:"refresh",display_name:"Refresh Every",type:"number",suffix:"seconds",default_value:5},{name:"method",display_name:"Method",type:"option",options:[{name:"GET",value:"GET"},{name:"POST",value:"POST"},{name:"PUT",value:"PUT"},{name:"DELETE",value:"DELETE"}]},{name:"body",display_name:"Body",type:"text",description:"The body of the request. Normally only used if method is POST"},{name:"headers",display_name:"Headers",type:"array",settings:[{name:"name",display_name:"Name",type:"text"},{name:"value",display_name:"Value",type:"text"}]}],newInstance:function(e,t,n){t(new function(e,t){var n=this,i=null,a=e,s=0,o=!1;function r(e){i&&clearInterval(i),i=setInterval(function(){n.updateNow()},e)}r(1e3*a.refresh),this.updateNow=function(){if(!(s>1&&!a.use_thingproxy||s>2)){var e=a.url;2==s&&a.use_thingproxy&&(e=("https:"==location.protocol?"https:":"http:")+"//thingproxy.freeboard.io/fetch/"+encodeURI(a.url));var i=a.body;if(i)try{i=JSON.parse(i)}catch(e){}$.ajax({url:e,dataType:1==s?"JSONP":"JSON",type:a.method||"GET",data:i,beforeSend:function(e){try{_.each(a.headers,function(t){var n=t.name,i=t.value;_.isUndefined(n)||_.isUndefined(i)||e.setRequestHeader(n,i)})}catch(e){}},success:function(e){o=!0,t(e)},error:function(e,t,i){o||(s++,n.updateNow())}})}},this.onDispose=function(){clearInterval(i),i=null},this.onSettingsChanged=function(e){o=!1,s=0,r(1e3*(a=e).refresh),n.updateNow()}}(e,n))}});freeboard.loadDatasourcePlugin({type_name:"openweathermap",display_name:"Open Weather Map API",settings:[{name:"api_key",display_name:"API Key",type:"text",description:"Your personal API Key from Open Weather Map"},{name:"location",display_name:"Location",type:"text",description:"Example: London, UK"},{name:"units",display_name:"Units",type:"option",default:"imperial",options:[{name:"Imperial",value:"imperial"},{name:"Metric",value:"metric"}]},{name:"refresh",display_name:"Refresh Every",type:"number",suffix:"seconds",default_value:5}],newInstance:function(e,t,n){t(new function(e,t){var n=this,i=null,a=e;function s(e){i&&clearInterval(i),i=setInterval(function(){n.updateNow()},e)}s(1e3*a.refresh),this.updateNow=function(){$.ajax({url:"http://api.openweathermap.org/data/2.5/weather?APPID="+a.api_key+"&q="+encodeURIComponent(a.location)+"&units="+a.units,dataType:"JSONP",success:function(e){var n,i={place_name:e.name,sunrise:new Date(1e3*e.sys.sunrise).toLocaleTimeString(),sunset:new Date(1e3*e.sys.sunset).toLocaleTimeString(),conditions:(n=e.weather[0].description,n.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()})),current_temp:e.main.temp,high_temp:e.main.temp_max,low_temp:e.main.temp_min,pressure:e.main.pressure,humidity:e.main.humidity,wind_speed:e.wind.speed,wind_direction:e.wind.deg};t(i)},error:function(e,t,n){}})},this.onDispose=function(){clearInterval(i),i=null},this.onSettingsChanged=function(e){a=e,n.updateNow(),s(1e3*a.refresh)}}(e,n))}});freeboard.loadDatasourcePlugin({type_name:"dweet_io",display_name:"Dweet.io",external_scripts:["http://dweet.io/client/dweet.io.min.js"],settings:[{name:"thing_id",display_name:"Thing Name",description:"Example: salty-dog-1",type:"text"}],newInstance:function(e,t,n){t(new function(e,t){var n=e;function i(e){t(e)}this.updateNow=function(){dweetio.get_latest_dweet_for(n.thing_id,function(e,t){e||i(t[0].content)})},this.onDispose=function(){},this.onSettingsChanged=function(e){dweetio.stop_listening_for(n.thing_id),n=e,dweetio.listen_for(n.thing_id,function(e){i(e.content)})},this.onSettingsChanged(e)}(e,n))}});freeboard.loadDatasourcePlugin({type_name:"playback",display_name:"Playback",settings:[{name:"datafile",display_name:"Data File URL",type:"text",description:"A link to a JSON array of data."},{name:"is_jsonp",display_name:"Is JSONP",type:"boolean"},{name:"loop",display_name:"Loop",type:"boolean",description:"Rewind and loop when finished"},{name:"refresh",display_name:"Refresh Every",type:"number",suffix:"seconds",default_value:5}],newInstance:function(e,t,n){t(new function(e,t){var n,i=this,a=e,s=[],o=0;function r(){s.length>0?(o=s.length&&a.loop&&(o=0),o=e&&s[n].shift(),s[n].push(Number(t)),(void 0===o||tr)&&(r=t)};_.isArray(i)?_.each(i,d):d(i,0),$(n).data().values=s,$(n).data().valueMin=o,$(n).data().valueMax=r;var l='● {{y}}',c=!1;_.each(s,function(e,i){$(n).sparkline(e,{type:"line",composite:c,height:"100%",width:"100%",fillColor:!1,lineColor:t[i%t.length],lineWidth:2,spotRadius:3,spotColor:!1,minSpotColor:"#78AB49",maxSpotColor:"#78AB49",highlightSpotColor:"#9D3926",highlightLineColor:"#9D3926",chartRangeMin:o,chartRangeMax:r,tooltipFormat:a&&a[i]?l+" ("+a[i]+")":l}),c=!0})}var i=freeboard.getStyleString("values");freeboard.addStyle(".widget-big-text",i+"font-size:75px;"),freeboard.addStyle(".tw-display","width: 100%; height:100%; display:table; table-layout:fixed;"),freeboard.addStyle(".tw-tr","display:table-row;"),freeboard.addStyle(".tw-tg","display:table-row-group;"),freeboard.addStyle(".tw-tc","display:table-caption;"),freeboard.addStyle(".tw-td","display:table-cell;"),freeboard.addStyle(".tw-value",i+"overflow: hidden;display: inline-block;text-overflow: ellipsis;"),freeboard.addStyle(".tw-unit","display: inline-block;padding-left: 10px;padding-bottom: 1.1em;vertical-align: bottom;"),freeboard.addStyle(".tw-value-wrapper","position: relative;vertical-align: middle;height:100%;"),freeboard.addStyle(".tw-sparkline","height:20px;");var a=function(e){var t=e,i=$('
'),a=$(' '),s=$('
'),o=$('
'),r=$('
');function d(){_.isUndefined(t.units)||""==t.units?s.css("max-width","100%"):s.css("max-width",i.innerWidth()-o.outerWidth(!0)+"px")}this.render=function(e){$(e).empty(),$(i).append($('
').append(a)).append($('
').append($('
').append(s).append(o))).append($('
').append(r)),$(e).append(i),d()},this.onSettingsChanged=function(e){t=e;var n=!_.isUndefined(e.title)&&""!=e.title,i=!_.isUndefined(e.units)&&""!=e.units;e.sparkline?r.attr("style",null):(delete r.data().values,r.empty(),r.hide()),n?(a.html(_.isUndefined(e.title)?"":e.title),a.attr("style",null)):(a.empty(),a.hide()),i?(o.html(_.isUndefined(e.units)?"":e.units),o.attr("style",null)):(o.empty(),o.hide());var l=30;"big"==e.size&&(l=75,e.sparkline&&(l=60)),s.css({"font-size":l+"px"}),d()},this.onSizeChanged=function(){d()},this.onCalculatedValueChanged=function(e,i){"value"==e&&(t.animate?function(e,t,n){var i=$(t).text();if(i!=e)if($.isNumeric(e)&&$.isNumeric(i)){var a=e.toString().split("."),s=0;a.length>1&&(s=a[1].length);var o=0;(a=i.toString().split(".")).length>1&&(o=a[1].length),jQuery({transitionValue:Number(i),precisionValue:o}).animate({transitionValue:Number(e),precisionValue:s},{duration:n,step:function(){$(t).text(this.transitionValue.toFixed(this.precisionValue))},done:function(){$(t).text(e)}})}else $(t).text(e)}(i,s,500):s.text(i),t.sparkline&&n(r,i))},this.onDispose=function(){},this.getHeight=function(){return"big"==t.size||t.sparkline?2:1},this.onSettingsChanged(e)};freeboard.loadWidgetPlugin({type_name:"text_widget",display_name:"Text",external_scripts:["plugins/thirdparty/jquery.sparkline.min.js"],settings:[{name:"title",display_name:"Title",type:"text"},{name:"size",display_name:"Size",type:"option",options:[{name:"Regular",value:"regular"},{name:"Big",value:"big"}]},{name:"value",display_name:"Value",type:"calculated"},{name:"sparkline",display_name:"Include Sparkline",type:"boolean"},{name:"animate",display_name:"Animate Value Changes",type:"boolean",default_value:!0},{name:"units",display_name:"Units",type:"text"}],newInstance:function(e,t){t(new a(e))}});var s=0;freeboard.addStyle(".gauge-widget-wrapper","width: 100%;text-align: center;"),freeboard.addStyle(".gauge-widget","width:200px;height:160px;display:inline-block;");freeboard.loadWidgetPlugin({type_name:"gauge",display_name:"Gauge",external_scripts:["plugins/thirdparty/raphael.2.1.0.min.js","plugins/thirdparty/justgage.1.0.1.js"],settings:[{name:"title",display_name:"Title",type:"text"},{name:"value",display_name:"Value",type:"calculated"},{name:"units",display_name:"Units",type:"text"},{name:"min_value",display_name:"Minimum",type:"text",default_value:0},{name:"max_value",display_name:"Maximum",type:"text",default_value:100}],newInstance:function(e,t){t(new function(e){var t,n="gauge-"+s++,i=$(' '),a=$('
'),o=!1,r=e;function d(){o&&(a.empty(),t=new JustGage({id:n,value:_.isUndefined(r.min_value)?0:r.min_value,min:_.isUndefined(r.min_value)?0:r.min_value,max:_.isUndefined(r.max_value)?0:r.max_value,label:r.units,showInnerShadow:!1,valueFontColor:"#d3d4d4"}))}this.render=function(e){o=!0,$(e).append(i).append($('
').append(a)),d()},this.onSettingsChanged=function(e){e.min_value!=r.min_value||e.max_value!=r.max_value||e.units!=r.units?(r=e,d()):r=e,i.html(e.title)},this.onCalculatedValueChanged=function(e,n){_.isUndefined(t)||t.refresh(Number(n))},this.onDispose=function(){},this.getHeight=function(){return 3},this.onSettingsChanged(e)}(e))}}),freeboard.addStyle(".sparkline","width:100%;height: 75px;");var o=function(e){var i=$(' '),a=$('
'),s=$("
"),o=e;this.render=function(e){$(e).append(i).append(a).append(s)},this.onSettingsChanged=function(e){o=e,i.html(_.isUndefined(e.title)?"":e.title),e.include_legend&&function(e,n){for(var i=$("
"),a=0;a● "+o+"")}e.empty().append(i),freeboard.addStyle(".sparkline-legend","margin:5px;"),freeboard.addStyle(".sparkline-legend-value","color:white; font:10px arial,san serif; float:left; overflow:hidden; width:50%;"),freeboard.addStyle(".sparkline-legend-value span","font-weight:bold; padding-right:5px;")}(s,e.legend.split(","))},this.onCalculatedValueChanged=function(e,t){o.legend?n(a,t,o.legend.split(",")):n(a,t)},this.onDispose=function(){},this.getHeight=function(){var e=0;if(o.include_legend&&o.legend){var t=o.legend.split(",").length;t>4?e=.5*Math.floor((t-1)/4):t&&(e=.5)}return 2+e},this.onSettingsChanged(e)};freeboard.loadWidgetPlugin({type_name:"sparkline",display_name:"Sparkline",external_scripts:["plugins/thirdparty/jquery.sparkline.min.js"],settings:[{name:"title",display_name:"Title",type:"text"},{name:"value",display_name:"Value",type:"calculated",multi_input:"true"},{name:"include_legend",display_name:"Include Legend",type:"boolean"},{name:"legend",display_name:"Legend",type:"text",description:"Comma-separated for multiple sparklines"}],newInstance:function(e,t){t(new o(e))}}),freeboard.addStyle("div.pointer-value","position:absolute;height:95px;margin: auto;top: 0px;bottom: 0px;width: 100%;text-align:center;");freeboard.loadWidgetPlugin({type_name:"pointer",display_name:"Pointer",external_scripts:["plugins/thirdparty/raphael.2.1.0.min.js"],settings:[{name:"direction",display_name:"Direction",type:"calculated",description:"In degrees"},{name:"value_text",display_name:"Value Text",type:"calculated"},{name:"units",display_name:"Units",type:"text"}],newInstance:function(e,t){t(new function(e){var t,n,i,a,s=$('
'),o=$("
");this.render=function(e){i=$(e).width(),a=$(e).height();var r=Math.min(i,a)/2-6,d=(t=Raphael($(e).get()[0],i,a)).circle(i/2,a/2,r);d.attr("stroke","#FF9900"),d.attr("stroke-width",3),(n=t.path(function(e){if(!e||e.length<2)return[];var t=[];t.push(["m",e[0],e[1]]);for(var n=2;n').append(s).append(o))},this.onSettingsChanged=function(e){o.html(e.units)},this.onCalculatedValueChanged=function(e,t){"direction"==e?_.isUndefined(n)||n.animate({transform:"r"+t+","+i/2+","+a/2},250,"bounce"):"value_text"==e&&s.html(t)},this.onDispose=function(){},this.getHeight=function(){return 4},this.onSettingsChanged(e)}(e))}});freeboard.loadWidgetPlugin({type_name:"picture",display_name:"Picture",fill_size:!0,settings:[{name:"src",display_name:"Image URL",type:"calculated"},{type:"number",display_name:"Refresh every",name:"refresh",suffix:"seconds",description:"Leave blank if the image doesn't need to be refreshed"}],newInstance:function(e,t){t(new function(e){var t,n,i;function a(){n&&(clearInterval(n),n=null)}function s(){if(t&&i){var e=i+(-1==i.indexOf("?")?"?":"&")+Date.now();$(t).css({"background-image":"url("+e+")"})}}this.render=function(e){$(e).css({width:"100%",height:"100%","background-size":"cover","background-position":"center"}),t=e},this.onSettingsChanged=function(e){a(),e.refresh&&e.refresh>0&&(n=setInterval(s,1e3*Number(e.refresh)))},this.onCalculatedValueChanged=function(e,t){"src"==e&&(i=t),s()},this.onDispose=function(){a()},this.getHeight=function(){return 4},this.onSettingsChanged(e)}(e))}}),freeboard.addStyle(".indicator-light","border-radius:50%;width:22px;height:22px;border:2px solid #3d3d3d;margin-top:5px;float:left;background-color:#222;margin-right:10px;"),freeboard.addStyle(".indicator-light.on","background-color:#FFC773;box-shadow: 0px 0px 15px #FF9900;border-color:#FDF1DF;"),freeboard.addStyle(".indicator-text","margin-top:10px;");freeboard.loadWidgetPlugin({type_name:"indicator",display_name:"Indicator Light",settings:[{name:"title",display_name:"Title",type:"text"},{name:"value",display_name:"Value",type:"calculated"},{name:"on_text",display_name:"On Text",type:"calculated"},{name:"off_text",display_name:"Off Text",type:"calculated"}],newInstance:function(e,t){t(new function(e){var t,n,i=$(' '),a=$('
'),s=$('
'),o=e,r=!1;function d(){s.toggleClass("on",r),r?a.text(_.isUndefined(t)?_.isUndefined(o.on_text)?"":o.on_text:t):a.text(_.isUndefined(n)?_.isUndefined(o.off_text)?"":o.off_text:n)}this.render=function(e){$(e).append(i).append(s).append(a)},this.onSettingsChanged=function(e){o=e,i.html(_.isUndefined(e.title)?"":e.title),d()},this.onCalculatedValueChanged=function(e,i){"value"==e&&(r=Boolean(i)),"on_text"==e&&(t=i),"off_text"==e&&(n=i),d()},this.onDispose=function(){},this.getHeight=function(){return 1},this.onSettingsChanged(e)}(e))}}),freeboard.addStyle(".gm-style-cc a","text-shadow:none;");freeboard.loadWidgetPlugin({type_name:"google_map",display_name:"Google Map",fill_size:!0,settings:[{name:"lat",display_name:"Latitude",type:"calculated"},{name:"lon",display_name:"Longitude",type:"calculated"}],newInstance:function(e,t){t(new function(e){var t,n,i={};function a(){if(t&&n&&i.lat&&i.lon){var e=new google.maps.LatLng(i.lat,i.lon);n.setPosition(e),t.panTo(e)}}this.render=function(e){function i(){var i={zoom:13,center:new google.maps.LatLng(37.235,-115.811111),disableDefaultUI:!0,draggable:!1,styles:[{featureType:"water",elementType:"geometry",stylers:[{color:"#2a2a2a"}]},{featureType:"landscape",elementType:"geometry",stylers:[{color:"#000000"},{lightness:20}]},{featureType:"road.highway",elementType:"geometry.fill",stylers:[{color:"#000000"},{lightness:17}]},{featureType:"road.highway",elementType:"geometry.stroke",stylers:[{color:"#000000"},{lightness:29},{weight:.2}]},{featureType:"road.arterial",elementType:"geometry",stylers:[{color:"#000000"},{lightness:18}]},{featureType:"road.local",elementType:"geometry",stylers:[{color:"#000000"},{lightness:16}]},{featureType:"poi",elementType:"geometry",stylers:[{color:"#000000"},{lightness:21}]},{elementType:"labels.text.stroke",stylers:[{visibility:"on"},{color:"#000000"},{lightness:16}]},{elementType:"labels.text.fill",stylers:[{saturation:36},{color:"#000000"},{lightness:40}]},{elementType:"labels.icon",stylers:[{visibility:"off"}]},{featureType:"transit",elementType:"geometry",stylers:[{color:"#000000"},{lightness:19}]},{featureType:"administrative",elementType:"geometry.fill",stylers:[{color:"#000000"},{lightness:20}]},{featureType:"administrative",elementType:"geometry.stroke",stylers:[{color:"#000000"},{lightness:17},{weight:1.2}]}]};t=new google.maps.Map(e,i),google.maps.event.addDomListener(e,"mouseenter",function(e){e.cancelBubble=!0,t.hover||(t.hover=!0,t.setOptions({zoomControl:!0}))}),google.maps.event.addDomListener(e,"mouseleave",function(e){t.hover&&(t.setOptions({zoomControl:!1}),t.hover=!1)}),n=new google.maps.Marker({map:t}),a()}window.google&&window.google.maps?i():(window.gmap_initialize=i,head.js("https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=gmap_initialize"))},this.onSettingsChanged=function(e){},this.onCalculatedValueChanged=function(e,t){"lat"==e?i.lat=t:"lon"==e&&(i.lon=t),a()},this.onDispose=function(){},this.getHeight=function(){return 4},this.onSettingsChanged(e)}(e))}}),freeboard.addStyle(".html-widget","white-space:normal;width:100%;height:100%");freeboard.loadWidgetPlugin({type_name:"html",display_name:"HTML",fill_size:!0,settings:[{name:"html",display_name:"HTML",type:"calculated",description:"Can be literal HTML, or javascript that outputs HTML."},{name:"height",display_name:"Height Blocks",type:"number",default_value:4,description:"A height block is around 60 pixels"}],newInstance:function(e,t){t(new function(e){var t=$('
'),n=e;this.render=function(e){$(e).append(t)},this.onSettingsChanged=function(e){n=e},this.onCalculatedValueChanged=function(e,n){"html"==e&&t.html(n)},this.onDispose=function(){},this.getHeight=function(){return Number(n.height)},this.onSettingsChanged(e)}(e))}})}();
\ No newline at end of file
diff --git a/lib/js/freeboard/PluginEditor.js b/lib/js/freeboard/PluginEditor.js
index 854cb8f0..6fa41823 100644
--- a/lib/js/freeboard/PluginEditor.js
+++ b/lib/js/freeboard/PluginEditor.js
@@ -338,6 +338,10 @@ PluginEditor = function(jsEditor, valueEditor)
{
newSettings.settings[settingDef.name] = Number($(this).val());
}
+ else if (settingDef.type == "integer")
+ {
+ newSettings.settings[settingDef.name] = parseInt($(this).val());
+ }
else
{
newSettings.settings[settingDef.name] = $(this).val();