Skip to content
Browse files

DRY top connected edge

  • Loading branch information...
1 parent 8880c7e commit a86602204ef2130cdfce7d5e33284653540652e1 @forresto forresto committed
Showing with 17 additions and 27 deletions.
  1. +1 −1 iframework-min.js
  2. +2 −3 iframework.css
  3. +14 −23 js/iframework-port-view.js
View
2 iframework-min.js
@@ -41,4 +41,4 @@ If the AGPL suits your project better you are also free to use Meemoo under that
http://meemoo.org/iframework/LICENSE-AGPL.txt
*/"",function(){function A(a,b,c){if(a===b)return a!==0||1/a==1/b;if(a==null||b==null)return a===b;a._chain&&(a=a._wrapped),b._chain&&(b=b._wrapped);if(a.isEqual&&w.isFunction(a.isEqual))return a.isEqual(b);if(b.isEqual&&w.isFunction(b.isEqual))return b.isEqual(a);var d=i.call(a);if(d!=i.call(b))return!1;switch(d){case"[object String]":return a==String(b);case"[object Number]":return a!=+a?b!=+b:a==0?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if(typeof a!="object"||typeof b!="object")return!1;var e=c.length;while(e--)if(c[e]==a)return!0;c.push(a);var f=0,g=!0;if(d=="[object Array]"){f=a.length,g=f==b.length;if(g)while(f--)if(!(g=f in a==f in b&&A(a[f],b[f],c)))break}else{if("constructor"in a!="constructor"in b||a.constructor!=b.constructor)return!1;for(var h in a)if(w.has(a,h)){f++;if(!(g=w.has(b,h)&&A(a[h],b[h],c)))break}if(g){for(h in b)if(w.has(b,h)&&!(f--))break;g=!f}}return c.pop(),g}var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.slice,h=d.unshift,i=e.toString,j=e.hasOwnProperty,k=d.forEach,l=d.map,m=d.reduce,n=d.reduceRight,o=d.filter,p=d.every,q=d.some,r=d.indexOf,s=d.lastIndexOf,t=Array.isArray,u=Object.keys,v=f.bind,w=function(a){return new I(a)};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=w),exports._=w):a._=w,w.VERSION="1.3.2";var x=w.each=w.forEach=function(a,b,d){if(a==null)return;if(k&&a.forEach===k)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;e<f;e++)if(e in a&&b.call(d,a[e],e,a)===c)return}else for(var g in a)if(w.has(a,g)&&b.call(d,a[g],g,a)===c)return};w.map=w.collect=function(a,b,c){var d=[];return a==null?d:l&&a.map===l?a.map(b,c):(x(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),a.length===+a.length&&(d.length=a.length),d)},w.reduce=w.foldl=w.inject=function(a,b,c,d){var e=arguments.length>2;a==null&&(a=[]);if(m&&a.reduce===m)return d&&(b=w.bind(b,d)),e?a.reduce(b,c):a.reduce(b);x(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)});if(!e)throw new TypeError("Reduce of empty array with no initial value");return c},w.reduceRight=w.foldr=function(a,b,c,d){var e=arguments.length>2;a==null&&(a=[]);if(n&&a.reduceRight===n)return d&&(b=w.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=w.toArray(a).reverse();return d&&!e&&(b=w.bind(b,d)),e?w.reduce(f,b,c,d):w.reduce(f,b)},w.find=w.detect=function(a,b,c){var d;return y(a,function(a,e,f){if(b.call(c,a,e,f))return d=a,!0}),d},w.filter=w.select=function(a,b,c){var d=[];return a==null?d:o&&a.filter===o?a.filter(b,c):(x(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},w.reject=function(a,b,c){var d=[];return a==null?d:(x(a,function(a,e,f){b.call(c,a,e,f)||(d[d.length]=a)}),d)},w.every=w.all=function(a,b,d){var e=!0;return a==null?e:p&&a.every===p?a.every(b,d):(x(a,function(a,f,g){if(!(e=e&&b.call(d,a,f,g)))return c}),!!e)};var y=w.some=w.any=function(a,b,d){b||(b=w.identity);var e=!1;return a==null?e:q&&a.some===q?a.some(b,d):(x(a,function(a,f,g){if(e||(e=b.call(d,a,f,g)))return c}),!!e)};w.include=w.contains=function(a,b){var c=!1;return a==null?c:r&&a.indexOf===r?a.indexOf(b)!=-1:(c=y(a,function(a){return a===b}),c)},w.invoke=function(a,b){var c=g.call(arguments,2);return w.map(a,function(a){return(w.isFunction(b)?b||a:a[b]).apply(a,c)})},w.pluck=function(a,b){return w.map(a,function(a){return a[b]})},w.max=function(a,b,c){if(!b&&w.isArray(a)&&a[0]===+a[0])return Math.max.apply(Math,a);if(!b&&w.isEmpty(a))return-Infinity;var d={computed:-Infinity};return x(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},w.min=function(a,b,c){if(!b&&w.isArray(a)&&a[0]===+a[0])return Math.min.apply(Math,a);if(!b&&w.isEmpty(a))return Infinity;var d={computed:Infinity};return x(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g<d.computed&&(d={value:a,computed:g})}),d.value},w.shuffle=function(a){var b=[],c;return x(a,function(a,d,e){c=Math.floor(Math.random()*(d+1)),b[d]=b[c],b[c]=a}),b},w.sortBy=function(a,b,c){var d=w.isFunction(b)?b:function(a){return a[b]};return w.pluck(w.map(a,function(a,b,e){return{value:a,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c===void 0?1:d===void 0?-1:c<d?-1:c>d?1:0}),"value")},w.groupBy=function(a,b){var c={},d=w.isFunction(b)?b:function(a){return a[b]};return x(a,function(a,b){var e=d(a,b);(c[e]||(c[e]=[])).push(a)}),c},w.sortedIndex=function(a,b,c){c||(c=w.identity);var d=0,e=a.length;while(d<e){var f=d+e>>1;c(a[f])<c(b)?d=f+1:e=f}return d},w.toArray=function(a){return a?w.isArray(a)?g.call(a):w.isArguments(a)?g.call(a):a.toArray&&w.isFunction(a.toArray)?a.toArray():w.values(a):[]},w.size=function(a){return w.isArray(a)?a.length:w.keys(a).length},w.first=w.head=w.take=function(a,b,c){return b!=null&&!c?g.call(a,0,b):a[0]},w.initial=function(a,b,c){return g.call(a,0,a.length-(b==null||c?1:b))},w.last=function(a,b,c){return b!=null&&!c?g.call(a,Math.max(a.length-b,0)):a[a.length-1]},w.rest=w.tail=function(a,b,c){return g.call(a,b==null||c?1:b)},w.compact=function(a){return w.filter(a,function(a){return!!a})},w.flatten=function(a,b){return w.reduce(a,function(a,c){return w.isArray(c)?a.concat(b?c:w.flatten(c)):(a[a.length]=c,a)},[])},w.without=function(a){return w.difference(a,g.call(arguments,1))},w.uniq=w.unique=function(a,b,c){var d=c?w.map(a,c):a,e=[];return a.length<3&&(b=!0),w.reduce(d,function(c,d,f){if(b?w.last(c)!==d||!c.length:!w.include(c,d))c.push(d),e.push(a[f]);return c},[]),e},w.union=function(){return w.uniq(w.flatten(arguments,!0))},w.intersection=w.intersect=function(a){var b=g.call(arguments,1);return w.filter(w.uniq(a),function(a){return w.every(b,function(b){return w.indexOf(b,a)>=0})})},w.difference=function(a){var b=w.flatten(g.call(arguments,1),!0);return w.filter(a,function(a){return!w.include(b,a)})},w.zip=function(){var a=g.call(arguments),b=w.max(w.pluck(a,"length")),c=new Array(b);for(var d=0;d<b;d++)c[d]=w.pluck(a,""+d);return c},w.indexOf=function(a,b,c){if(a==null)return-1;var d,e;if(c)return d=w.sortedIndex(a,b),a[d]===b?d:-1;if(r&&a.indexOf===r)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===b)return d;return-1},w.lastIndexOf=function(a,b){if(a==null)return-1;if(s&&a.lastIndexOf===s)return a.lastIndexOf(b);var c=a.length;while(c--)if(c in a&&a[c]===b)return c;return-1},w.range=function(a,b,c){arguments.length<=1&&(b=a||0,a=0),c=arguments[2]||1;var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);while(e<d)f[e++]=a,a+=c;return f};var z=function(){};w.bind=function(b,c){var d,e;if(b.bind===v&&v)return v.apply(b,g.call(arguments,1));if(!w.isFunction(b))throw new TypeError;return e=g.call(arguments,2),d=function(){if(this instanceof d){z.prototype=b.prototype;var a=new z,f=b.apply(a,e.concat(g.call(arguments)));return Object(f)===f?f:a}return b.apply(c,e.concat(g.call(arguments)))}},w.bindAll=function(a){var b=g.call(arguments,1);return b.length==0&&(b=w.functions(a)),x(b,function(b){a[b]=w.bind(a[b],a)}),a},w.memoize=function(a,b){var c={};return b||(b=w.identity),function(){var d=b.apply(this,arguments);return w.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},w.delay=function(a,b){var c=g.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},w.defer=function(a){return w.delay.apply(w,[a,1].concat(g.call(arguments,1)))},w.throttle=function(a,b){var c,d,e,f,g,h,i=w.debounce(function(){g=f=!1},b);return function(){c=this,d=arguments;var j=function(){e=null,g&&a.apply(c,d),i()};return e||(e=setTimeout(j,b)),f?g=!0:h=a.apply(c,d),i(),f=!0,h}},w.debounce=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)};c&&!d&&a.apply(e,f),clearTimeout(d),d=setTimeout(g,b)}},w.once=function(a){var b=!1,c;return function(){return b?c:(b=!0,c=a.apply(this,arguments))}},w.wrap=function(a,b){return function(){var c=[a].concat(g.call(arguments,0));return b.apply(this,c)}},w.compose=function(){var a=arguments;return function(){var b=arguments;for(var c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},w.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}},w.keys=u||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)w.has(a,c)&&(b[b.length]=c);return b},w.values=function(a){return w.map(a,w.identity)},w.functions=w.methods=function(a){var b=[];for(var c in a)w.isFunction(a[c])&&b.push(c);return b.sort()},w.extend=function(a){return x(g.call(arguments,1),function(b){for(var c in b)a[c]=b[c]}),a},w.pick=function(a){var b={};return x(w.flatten(g.call(arguments,1)),function(c){c in a&&(b[c]=a[c])}),b},w.defaults=function(a){return x(g.call(arguments,1),function(b){for(var c in b)a[c]==null&&(a[c]=b[c])}),a},w.clone=function(a){return w.isObject(a)?w.isArray(a)?a.slice():w.extend({},a):a},w.tap=function(a,b){return b(a),a},w.isEqual=function(a,b){return A(a,b,[])},w.isEmpty=function(a){if(a==null)return!0;if(w.isArray(a)||w.isString(a))return a.length===0;for(var b in a)if(w.has(a,b))return!1;return!0},w.isElement=function(a){return!!a&&a.nodeType==1},w.isArray=t||function(a){return i.call(a)=="[object Array]"},w.isObject=function(a){return a===Object(a)},w.isArguments=function(a){return i.call(a)=="[object Arguments]"},w.isArguments(arguments)||(w.isArguments=function(a){return!!a&&!!w.has(a,"callee")}),w.isFunction=function(a){return i.call(a)=="[object Function]"},w.isString=function(a){return i.call(a)=="[object String]"},w.isNumber=function(a){return i.call(a)=="[object Number]"},w.isFinite=function(a){return w.isNumber(a)&&isFinite(a)},w.isNaN=function(a){return a!==a},w.isBoolean=function(a){return a===!0||a===!1||i.call(a)=="[object Boolean]"},w.isDate=function(a){return i.call(a)=="[object Date]"},w.isRegExp=function(a){return i.call(a)=="[object RegExp]"},w.isNull=function(a){return a===null},w.isUndefined=function(a){return a===void 0},w.has=function(a,b){return j.call(a,b)},w.noConflict=function(){return a._=b,this},w.identity=function(a){return a},w.times=function(a,b,c){for(var d=0;d<a;d++)b.call(c,d)},w.escape=function(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;")},w.result=function(a,b){if(a==null)return null;var c=a[b];return w.isFunction(c)?c.call(a):c},w.mixin=function(a){x(w.functions(a),function(b){K(b,w[b]=a[b])})};var B=0;w.uniqueId=function(a){var b=B++;return a?a+b:b},w.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var C=/.^/,D={"\\":"\\","'":"'",r:"\r",n:"\n",t:" ",u2028:"\u2028",u2029:"\u2029"};for(var E in D)D[D[E]]=E;var F=/\\|'|\r|\n|\t|\u2028|\u2029/g,G=/\\(\\|'|r|n|t|u2028|u2029)/g,H=function(a){return a.replace(G,function(a,b){return D[b]})};w.template=function(a,b,c){c=w.extend(w.templateSettings,c);var d="__p+='"+a.replace(F,function(a){return"\\"+D[a]}).replace(c.escape||C,function(a,b){return"'+\n_.escape("+H(b)+")+\n'"}).replace(c.interpolate||C,function(a,b){return"'+\n("+H(b)+")+\n'"}).replace(c.evaluate||C,function(a,b){return"';\n"+H(b)+"\n;__p+='"})+"';\n";c.variable||(d="with(obj||{}){\n"+d+"}\n"),d="var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n"+d+"return __p;\n";var e=new Function(c.variable||"obj","_",d);if(b)return e(b,w);var f=function(a){return e.call(this,a,w)};return f.source="function("+(c.variable||"obj")+"){\n"+d+"}",f},w.chain=function(a){return w(a).chain()};var I=function(a){this._wrapped=a};w.prototype=I.prototype;var J=function(a,b){return b?w(a).chain():a},K=function(a,b){I.prototype[a]=function(){var a=g.call(arguments);return h.call(a,this._wrapped),J(b.apply(w,a),this._chain)}};w.mixin(w),x(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];I.prototype[a]=function(){var c=this._wrapped;b.apply(c,arguments);var d=c.length;return(a=="shift"||a=="splice")&&d===0&&delete c[0],J(c,this._chain)}}),x(["concat","join","slice"],function(a){var b=d[a];I.prototype[a]=function(){return J(b.apply(this._wrapped,arguments),this._chain)}}),I.prototype.chain=function(){return this._chain=!0,this},I.prototype.value=function(){return this._wrapped}}.call(this),function(){var a=this,b=a.Backbone,c=Array.prototype.slice,d=Array.prototype.splice,e;typeof exports!="undefined"?e=exports:e=a.Backbone={},e.VERSION="0.9.2";var f=a._;!f&&typeof require!="undefined"&&(f=require("underscore"));var g=a.jQuery||a.Zepto||a.ender;e.setDomLibrary=function(a){g=a},e.noConflict=function(){return a.Backbone=b,this},e.emulateHTTP=!1,e.emulateJSON=!1;var h=/\s+/,i=e.Events={on:function(a,b,c){var d,e,f,g,i;if(!b)return this;a=a.split(h),d=this._callbacks||(this._callbacks={});while(e=a.shift())i=d[e],f=i?i.tail:{},f.next=g={},f.context=c,f.callback=b,d[e]={tail:g,next:i?i.next:f};return this},off:function(a,b,c){var d,e,g,i,j,k;if(!(e=this._callbacks))return;if(!(a||b||c))return delete this._callbacks,this;a=a?a.split(h):f.keys(e);while(d=a.shift()){g=e[d],delete e[d];if(!g||!b&&!c)continue;i=g.tail;while((g=g.next)!==i)j=g.callback,k=g.context,(b&&j!==b||c&&k!==c)&&this.on(d,j,k)}return this},trigger:function(a){var b,d,e,f,g,i,j;if(!(e=this._callbacks))return this;i=e.all,a=a.split(h),j=c.call(arguments,1);while(b=a.shift()){if(d=e[b]){f=d.tail;while((d=d.next)!==f)d.callback.apply(d.context||this,j)}if(d=i){f=d.tail,g=[b].concat(j);while((d=d.next)!==f)d.callback.apply(d.context||this,g)}}return this}};i.bind=i.on,i.unbind=i.off;var j=e.Model=function(a,b){var c;a||(a={}),b&&b.parse&&(a=this.parse(a));if(c=A(this,"defaults"))a=f.extend({},c,a);b&&b.collection&&(this.collection=b.collection),this.attributes={},this._escapedAttributes={},this.cid=f.uniqueId("c"),this.changed={},this._silent={},this._pending={},this.set(a,{silent:!0}),this.changed={},this._silent={},this._pending={},this._previousAttributes=f.clone(this.attributes),this.initialize.apply(this,arguments)};f.extend(j.prototype,i,{changed:null,_silent:null,_pending:null,idAttribute:"id",initialize:function(){},toJSON:function(a){return f.clone(this.attributes)},get:function(a){return this.attributes[a]},escape:function(a){var b;if(b=this._escapedAttributes[a])return b;var c=this.get(a);return this._escapedAttributes[a]=f.escape(c==null?"":""+c)},has:function(a){return this.get(a)!=null},set:function(a,b,c){var d,e,g;f.isObject(a)||a==null?(d=a,c=b):(d={},d[a]=b),c||(c={});if(!d)return this;d instanceof j&&(d=d.attributes);if(c.unset)for(e in d)d[e]=void 0;if(!this._validate(d,c))return!1;this.idAttribute in d&&(this.id=d[this.idAttribute]);var h=c.changes={},i=this.attributes,k=this._escapedAttributes,l=this._previousAttributes||{};for(e in d){g=d[e];if(!f.isEqual(i[e],g)||c.unset&&f.has(i,e))delete k[e],(c.silent?this._silent:h)[e]=!0;c.unset?delete i[e]:i[e]=g,!f.isEqual(l[e],g)||f.has(i,e)!=f.has(l,e)?(this.changed[e]=g,c.silent||(this._pending[e]=!0)):(delete this.changed[e],delete this._pending[e])}return c.silent||this.change(c),this},unset:function(a,b){return(b||(b={})).unset=!0,this.set(a,null,b)},clear:function(a){return(a||(a={})).unset=!0,this.set(f.clone(this.attributes),a)},fetch:function(a){a=a?f.clone(a):{};var b=this,c=a.success;return a.success=function(d,e,f){if(!b.set(b.parse(d,f),a))return!1;c&&c(b,d)},a.error=e.wrapError(a.error,b,a),(this.sync||e.sync).call(this,"read",this,a)},save:function(a,b,c){var d,g;f.isObject(a)||a==null?(d=a,c=b):(d={},d[a]=b),c=c?f.clone(c):{};if(c.wait){if(!this._validate(d,c))return!1;g=f.clone(this.attributes)}var h=f.extend({},c,{silent:!0});if(d&&!this.set(d,c.wait?h:c))return!1;var i=this,j=c.success;c.success=function(a,b,e){var g=i.parse(a,e);c.wait&&(delete c.wait,g=f.extend(d||{},g));if(!i.set(g,c))return!1;j?j(i,a):i.trigger("sync",i,a,c)},c.error=e.wrapError(c.error,i,c);var k=this.isNew()?"create":"update",l=(this.sync||e.sync).call(this,k,this,c);return c.wait&&this.set(g,h),l},destroy:function(a){a=a?f.clone(a):{};var b=this,c=a.success,d=function(){b.trigger("destroy",b,b.collection,a)};if(this.isNew())return d(),!1;a.success=function(e){a.wait&&d(),c?c(b,e):b.trigger("sync",b,e,a)},a.error=e.wrapError(a.error,b,a);var g=(this.sync||e.sync).call(this,"delete",this,a);return a.wait||d(),g},url:function(){var a=A(this,"urlRoot")||A(this.collection,"url")||B();return this.isNew()?a:a+(a.charAt(a.length-1)=="/"?"":"/")+encodeURIComponent(this.id)},parse:function(a,b){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return this.id==null},change:function(a){a||(a={});var b=this._changing;this._changing=!0;for(var c in this._silent)this._pending[c]=!0;var d=f.extend({},a.changes,this._silent);this._silent={};for(var c in d)this.trigger("change:"+c,this,this.get(c),a);if(b)return this;while(!f.isEmpty(this._pending)){this._pending={},this.trigger("change",this,a);for(var c in this.changed){if(this._pending[c]||this._silent[c])continue;delete this.changed[c]}this._previousAttributes=f.clone(this.attributes)}return this._changing=!1,this},hasChanged:function(a){return arguments.length?f.has(this.changed,a):!f.isEmpty(this.changed)},changedAttributes:function(a){if(!a)return this.hasChanged()?f.clone(this.changed):!1;var b,c=!1,d=this._previousAttributes;for(var e in a){if(f.isEqual(d[e],b=a[e]))continue;(c||(c={}))[e]=b}return c},previous:function(a){return!arguments.length||!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},isValid:function(){return!this.validate(this.attributes)},_validate:function(a,b){if(b.silent||!this.validate)return!0;a=f.extend({},this.attributes,a);var c=this.validate(a,b);return c?(b&&b.error?b.error(this,c,b):this.trigger("error",this,c,b),!1):!0}});var k=e.Collection=function(a,b){b||(b={}),b.model&&(this.model=b.model),b.comparator&&(this.comparator=b.comparator),this._reset(),this.initialize.apply(this,arguments),a&&this.reset(a,{silent:!0,parse:b.parse})};f.extend(k.prototype,i,{model:j,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},add:function(a,b){var c,e,g,h,i,j,k={},l={},m=[];b||(b={}),a=f.isArray(a)?a.slice():[a];for(c=0,g=a.length;c<g;c++){if(!(h=a[c]=this._prepareModel(a[c],b)))throw new Error("Can't add an invalid model to a collection");i=h.cid,j=h.id;if(k[i]||this._byCid[i]||j!=null&&(l[j]||this._byId[j])){m.push(c);continue}k[i]=l[j]=h}c=m.length;while(c--)a.splice(m[c],1);for(c=0,g=a.length;c<g;c++)(h=a[c]).on("all",this._onModelEvent,this),this._byCid[h.cid]=h,h.id!=null&&(this._byId[h.id]=h);this.length+=g,e=b.at!=null?b.at:this.models.length,d.apply(this.models,[e,0].concat(a)),this.comparator&&this.sort({silent:!0});if(b.silent)return this;for(c=0,g=this.models.length;c<g;c++){if(!k[(h=this.models[c]).cid])continue;b.index=c,h.trigger("add",h,this,b)}return this},remove:function(a,b){var c,d,e,g;b||(b={}),a=f.isArray(a)?a.slice():[a];for(c=0,d=a.length;c<d;c++){g=this.getByCid(a[c])||this.get(a[c]);if(!g)continue;delete this._byId[g.id],delete this._byCid[g.cid],e=this.indexOf(g),this.models.splice(e,1),this.length--,b.silent||(b.index=e,g.trigger("remove",g,this,b)),this._removeReference(g)}return this},push:function(a,b){return a=this._prepareModel(a,b),this.add(a,b),a},pop:function(a){var b=this.at(this.length-1);return this.remove(b,a),b},unshift:function(a,b){return a=this._prepareModel(a,b),this.add(a,f.extend({at:0},b)),a},shift:function(a){var b=this.at(0);return this.remove(b,a),b},get:function(a){return a==null?void 0:this._byId[a.id!=null?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},where:function(a){return f.isEmpty(a)?[]:this.filter(function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0})},sort:function(a){a||(a={});if(!this.comparator)throw new Error("Cannot sort a set without a comparator");var b=f.bind(this.comparator,this);return this.comparator.length==1?this.models=this.sortBy(b):this.models.sort(b),a.silent||this.trigger("reset",this,a),this},pluck:function(a){return f.map(this.models,function(b){return b.get(a)})},reset:function(a,b){a||(a=[]),b||(b={});for(var c=0,d=this.models.length;c<d;c++)this._removeReference(this.models[c]);return this._reset(),this.add(a,f.extend({silent:!0},b)),b.silent||this.trigger("reset",this,b),this},fetch:function(a){a=a?f.clone(a):{},a.parse===undefined&&(a.parse=!0);var b=this,c=a.success;return a.success=function(d,e,f){b[a.add?"add":"reset"](b.parse(d,f),a),c&&c(b,d)},a.error=e.wrapError(a.error,b,a),(this.sync||e.sync).call(this,"read",this,a)},create:function(a,b){var c=this;b=b?f.clone(b):{},a=this._prepareModel(a,b);if(!a)return!1;b.wait||c.add(a,b);var d=b.success;return b.success=function(e,f,g){b.wait&&c.add(e,b),d?d(e,f):e.trigger("sync",a,f,b)},a.save(null,b),a},parse:function(a,b){return a},chain:function(){return f(this.models).chain()},_reset:function(a){this.length=0,this.models=[],this._byId={},this._byCid={}},_prepareModel:function(a,b){b||(b={});if(a instanceof j)a.collection||(a.collection=this);else{var c=a;b.collection=this,a=new this.model(c,b),a._validate(a.attributes,b)||(a=!1)}return a},_removeReference:function(a){this==a.collection&&delete a.collection,a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){if((a=="add"||a=="remove")&&c!=this)return;a=="destroy"&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,arguments)}});var l=["forEach","each","map","reduce","reduceRight","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","sortBy","sortedIndex","toArray","size","first","initial","rest","last","without","indexOf","shuffle","lastIndexOf","isEmpty","groupBy"];f.each(l,function(a){k.prototype[a]=function(){return f[a].apply(f,[this.models].concat(f.toArray(arguments)))}});var m=e.Router=function(a){a||(a={}),a.routes&&(this.routes=a.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},n=/:\w+/g,o=/\*\w+/g,p=/[-[\]{}()+?.,\\^$|#\s]/g;f.extend(m.prototype,i,{initialize:function(){},route:function(a,b,c){return e.history||(e.history=new q),f.isRegExp(a)||(a=this._routeToRegExp(a)),c||(c=this[b]),e.history.route(a,f.bind(function(d){var f=this._extractParameters(a,d);c&&c.apply(this,f),this.trigger.apply(this,["route:"+b].concat(f)),e.history.trigger("route",this,b,f)},this)),this},navigate:function(a,b){e.history.navigate(a,b)},_bindRoutes:function(){if(!this.routes)return;var a=[];for(var b in this.routes)a.unshift([b,this.routes[b]]);for(var c=0,d=a.length;c<d;c++)this.route(a[c][0],a[c][1],this[a[c][1]])},_routeToRegExp:function(a){return a=a.replace(p,"\\$&").replace(n,"([^/]+)").replace(o,"(.*?)"),new RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});var q=e.History=function(){this.handlers=[],f.bindAll(this,"checkUrl")},r=/^[#\/]/,s=/msie [\w.]+/;q.started=!1,f.extend(q.prototype,i,{interval:50,getHash:function(a){var b=a?a.location:window.location,c=b.href.match(/#(.*)$/);return c?c[1]:""},getFragment:function(a,b){if(a==null)if(this._hasPushState||b){a=window.location.pathname;var c=window.location.search;c&&(a+=c)}else a=this.getHash();return a.indexOf(this.options.root)||(a=a.substr(this.options.root.length)),a.replace(r,"")},start:function(a){if(q.started)throw new Error("Backbone.history has already been started");q.started=!0,this.options=f.extend({},{root:"/"},this.options,a),this._wantsHashChange=this.options.hashChange!==!1,this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&window.history&&window.history.pushState);var b=this.getFragment(),c=document.documentMode,d=s.exec(navigator.userAgent.toLowerCase())&&(!c||c<=7);d&&(this.iframe=g('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(b)),this._hasPushState?g(window).bind("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!d?g(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,this.interval)),this.fragment=b;var e=window.location,h=e.pathname==this.options.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!h)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&h&&e.hash&&(this.fragment=this.getHash().replace(r,""),window.history.replaceState({},document.title,e.protocol+"//"+e.host+this.options.root+this.fragment));if(!this.options.silent)return this.loadUrl()},stop:function(){g(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl),clearInterval(this._checkUrlInterval),q.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(a){var b=this.getFragment();b==this.fragment&&this.iframe&&(b=this.getFragment(this.getHash(this.iframe)));if(b==this.fragment)return!1;this.iframe&&this.navigate(b),this.loadUrl()||this.loadUrl(this.getHash())},loadUrl:function(a){var b=this.fragment=this.getFragment(a),c=f.any(this.handlers,function(a){if(a.route.test(b))return a.callback(b),!0});return c},navigate:function(a,b){if(!q.started)return!1;if(!b||b===!0)b={trigger:b};var c=(a||"").replace(r,"");if(this.fragment==c)return;this._hasPushState?(c.indexOf(this.options.root)!=0&&(c=this.options.root+c),this.fragment=c,window.history[b.replace?"replaceState":"pushState"]({},document.title,c)):this._wantsHashChange?(this.fragment=c,this._updateHash(window.location,c,b.replace),this.iframe&&c!=this.getFragment(this.getHash(this.iframe))&&(b.replace||this.iframe.document.open().close(),this._updateHash(this.iframe.location,c,b.replace))):window.location.assign(this.options.root+a),b.trigger&&this.loadUrl(a)},_updateHash:function(a,b,c){c?a.replace(a.toString().replace(/(javascript:|#).*$/,"")+"#"+b):a.hash=b}});var t=e.View=function(a){this.cid=f.uniqueId("view"),this._configure(a||{}),this._ensureElement(),this.initialize.apply(this,arguments),this.delegateEvents()},u=/^(\S+)\s*(.*)$/,v=["model","collection","el","id","attributes","className","tagName"];f.extend(t.prototype,i,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){return this.$el.remove(),this},make:function(a,b,c){var d=document.createElement(a);return b&&g(d).attr(b),c&&g(d).html(c),d},setElement:function(a,b){return this.$el&&this.undelegateEvents(),this.$el=a instanceof g?a:g(a),this.el=this.$el[0],b!==!1&&this.delegateEvents(),this},delegateEvents:function(a){if(!a&&!(a=A(this,"events")))return;this.undelegateEvents();for(var b in a){var c=a[b];f.isFunction(c)||(c=this[a[b]]);if(!c)throw new Error('Method "'+a[b]+'" does not exist');var d=b.match(u),e=d[1],g=d[2];c=f.bind(c,this),e+=".delegateEvents"+this.cid,g===""?this.$el.bind(e,c):this.$el.delegate(g,e,c)}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b=0,c=v.length;b<c;b++){var d=v[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(!this.el){var a=A(this,"attributes")||{};this.id&&(a.id=this.id),this.className&&(a["class"]=this.className),this.setElement(this.make(this.tagName,a),!1)}else this.setElement(this.el,!1)}});var w=function(a,b){var c=z(this,a,b);return c.extend=this.extend,c};j.extend=k.extend=m.extend=t.extend=w;var x={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};e.sync=function(a,b,c){var d=x[a];c||(c={});var h={type:d,dataType:"json"};return c.url||(h.url=A(b,"url")||B()),!c.data&&b&&(a=="create"||a=="update")&&(h.contentType="application/json",h.data=JSON.stringify(b.toJSON())),e.emulateJSON&&(h.contentType="application/x-www-form-urlencoded",h.data=h.data?{model:h.data}:{}),e.emulateHTTP&&(d==="PUT"||d==="DELETE")&&(e.emulateJSON&&(h.data._method=d),h.type="POST",h.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d)}),h.type!=="GET"&&!e.emulateJSON&&(h.processData=!1),g.ajax(f.extend(h,c))},e.wrapError=function(a,b,c){return function(d,e){e=d===b?e:d,a?a(b,e,c):b.trigger("error",b,e,c)}};var y=function(){},z=function(a,b,c){var d;return b&&b.hasOwnProperty("constructor")?d=b.constructor:d=function(){a.apply(this,arguments)},f.extend(d,a),y.prototype=a.prototype,d.prototype=new y,b&&f.extend(d.prototype,b),c&&f.extend(d,c),d.prototype.constructor=d,d.__super__=a.prototype,d},A=function(a,b){return!a||!a[b]?null:f.isFunction(a[b])?a[b]():a[b]},B=function(){throw new Error('A "url" property or function must be specified')}}.call(this),function(a){function b(b){if(typeof b.data!="string")return;var c=b.handler,d=b.data.toLowerCase().split(" ");b.handler=function(b){if(!(this===b.target||!/textarea|select/i.test(b.target.nodeName)&&b.target.type!=="text"))return;var e=b.type!=="keypress"&&a.hotkeys.specialKeys[b.which],f=String.fromCharCode(b.which).toLowerCase(),g,h="",i={};b.altKey&&e!=="alt"&&(h+="alt+"),b.ctrlKey&&e!=="ctrl"&&(h+="ctrl+"),b.metaKey&&!b.ctrlKey&&e!=="meta"&&(h+="meta+"),b.shiftKey&&e!=="shift"&&(h+="shift+"),e?i[h+e]=!0:(i[h+f]=!0,i[h+a.hotkeys.shiftNums[f]]=!0,h==="shift+"&&(i[a.hotkeys.shiftNums[f]]=!0));for(var j=0,k=d.length;j<k;j++)if(i[d[j]])return c.apply(this,arguments)}}a.hotkeys={version:"0.8",specialKeys:{8:"backspace",9:"tab",13:"return",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"del",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scroll",191:"/",224:"meta"},shiftNums:{"`":"~",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")","-":"_","=":"+",";":": ","'":'"',",":"<",".":">","/":"?","\\":"|"}},a.each(["keydown","keyup","keypress"],function(){a.event.special[this]={add:b}})}(jQuery),$(function(){var a='<div class="showpanel"><button class="button showload">load app</button><button class="button showsource">source</button><button class="button showlibrary">add module</button></div><div class="panel"><div class="load"><button class="button close">close</button></div><div class="source"><button class="button close">close</button><div class="sourceedit"><textarea /></div><div class="controls"><button class="button sourcerefresh" title="refresh the source code">refresh</button><button class="button sourcecompress" title="refresh and compress the source code into one line">compress</button><button class="button sourceapply" title="reloads the app">apply changes</button></div></div><div class="library"><div class="controls"><button class="button close">close</button><form class="addbyurl"><input class="addbyurlinput" name="addbyurlinput" placeholder="search or url" type="text" /><button class="addbyurlsubmit" type="submit">load</button></form></div><div class="listing"></div></div></div>'
-,b=Backbone.View.extend({tagName:"div",className:"app",template:_.template(a),frameCount:0,events:{"click .close":"closepanels","click .showload":"showload","click .showsource":"showsource","click .showlibrary":"showlibrary","click .sourcerefresh":"sourcerefresh","click .sourcecompress":"sourcecompress","click .sourceapply":"sourceapply","submit .addbyurl":"addbyurl"},initialize:function(){this.render(),$("body").append(this.el),this.$(".panel .source").hide(),this.$(".panel .library").hide(),this.$(".close").button({icons:{primary:"ui-icon-close"},text:!1}),this.$(".showsource").button({icons:{primary:"ui-icon-gear"}}),this.$(".showload").button({icons:{primary:"ui-icon-disk"}}),this.$(".showlibrary").button({icons:{primary:"ui-icon-plus"}}),this.$(".sourcerefresh").button({icons:{primary:"ui-icon-arrowrefresh-1-s"}}),this.$(".sourcecompress").button({icons:{primary:"ui-icon-suitcase"}}),this.$(".sourceapply").button({icons:{primary:"ui-icon-check"}}),this.$(".addbyurlsubmit").button({icons:{primary:"ui-icon-check"}})},render:function(){return this.$el.html(this.template()),this},shownGraph:undefined,wireColors:["#FF9292","#00C2EE","#DCA761","#8BB0FF","#96BD6D","#E797D7","#29C6AD"],wireColorIndex:0,selectedPort:null,getWireColor:function(){var a=this.wireColors[this.wireColorIndex];return this.wireColorIndex++,this.wireColorIndex>this.wireColors.length-1&&(this.wireColorIndex=0),a},showGraph:function(a){this.shownGraph&&this.shownGraph.view&&(this.shownGraph.view.$el.remove(),this.shownGraph.view=null,this.shownGraph=null),this.wireColorIndex=0,this.shownGraph=new Iframework.Graph(a),a.info.title&&(document.title="Meemoo: "+a.info.title)},gotMessage:function(a){if(Iframework.shownGraph){var b=Iframework.shownGraph.get("nodes").get(a.data.nodeid);if(b)for(var c in a.data)if(a.data.hasOwnProperty(c)){var d=a.data[c];switch(c){case"info":b.infoLoaded(d);break;case"addInput":b.addInput(d);break;case"addOutput":b.addOutput(d);break;case"stateReady":b.stateReady();break;default:}}}},maskFrames:function(){$(".module").each(function(){$(this).append($('<div class="iframemask" />').css({width:$(this).children(".frame").width()+2,height:$(this).children(".frame").height()+2}))})},unmaskFrames:function(){$(".iframemask").remove()},Library:null,addModulesToLibrary:function(){this.Library||(this.Library=new Iframework.Modules),this.shownGraph.get("nodes").each(function(a){var b=this.Library.findOrAdd(a)},this)},loadLibrary:function(a){this.Library=a;var b=[];Iframework.Library.each(function(a){a.initializeView();var c={value:a.get("src"),label:a.get("info").title+" by "+a.get("info").author+" - "+a.get("info").description+" "+a.get("src"),title:a.get("info").title,desc:a.get("info").description};b.push(c)},this),this.$(".addbyurlinput").autocomplete({minLength:1,source:b}).data("autocomplete")._renderItem=function(a,b){return $("<li></li>").data("item.autocomplete",b).append('<a title="'+b.value+'"><span class="autocomplete-title">'+b.title+'</span><br /><span class="autocomplete-desc">'+b.desc+"</span></a>").appendTo(a)}},closepanels:function(){this.$(".showpanel").show(),this.$(".panel").hide(),this.$(".graph").css("right","0px"),this.$(".panel .load").hide(),this.$(".panel .library").hide(),this.$(".panel .source").hide()},showpanel:function(){this.$(".panel .load").hide(),this.$(".panel .library").hide(),this.$(".panel .source").hide(),this.$(".showpanel").hide(),this.$(".panel").show(),this.$(".graph").css("right","350px")},showload:function(){this.showpanel(),this.$(".panel .load").show()},showsource:function(){this.showpanel(),this.$(".panel .source").show(),this.$(".panel .source textarea").val(JSON.stringify(Iframework.shownGraph,null," "))},showlibrary:function(){this.showpanel(),this.$(".panel .library").show()},sourcerefresh:function(){this.$(".panel .source textarea").val(JSON.stringify(Iframework.shownGraph,null," "))},sourcecompress:function(){this.$(".panel .source textarea").val(JSON.stringify(Iframework.shownGraph,null,""))},sourceapply:function(){var a=JSON.parse($(".panel .sourceedit textarea").val());this.showGraph(a),this.showsource()},addbyurl:function(){$(".addbyurlinput").blur();var a=this.$(".addbyurlinput").val();return a!=""&&(this.shownGraph.addNode(new Iframework.Node({src:a})),this.$(".addbyurlinput").val("").attr("placeholder","loading..."),window.setTimeout(function(){this.$(".addbyurlinput").attr("placeholder","search or url")},1e3)),!1}});window.Iframework=new b,window.addEventListener("message",Iframework.gotMessage,!1)}),$(function(){Iframework.Event=Backbone.Model.extend({defaults:function(){return{action:"",args:{}}},initialize:function(){}}),Iframework.EventsHistory=Backbone.Collection.extend({model:Iframework.Event}),$("body").bind("keydown","ctrl+z",function(){var a=window.Iframework.shownGraph,b=a.eventsHistory.last();if(b.get("action")==="removeNode"){var c=b.get("args").node,d=a.usedIds.indexOf(c.get("id"));a.usedIds.splice(d,1),a.addNode(c);for(var e=0;e<c.Inputs.length;e++)c.view.addInput(c.Inputs.at(e));for(var e=0;e<c.Outputs.length;e++)c.view.addOutput(c.Outputs.at(e));var f=b.get("args").edges;for(var e=0;e<f.length;e++)a.addEdge(f[e])}a.eventsHistory.pop()})}),$(function(){Iframework.Graph=Backbone.Model.extend({loaded:!1,defaults:{info:{author:"",title:"",description:"",parent:"",permalink:""},nodes:[],edges:[]},usedIds:[],edgeCount:0,eventsHistory:[],initialize:function(){this.usedIds=[];if(this.attributes.nodes){var a=this.attributes.nodes;this.attributes.nodes=new Iframework.Nodes;for(var b=0;b<a.length;b++){var c=new Iframework.Node(a[b]);c.graph=this,this.addNode(c)}}if(this.attributes.edges){var d=this.attributes.edges;this.attributes.edges=new Iframework.Edges;for(var e=0;e<d.length;e++){var f=new Iframework.Edge(d[e]);f.graph=this,this.addEdge(f)}}this.eventsHistory=new Iframework.EventsHistory,this.view=new Iframework.GraphView({model:this}),this.on("change",this.graphChanged)},addNode:function(a){var b=this.get("nodes").length,c=parseInt(a.get("id"),10);c!==c&&a.set({id:b});while(this.usedIds.indexOf(a.get("id"))>=0)b++,a.set({id:b});this.usedIds.push(a.get("id"));var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789---",e="";for(var f=0;f<5;f++)e+=d.charAt(Math.floor(Math.random()*d.length));a.frameIndex="frame_"+a.get("id")+"_"+Iframework.frameCount++ +"_"+e,this.get("nodes").add(a),a.graph=this,this.view&&this.view.addNode(a),this.trigger("change")},addEdge:function(a){var b=this.get("edges").any(function(b){return b.get("source")[0]===a.get("source")[0]&&b.get("source")[1]===a.get("source")[1]&&b.get("target")[0]===a.get("target")[0]&&b.get("target")[1]===a.get("target")[1]});return b?(console.warn("duplicate edge ignored"),!1):(this.trigger("change"),this.get("edges").add(a))},removeNode:function(a){this.view&&this.view.removeNode(a);var b=[];this.get("edges").each(function(c){(c.source.node==a||c.target.node==a)&&b.push(c)});for(var c=0;c<b.length;c++)b[c].remove();this.get("nodes").remove(a),this.eventsHistory.add(new Iframework.Event({action:"removeNode",args:{node:a,edges:b}})),this.trigger("change")},removeEdge:function(a){a.disconnect(),this.get("edges").remove(a),this.view&&this.view.removeEdge(a),this.trigger("change")},checkLoaded:function(){for(var a=0;a<this.get("nodes").length;a++)if(this.get("nodes").at(a).loaded===!1)return!1;return this.loaded=!0,this.reconnectEdges(),Iframework.addModulesToLibrary(),!0},reconnectEdges:function(){for(var a=0;a<this.get("edges").length;a++)this.get("edges").at(a).disconnect();setTimeout(function(){Iframework.shownGraph.connectEdges()},500)},connectEdges:function(){for(var a=0;a<this.get("edges").length;a++){var b=this.get("edges").at(a),c=this.get("nodes").get(b.get("source")[0]),d=this.get("nodes").get(b.get("target")[0]);c&&d?b.connect():b.remove()}},graphChanged:function(){Iframework.$(".source").is(":visible")&&window.setTimeout(function(){Iframework.sourcerefresh()},100)}}),Iframework.Graphs=Backbone.Collection.extend({model:Iframework.Graph})}),$(function(){var a='<div class="edges"><svg id="edgesSvg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg></div><div class="nodes" />';Iframework.GraphView=Backbone.View.extend({tagName:"div",className:"graph",template:_.template(a),events:{click:"click"},initialize:function(){this.render(),Iframework.$el.prepend(this.el),this.model.get("nodes").each(this.addNode),this.resizeEdgeSVG()},render:function(){return this.$el.html(this.template(this.model.toJSON())),this},click:function(a){$(".edge-edit").remove(),Iframework.selectedPort=null,$("div.module").removeClass("active")},addNode:function(a){this.$(".nodes").append(a.initializeView().el)},addEdge:function(a){a.initializeView(),a.source.view&&a.source.view.resetRelatedEdges(),a.target.view&&a.target.view.resetRelatedEdges()},removeNode:function(a){a.view&&a.view.$el.remove()},removeEdge:function(a){a.view&&a.view.remove(),a.source&&a.source.view&&a.source.view.resetRelatedEdges(),a.target&&a.target.view&&a.target.view.resetRelatedEdges()},resizeEdgeSVG:function(){var a=0,b=0;this.model.get("nodes").each(function(c){var d=c.get("x")+c.get("w");d>a&&(a=d);var e=c.get("y")+c.get("h");e>b&&(b=e)},this),a+=150,b+=50,this.$("#edgesSvg").css({width:a,height:b})}})}),$(function(){Iframework.Node=Backbone.Model.extend({loaded:!1,defaults:function(){return{src:"",x:100,y:400,z:0,w:200,h:200,state:{}}},initialize:function(){this.Inputs=new Iframework.Ports,this.Outputs=new Iframework.Ports,this.on("change",this.nodeChanged)},initializeView:function(){return this.view=new Iframework.NodeView({model:this}),this.view},send:function(a){window.frames[this.frameIndex]?window.frames[this.frameIndex].postMessage(a,"*"):console.error("wat "+this.id+" "+this.frameIndex)},Info:{},infoLoaded:function(a){this.view&&(this.Info=a,this.view.infoLoaded(a))},setState:function(a){this.send({setState:a})},stateReady:function(){this.get("state")&&this.setState(this.get("state")),this.loaded=!0,this.graph.checkLoaded()},addInput:function(a){var b=this.Inputs.findByName(a.name);if(b)return;var c=new Iframework.Port(a);c.isIn=!0,c.node=this,c.graph=this.graph,this.Inputs.add(c),this.view&&this.view.addInput(c);var d=this.get("state");a.hasOwnProperty("default")&&a.default!=""&&!d.hasOwnProperty(a.name)&&(d[a.name]=a.default)},addOutput:function(a){var b=this.Outputs.findByName(a.name);if(b)return;var c=new Iframework.Port(a);c.isIn=!1,c.node=this,c.graph=this.graph,this.Outputs.add(c),this.view&&this.view.addOutput(c)},nodeChanged:function(){this.graph&&this.graph.trigger("change")},remove:function(){this.graph.removeNode(this)}}),Iframework.Nodes=Backbone.Collection.extend({model:Iframework.Node})}),$(function(){var a='<div class="module" style="left:<%= get("x")-10 %>px;top:<%= get("y")-30 %>px;width:<%= get("w")+20 %>px;height:<%= get("h")+40 %>px;" ><div class="ports ports-in"></div><div class="ports ports-out"></div><h1 class="title">...</h1><button type="button" class="showcontrols">show controls</button><div class="controls"><button type="button" class="remove">remove</button><button type="button" class="refresh">refresh</button><button type="button" class="hidecontrols">hide controls</button></div><iframe class="frame" name="<%= frameIndex %>" src="<%= get("src") %>" style="width:<%= get("w") %>px;height:<%= get("h") %>px;"></iframe></div>';Iframework.NodeView=Backbone.View.extend({tagName:"div",className:"node",template:_.template(a),events:{"dragstart .module":"dragstart","drag .module":"drag","dragstop .module":"dragstop","resizestart .module":"resizestart","resize .module":"resize","resizestop .module":"resizestop","mousedown .module, .title":"mousedown","click .module, .title":"click","click .showcontrols":"showControls","click .hidecontrols":"hideControls","click .refresh":"refresh","click .remove":"removeModel"},initialize:function(){this.render(),this.$(".module").draggable({handle:"h1"}).resizable(),this.$(".showcontrols").button({icons:{primary:"ui-icon-carat-1-w"},text:!1}),this.$(".hidecontrols").button({icons:{primary:"ui-icon-carat-1-e"},text:!1}),this.$(".refresh").button({icons:{primary:"ui-icon-arrowrefresh-1-s"},text:!1}),this.$(".remove").button({icons:{primary:"ui-icon-trash"},text:!1}),this.$("h1").disableSelection()},render:function(){return this.$el.html(this.template(this.model)),this},infoLoaded:function(a){this.$("h1").text(this.model.get("id")+": "+a.title).attr({title:"by "+a.author+": "+a.description})},_relatedEdges:null,relatedEdges:function(){return this._relatedEdges===null&&(this._relatedEdges=this.model.graph.get("edges").filter(function(a){return a.get("source")[0]===this.model.get("id")||a.get("target")[0]===this.model.get("id")},this)),this._relatedEdges},resetRelatedEdges:function(){this._relatedEdges=null,this.relatedEdges()},dragstart:function(a,b){Iframework.maskFrames()},drag:function(a,b){_.each(this.relatedEdges(),function(a){a.view&&a.view.redraw()})},dragstop:function(a,b){Iframework.unmaskFrames(),this.drag(),this.model.set({x:b.offset.left+10+$(".graph").scrollLeft(),y:b.offset.top+30+$(".graph").scrollTop()}),this.model.graph.view.resizeEdgeSVG()},resizestart:function(a,b){Iframework.maskFrames()},resize:function(a,b){this.drag()},resizestop:function(a,b){Iframework.unmaskFrames();var c=b.size.width,d=b.size.height;this.model.set({w:c-20,h:d-40}),this.$(".frame").css({width:c-20,height:d-40}),this.model.graph.view.resizeEdgeSVG(),this.drag()},mousedown:function(a,b){$("div.module").removeClass("active");var c=0;$("div.nodes div.module").each(function(){var a=Number($(this).css("z-index"));a>c&&(c=a)}),this.$(".module").css("z-index",c+1).addClass("active")},click:function(a){a.stopPropagation()},addInput:function(a){this.$(".ports-in").append(a.initializeView().el)},addOutput:function(a){this.$(".ports-out").append(a.initializeView().el)},showControls:function(){this.$(".showcontrols").hide(),this.$(".controls").show()},hideControls:function(){this.$(".showcontrols").show(),this.$(".controls").hide()},refresh:function(){this.$(".frame")[0].src=this.model.get("src")},removeModel:function(){this.model.remove()},remove:function(){this.$el.remove()}})}),$(function(){Iframework.Module=Backbone.Model.extend({defaults:{src:"",info:{},inputs:[],outputs:[]},initialize:function(){},initializeView:function(){return this.view||(this.view=new Iframework.ModuleView({model:this})),this.view},toJSON:function(){return{src:this.get("src"),info:this.get("info"),inputs:this.get("inputs"),outputs:this.get("outputs")}}}),Iframework.Modules=Backbone.Collection.extend({model:Iframework.Module,findOrAdd:function(a){var b;return b=this.find(function(b){return b.get("src")===a.get("src")}),b||(b=new Iframework.Module({node:a}),this.add(b)),b}})}),$(function(){var a='<button class="addnode" type="button">add node</button><h2 class="title"><%= info.title %></h2><p class="description"><%= info.description %></p><p class="src"><%= src %></p><ul class="inputs"></ul><ul class="outputs"></ul>';Iframework.ModuleView=Backbone.View.extend({tagName:"div",className:"librarymodule",template:_.template(a),events:{"click .addnode":"addnode"},initialize:function(){return this.render(),Iframework.$(".panel .library .listing").append(this.el),this.$(".addnode").button({icons:{primary:"ui-icon-plus"},text:!1}),this},render:function(){this.$el.html(this.template(this.model.toJSON()))},addnode:function(){Iframework.shownGraph.addNode(new Iframework.Node({src:this.model.get("src")}))}})}),$(function(){Iframework.Port=Backbone.Model.extend({defaults:{name:"",type:"",description:"","default":null},initialize:function(){this.get("type")===""&&this.set("type","all"),this.set("type_class",this.get("type").split("/")[0].replace(":","_"))},initializeView:function(){return this.view=new Iframework.PortView({model:this})}}),Iframework.Ports=Backbone.Collection.extend({model:Iframework.Ports,findByName:function(a){return this.find(function(b){return b.get("name")===a})}})}),$(function(){var a='<div class="portshown portshown-in"><span class="hole hole-in hole-<%= type_class %>"></span><span class="label"><%= name %></span></div><span class="plugend plugend-in plugend-<%= type_class %>"></span>',b='<div class="portshown portshown-out"><span class="label"><%= name %></span><span class="hole hole-out hole-<%= type_class %>"></span></div><span class="plugend plugend-out plugend-<%= type_class %>"></span>',c='<div class="edge-edit"><button class="close">close</button><h2><%= name %> (<%= type %>)</h2><p><%= description %></p></div>',d='<div class="edge-edit-item" id="<%= model.cid %>"><span><%= label() %></span><button class="disconnect" type="button">disconnect</button></div>';Iframework.PortView=Backbone.View.extend({tagName:"div",className:"port",portInTemplate:_.template(a),portOutTemplate:_.template(b),popupTemplate:_.template(c),edgeEditTemplate:_.template(d),events:{mousedown:"highlightEdge","click .hole":"clickhole","dragstart .hole":"dragstart","drag .hole, .holehelper":"drag","dragstop .hole, .holehelper":"dragstop","dragstart .plugend":"unplugstart","drag .plugend":"unplugdrag","dragstop .plugend":"unplugstop",drop:"drop","click .disconnect":"disconnect","submit .manualinput":"manualinput"},initialize:function(){return this.render(),this},render:function(){this.model.isIn?(this.$el.html(this.portInTemplate(this.model.toJSON())),this.$el.addClass("port-in"),this.$(".hole").draggable({helper:function(a){return $('<span class="holehelper holehelper-out" />')}}),this.$(".plugend").draggable({helper:function(a){return $('<span class="plugendhelper plugendhelper-in" />')}})):(this.$el.html(this.portOutTemplate(this.model.toJSON())),this.$el.addClass("port-out"),this.$(".hole").draggable({helper:function(a){return $('<span class="holehelper holehelper-in" />')}}),this.$(".plugend").draggable({helper:function(a){return $('<span class="plugendhelper plugendhelper-out" />')}})),this.$(".hole").data({model:this.model}).button({icons:{primary:"ui-icon-arrow-1-e"},text:!1});var a="";if(this.model.get("type")==="all")this.model.isIn?a=".hole-out, .plugend-in":a=".hole-in .plugend-out";else{var b=this.model.get("type_class");this.model.isIn?a=".hole-out.hole-all, .hole-out.hole-"+b+", .plugend-in.plugend-all, .plugend-in.plugend-"+b:a=".hole-in.hole-all, .hole-in.hole-"+b+", .plugend-out.plugend-all, .plugend-out.plugend-"+b}this.$el.droppable({hoverClass:"drophover",accept:a}),this.$(".plugend").hide(),this.$(".portshown").disableSelection()},dragstart:function(a,b){Iframework.maskFrames(),$("div.ports-"+(this.model.isIn?"out":"in")+" span.hole-"+this.model.get("type_class")).addClass("highlight");var c=new Iframework.EdgeView;Iframework.edgePreview=c,this.drag(a,b),this.$(".plugend").show(),a.stopPropagation()},drag:function(a,b){if(Iframework.edgePreview){var c=b.offset.left+$(".graph").scrollLeft(),d=b.offset.top+6+$(".graph").scrollTop(),e=this.portOffsetLeft(),f=this.portOffsetTop(),g={fromX:this.model.isIn?c-2:e,fromY:this.model.isIn?d:f,toX:this.model.isIn?e:c+20,toY:this.model.isIn?f:d};Iframework.edgePreview.setPositions(g),Iframework.edgePreview.redraw()}a.stopPropagation()},dragstop:function(a,b){Iframework.unmaskFrames(),$(".hole").removeClass("highlight"),Iframework.edgePreview.remove(),Iframework.edgePreview=undefined,this.relatedEdges().length<1&&this.$(".plugend").hide(),a.stopPropagation()},drop:function(a,b){if(this.armDelete)this.armDelete=!1;else{var c=$(b.draggable).data("model"),d=this.model,e=this.model.isIn?c:d,f=this.model.isIn?d:c,g=new Iframework.Edge({source:[e.node.get("id"),e.get("name")],target:[f.node.get("id"),f.get("name")]});g.graph=this.model.graph,Iframework.edgePreview&&(g._color=Iframework.edgePreview._color),g.graph.addEdge(g)&&g.connect()}a.stopPropagation()},unpluggingEdge:null,armDeleteTimeout:null,armDelete:!1,unplugstart:function(a,b){Iframework.maskFrames();var c,d=0,e=0;this.model.graph.get("edges").each(function(a){if(a.source===this.model||a.target===this.model)d++,a.view._z>=e&&(e=a.view._z,c=a)},this);if(!c)return!1;this.unpluggingEdge=c,this.unpluggingEdge.view.dim(),d===1&&this.$(".plugend").hide();var f=this.model.isIn?this.unpluggingEdge.source:this.unpluggingEdge.target;this.$(".plugend").data("model",f),$("div.ports-"+(this.model.isIn?"in":"out")+" span.hole-"+this.model.get("type_class")).addClass("highlight");var g=new Iframework.EdgeView;g.setColor(this.unpluggingEdge.view._color),Iframework.edgePreview=g,this.armDelete=!0,a.stopPropagation()},unplugdrag:function(a,b){if(Iframework.edgePreview&&this.unpluggingEdge){var c=b.offset.left+$(".graph").scrollLeft(),d=b.offset.top+6+$(".graph").scrollTop(),e=this.model.isIn?this.unpluggingEdge.source.view:this.unpluggingEdge.target.view,f=e.portOffsetLeft(),g=e.portOffsetTop(),h={fromX:this.model.isIn?f:c-2,fromY:this.model.isIn?g:d,toX:this.model.isIn?c+20:f,toY:this.model.isIn?d:g};Iframework.edgePreview.setPositions(h),Iframework.edgePreview.redraw()}a.stopPropagation()},unplugstop:function(a,b){this.armDelete&&this.unpluggingEdge?this.model.graph.removeEdge(this.unpluggingEdge):(this.$(".plugend").show(),this.unpluggingEdge.view.undim()),this.armDelete=!1,this.unpluggingEdge=null,this.dragstop(a,b)},clickhole:function(a){$("div.edge-edit").remove();var b=this.$(".hole"),c=this.model.isIn,d=this.model.get("name");if(Iframework.selectedPort&&c!==Iframework.selectedPort.isIn){if(c)var e=new Iframework.Edge({source:[Iframework.selectedPort.node.get("id"),Iframework.selectedPort.get("name")],target:[this.model.node.get("id"),this.model.get("name")]});else var e=new Iframework.Edge({source:[this.model.node.get("id"),this.model.get("name")],target:[Iframework.selectedPort.node.get("id"),Iframework.selectedPort.get("name")]});e.graph=Iframework.shownGraph,e.graph.addEdge(e)&&e.connect(),Iframework.edgePreview&&(Iframework.shownGraph.view.$(".edges").children(".preview").remove(),Iframework.edgePreview=undefined),Iframework.selectedPort=null;return}var f=this.popupTemplate(this.model.toJSON());f=$(f),this.$el.append(f),f.children("button.close").button({icons:{primary:"ui-icon-close"},text:!1}).click(function(){$("div.edge-edit").remove(),Iframework.selectedPort=null});var g=this.model.get("type").substring(0,3);if(c){var h=!1,i=$("<form />").attr({id:this.model.node.id+"_"+this.model.get("name"),"class":"manualinput"});if(g==="int"||g==="num")h=!0,i.append($("<input />").attr({type:"number",min:b.data("min"),max:b.data("max"),value:this.model.node.get("state")[this.model.get("name")]}));else if(g==="col"||g==="str")h=!0,i.append($("<input />").attr({type:"text",maxlength:b.data("max"),value:this.model.node.get("state")[this.model.get("name")]}));else if(g==="boo"){h=!0;var j=this.model.node.get("state")[this.model.get("name")];j=Boolean(j)&&j!="false",i.append($("<input />").attr({type:"checkbox",checked:j}))}else g==="ban"&&(i.append("<label>Send bang:</label> "),h=!0);h&&(i.append($("<button></button>").html("send").attr({type:"submit","class":"send",title:"send value to module"}).button({icons:{primary:"ui-icon-check"},text:!1})),f.append(i))}$("#select_"+this.model.id).button({icons:{primary:"ui-icon-power"}}),this.relatedEdges().length>0&&(f.append("<h2>disconnect</h2>"),_.each(this.relatedEdges(),function(a){var b=this.edgeEditTemplate(a.view);f.append(b)},this),$(".disconnect").button({icons:{primary:"ui-icon-scissors"},text:!1})),this.model.get("options")&&this.model.get("options").length>0&&this.$("input").autocomplete({minLength:0,source:this.model.get("options")}),a.stopPropagation()},manualinput:function(a){var b=this.model.get("name"),c=this.$(".manualinput").children("input")?this.$(".manualinput").children("input").val():"bang!";this.$(".manualinput").children("input:checkbox").length>0&&(this.$(".manualinput").children("input:checkbox").is(":checked")?c=!0:c=!1),this.model.get("type")==="int"&&(c=parseInt(c)),this.model.get("type")==="number"&&(c=parseFloat(c));var d={};return d[b]=c,this.model.node.send(d),this.model.node.get("state")[b]=c,this.model.node.trigger("change"),$("div.edge-edit").remove(),!1},disconnect:function(a){var b=this.model.graph.get("edges").getByCid($(a.target).parents(".edge-edit-item").attr("id"));b&&this.model.graph.removeEdge(b),$("div.edge-edit").remove(),Iframework.selectedPort=null,a.stopPropagation()},portOffsetLeft:function(){var a=this.$(".hole").offset();return a?a.left+7+$(".graph").scrollLeft():0},portOffsetTop:function(){var a=this.$(".hole").offset();return a?a.top+7+$(".graph").scrollTop():0},_relatedEdges:null,relatedEdges:function(){return this._relatedEdges===null&&(this._relatedEdges=this.model.graph.get("edges").filter(function(a){return a.source===this.model||a.target===this.model},this),this._relatedEdges.length>=1?this.$(".plugend").show():this.$(".plugend").hide(),this.model.node.view.resetRelatedEdges()),this._relatedEdges},resetRelatedEdges:function(){this._relatedEdges=null,this.relatedEdges()},highlightEdge:function(){if(this.relatedEdges().length>0){var a,b=0;_.each(this.relatedEdges(),function(c){c.view._z>=b&&(b=c.view._z,a=c)},this),a.view.highlight()}},highlight:function(){var a=this.$(".plugend");a.addClass("highlight"),setTimeout(function(){a.removeClass("highlight")},1e3)}})}),$(function(){Iframework.Edge=Backbone.Model.extend({defaults:{source:[0,"default"],target:[0,"default"]},initialize:function(){},initializeView:function(){return this.view=new Iframework.EdgeView({model:this}),this.view},source:null,target:null,connect:function(){for(var a=0;a<this.graph.get("nodes").length;a++)this.graph.get("nodes").at(a).get("id")===this.get("source")[0]&&(this.source=this.graph.get("nodes").at(a).Outputs.findByName(this.get("source")[1])),this.graph.get("nodes").at(a).get("id")===this.get("target")[0]&&(this.target=this.graph.get("nodes").at(a).Inputs.findByName(this.get("target")[1]));return!this.source||!this.target?!1:(this.source.node.send({connect:{source:[this.source.node.frameIndex,this.get("source")[1]],target:[this.target.node.frameIndex,this.get("target")[1]]}}),this.graph.view&&this.graph.view.addEdge(this),this)},disconnect:function(){this.source&&this.target&&this.source.node.send({disconnect:{source:[this.source.node.frameIndex,this.get("source")[1]],target:[this.target.node.frameIndex,this.get("target")[1]]}}),this.view&&this.view.remove()},remove:function(){this.graph.removeEdge(this)}}),Iframework.Edges=Backbone.Collection.extend({model:Iframework.Edge})}),$(function(){Iframework.EdgeView=Backbone.View.extend({tagName:"div",className:"edge",positions:null,graphSVGElement:null,elementGroup:null,elementWire:null,elementShadow:null,isPreview:!1,initialize:function(){this.graphSVGElement=document.getElementById("edgesSvg"),this.positions={fromX:0,fromY:0,toX:0,toY:0},this.model||(this.isPreview=!0),this.model&&this.model._color&&(this._color=this.model._color),this.render(),this.model&&(this._z=this.model.graph.edgeCount++,$(this.elementWire).data({model:this.model}).click(function(a){$(a.target).data("model").view.click(a)}))},render:function(){return this.calcPositions(),this.elementGroup=this.makeSVG("g",{transform:"translate("+this.svgX()+","+this.svgY()+")","class":"wire-group"+(this.isPreview?" preview":"")}),this.elementShadow=this.makeSVG("path",{"class":"wire-shadow",d:this.svgPathShadow()}),this.elementWire=this.makeSVG("path",{"class":"wire",d:this.svgPath(),stroke:this.color()}),this.elementGroup.appendChild(this.elementShadow),this.elementGroup.appendChild(this.elementWire),this.graphSVGElement.appendChild(this.elementGroup),this.model&&(this.model.source.view.$(".plugend").show(),this.model.target.view.$(".plugend").show()),this},redraw:function(){this.calcPositions(),$(this.elementGroup).attr("transform","translate("+this.svgX()+", "+this.svgY()+")"),$(this.elementWire).attr("d",this.svgPath()),$(this.elementShadow).attr("d",this.svgPathShadow())},remove:function(){$(this.elementGroup).remove()},setPositions:function(a){this.positions=a},calcPositions:function(){if(this.model){var a=this.model.get("source")[1],b=this.model.get("target")[1];this.positions.fromX=this.model.source.view.portOffsetLeft("out",a),this.positions.fromY=this.model.source.view.portOffsetTop("out",a),this.positions.toX=this.model.target.view.portOffsetLeft("in",b),this.positions.toY=this.model.target.view.portOffsetTop("in",b)}},svgX:function(){return Math.min(this.positions.toX,this.positions.fromX)-50},svgY:function(){return Math.min(this.positions.toY,this.positions.fromY)-25},svgW:function(){return Math.abs(this.positions.toX-this.positions.fromX)+100},svgH:function(){return Math.abs(this.positions.toY-this.positions.fromY)+50},pathStraight:35,pathCurve:60,svgPath:function(){var a=this.positions.fromX-this.svgX(),b=this.positions.fromY-this.svgY(),c=this.positions.toX-this.svgX(),d=this.positions.toY-this.svgY();return"M "+a+" "+b+" L "+(a+this.pathStraight)+" "+b+" C "+(a+this.pathCurve)+" "+b+" "+(c-this.pathCurve)+" "+d+" "+(c-this.pathStraight)+" "+d+" L "+c+" "+d},svgPathShadow:function(){var a=this.positions.fromX-this.svgX(),b=this.positions.fromY-this.svgY()+1,c=this.positions.toX-this.svgX(),d=this.positions.toY-this.svgY()+1;return"M "+a+" "+b+" L "+(a+this.pathStraight)+" "+b+" C "+(a+this.pathCurve)+" "+b+" "+(c-this.pathCurve)+" "+d+" "+(c-this.pathStraight)+" "+d+" L "+c+" "+d},color:function(){return this._color?this._color:this.model?this._color=Iframework.getWireColor():Iframework.wireColors[Iframework.wireColorIndex]},setColor:function(a){this._color=a,$(this.elementWire).attr("stroke",a)},label:function(){return this.model.get("source")[0]+":"+this.model.get("source")[1]+'<span class="wiresymbol" style="color:'+this._color+'">&rarr;</span>'+this.model.get("target")[0]+":"+this.model.get("target")[1]},makeSVG:function(a,b){var c=document.createElementNS("http://www.w3.org/2000/svg",a);for(var d in b)d==="xlink:href"?c.setAttributeNS("http://www.w3.org/1999/xlink","href",b[d]):c.setAttribute(d,b[d]);return c},dim:function(){$(this.elementGroup).attr("opacity",.2)},undim:function(){$(this.elementGroup).attr("opacity",1)},click:function(a){this._z<this.model.graph.edgeCount-1&&(this.graphSVGElement.appendChild(this.elementGroup),this._z=this.model.graph.edgeCount++),this.highlight()},highlight:function(){var a=$(this.elementShadow);a.attr("class","wire-shadow highlight"),setTimeout(function(){a.attr("class","wire-shadow")},1e3),this.model.source.view&&this.model.source.view.highlight(),this.model.target.view&&this.model.target.view.highlight()}})});
+,b=Backbone.View.extend({tagName:"div",className:"app",template:_.template(a),frameCount:0,events:{"click .close":"closepanels","click .showload":"showload","click .showsource":"showsource","click .showlibrary":"showlibrary","click .sourcerefresh":"sourcerefresh","click .sourcecompress":"sourcecompress","click .sourceapply":"sourceapply","submit .addbyurl":"addbyurl"},initialize:function(){this.render(),$("body").append(this.el),this.$(".panel .source").hide(),this.$(".panel .library").hide(),this.$(".close").button({icons:{primary:"ui-icon-close"},text:!1}),this.$(".showsource").button({icons:{primary:"ui-icon-gear"}}),this.$(".showload").button({icons:{primary:"ui-icon-disk"}}),this.$(".showlibrary").button({icons:{primary:"ui-icon-plus"}}),this.$(".sourcerefresh").button({icons:{primary:"ui-icon-arrowrefresh-1-s"}}),this.$(".sourcecompress").button({icons:{primary:"ui-icon-suitcase"}}),this.$(".sourceapply").button({icons:{primary:"ui-icon-check"}}),this.$(".addbyurlsubmit").button({icons:{primary:"ui-icon-check"}})},render:function(){return this.$el.html(this.template()),this},shownGraph:undefined,wireColors:["#FF9292","#00C2EE","#DCA761","#8BB0FF","#96BD6D","#E797D7","#29C6AD"],wireColorIndex:0,selectedPort:null,getWireColor:function(){var a=this.wireColors[this.wireColorIndex];return this.wireColorIndex++,this.wireColorIndex>this.wireColors.length-1&&(this.wireColorIndex=0),a},showGraph:function(a){this.shownGraph&&this.shownGraph.view&&(this.shownGraph.view.$el.remove(),this.shownGraph.view=null,this.shownGraph=null),this.wireColorIndex=0,this.shownGraph=new Iframework.Graph(a),a.info.title&&(document.title="Meemoo: "+a.info.title)},gotMessage:function(a){if(Iframework.shownGraph){var b=Iframework.shownGraph.get("nodes").get(a.data.nodeid);if(b)for(var c in a.data)if(a.data.hasOwnProperty(c)){var d=a.data[c];switch(c){case"info":b.infoLoaded(d);break;case"addInput":b.addInput(d);break;case"addOutput":b.addOutput(d);break;case"stateReady":b.stateReady();break;default:}}}},maskFrames:function(){$(".module").each(function(){$(this).append($('<div class="iframemask" />').css({width:$(this).children(".frame").width()+2,height:$(this).children(".frame").height()+2}))})},unmaskFrames:function(){$(".iframemask").remove()},Library:null,addModulesToLibrary:function(){this.Library||(this.Library=new Iframework.Modules),this.shownGraph.get("nodes").each(function(a){var b=this.Library.findOrAdd(a)},this)},loadLibrary:function(a){this.Library=a;var b=[];Iframework.Library.each(function(a){a.initializeView();var c={value:a.get("src"),label:a.get("info").title+" by "+a.get("info").author+" - "+a.get("info").description+" "+a.get("src"),title:a.get("info").title,desc:a.get("info").description};b.push(c)},this),this.$(".addbyurlinput").autocomplete({minLength:1,source:b}).data("autocomplete")._renderItem=function(a,b){return $("<li></li>").data("item.autocomplete",b).append('<a title="'+b.value+'"><span class="autocomplete-title">'+b.title+'</span><br /><span class="autocomplete-desc">'+b.desc+"</span></a>").appendTo(a)}},closepanels:function(){this.$(".showpanel").show(),this.$(".panel").hide(),this.$(".graph").css("right","0px"),this.$(".panel .load").hide(),this.$(".panel .library").hide(),this.$(".panel .source").hide()},showpanel:function(){this.$(".panel .load").hide(),this.$(".panel .library").hide(),this.$(".panel .source").hide(),this.$(".showpanel").hide(),this.$(".panel").show(),this.$(".graph").css("right","350px")},showload:function(){this.showpanel(),this.$(".panel .load").show()},showsource:function(){this.showpanel(),this.$(".panel .source").show(),this.$(".panel .source textarea").val(JSON.stringify(Iframework.shownGraph,null," "))},showlibrary:function(){this.showpanel(),this.$(".panel .library").show()},sourcerefresh:function(){this.$(".panel .source textarea").val(JSON.stringify(Iframework.shownGraph,null," "))},sourcecompress:function(){this.$(".panel .source textarea").val(JSON.stringify(Iframework.shownGraph,null,""))},sourceapply:function(){var a=JSON.parse($(".panel .sourceedit textarea").val());this.showGraph(a),this.showsource()},addbyurl:function(){$(".addbyurlinput").blur();var a=this.$(".addbyurlinput").val();return a!=""&&(this.shownGraph.addNode(new Iframework.Node({src:a})),this.$(".addbyurlinput").val("").attr("placeholder","loading..."),window.setTimeout(function(){this.$(".addbyurlinput").attr("placeholder","search or url")},1e3)),!1}});window.Iframework=new b,window.addEventListener("message",Iframework.gotMessage,!1)}),$(function(){Iframework.Event=Backbone.Model.extend({defaults:function(){return{action:"",args:{}}},initialize:function(){}}),Iframework.EventsHistory=Backbone.Collection.extend({model:Iframework.Event}),$("body").bind("keydown","ctrl+z",function(){var a=window.Iframework.shownGraph,b=a.eventsHistory.last();if(b.get("action")==="removeNode"){var c=b.get("args").node,d=a.usedIds.indexOf(c.get("id"));a.usedIds.splice(d,1),a.addNode(c);for(var e=0;e<c.Inputs.length;e++)c.view.addInput(c.Inputs.at(e));for(var e=0;e<c.Outputs.length;e++)c.view.addOutput(c.Outputs.at(e));var f=b.get("args").edges;for(var e=0;e<f.length;e++)a.addEdge(f[e])}a.eventsHistory.pop()})}),$(function(){Iframework.Graph=Backbone.Model.extend({loaded:!1,defaults:{info:{author:"",title:"",description:"",parent:"",permalink:""},nodes:[],edges:[]},usedIds:[],edgeCount:0,eventsHistory:[],initialize:function(){this.usedIds=[];if(this.attributes.nodes){var a=this.attributes.nodes;this.attributes.nodes=new Iframework.Nodes;for(var b=0;b<a.length;b++){var c=new Iframework.Node(a[b]);c.graph=this,this.addNode(c)}}if(this.attributes.edges){var d=this.attributes.edges;this.attributes.edges=new Iframework.Edges;for(var e=0;e<d.length;e++){var f=new Iframework.Edge(d[e]);f.graph=this,this.addEdge(f)}}this.eventsHistory=new Iframework.EventsHistory,this.view=new Iframework.GraphView({model:this}),this.on("change",this.graphChanged)},addNode:function(a){var b=this.get("nodes").length,c=parseInt(a.get("id"),10);c!==c&&a.set({id:b});while(this.usedIds.indexOf(a.get("id"))>=0)b++,a.set({id:b});this.usedIds.push(a.get("id"));var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789---",e="";for(var f=0;f<5;f++)e+=d.charAt(Math.floor(Math.random()*d.length));a.frameIndex="frame_"+a.get("id")+"_"+Iframework.frameCount++ +"_"+e,this.get("nodes").add(a),a.graph=this,this.view&&this.view.addNode(a),this.trigger("change")},addEdge:function(a){var b=this.get("edges").any(function(b){return b.get("source")[0]===a.get("source")[0]&&b.get("source")[1]===a.get("source")[1]&&b.get("target")[0]===a.get("target")[0]&&b.get("target")[1]===a.get("target")[1]});return b?(console.warn("duplicate edge ignored"),!1):(this.trigger("change"),this.get("edges").add(a))},removeNode:function(a){this.view&&this.view.removeNode(a);var b=[];this.get("edges").each(function(c){(c.source.node==a||c.target.node==a)&&b.push(c)});for(var c=0;c<b.length;c++)b[c].remove();this.get("nodes").remove(a),this.eventsHistory.add(new Iframework.Event({action:"removeNode",args:{node:a,edges:b}})),this.trigger("change")},removeEdge:function(a){a.disconnect(),this.get("edges").remove(a),this.view&&this.view.removeEdge(a),this.trigger("change")},checkLoaded:function(){for(var a=0;a<this.get("nodes").length;a++)if(this.get("nodes").at(a).loaded===!1)return!1;return this.loaded=!0,this.reconnectEdges(),Iframework.addModulesToLibrary(),!0},reconnectEdges:function(){for(var a=0;a<this.get("edges").length;a++)this.get("edges").at(a).disconnect();setTimeout(function(){Iframework.shownGraph.connectEdges()},500)},connectEdges:function(){for(var a=0;a<this.get("edges").length;a++){var b=this.get("edges").at(a),c=this.get("nodes").get(b.get("source")[0]),d=this.get("nodes").get(b.get("target")[0]);c&&d?b.connect():b.remove()}},graphChanged:function(){Iframework.$(".source").is(":visible")&&window.setTimeout(function(){Iframework.sourcerefresh()},100)}}),Iframework.Graphs=Backbone.Collection.extend({model:Iframework.Graph})}),$(function(){var a='<div class="edges"><svg id="edgesSvg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg></div><div class="nodes" />';Iframework.GraphView=Backbone.View.extend({tagName:"div",className:"graph",template:_.template(a),events:{click:"click"},initialize:function(){this.render(),Iframework.$el.prepend(this.el),this.model.get("nodes").each(this.addNode),this.resizeEdgeSVG()},render:function(){return this.$el.html(this.template(this.model.toJSON())),this},click:function(a){$(".edge-edit").remove(),Iframework.selectedPort=null,$("div.module").removeClass("active")},addNode:function(a){this.$(".nodes").append(a.initializeView().el)},addEdge:function(a){a.initializeView(),a.source.view&&a.source.view.resetRelatedEdges(),a.target.view&&a.target.view.resetRelatedEdges()},removeNode:function(a){a.view&&a.view.$el.remove()},removeEdge:function(a){a.view&&a.view.remove(),a.source&&a.source.view&&a.source.view.resetRelatedEdges(),a.target&&a.target.view&&a.target.view.resetRelatedEdges()},resizeEdgeSVG:function(){var a=0,b=0;this.model.get("nodes").each(function(c){var d=c.get("x")+c.get("w");d>a&&(a=d);var e=c.get("y")+c.get("h");e>b&&(b=e)},this),a+=150,b+=50,this.$("#edgesSvg").css({width:a,height:b})}})}),$(function(){Iframework.Node=Backbone.Model.extend({loaded:!1,defaults:function(){return{src:"",x:100,y:400,z:0,w:200,h:200,state:{}}},initialize:function(){this.Inputs=new Iframework.Ports,this.Outputs=new Iframework.Ports,this.on("change",this.nodeChanged)},initializeView:function(){return this.view=new Iframework.NodeView({model:this}),this.view},send:function(a){window.frames[this.frameIndex]?window.frames[this.frameIndex].postMessage(a,"*"):console.error("wat "+this.id+" "+this.frameIndex)},Info:{},infoLoaded:function(a){this.view&&(this.Info=a,this.view.infoLoaded(a))},setState:function(a){this.send({setState:a})},stateReady:function(){this.get("state")&&this.setState(this.get("state")),this.loaded=!0,this.graph.checkLoaded()},addInput:function(a){var b=this.Inputs.findByName(a.name);if(b)return;var c=new Iframework.Port(a);c.isIn=!0,c.node=this,c.graph=this.graph,this.Inputs.add(c),this.view&&this.view.addInput(c);var d=this.get("state");a.hasOwnProperty("default")&&a.default!=""&&!d.hasOwnProperty(a.name)&&(d[a.name]=a.default)},addOutput:function(a){var b=this.Outputs.findByName(a.name);if(b)return;var c=new Iframework.Port(a);c.isIn=!1,c.node=this,c.graph=this.graph,this.Outputs.add(c),this.view&&this.view.addOutput(c)},nodeChanged:function(){this.graph&&this.graph.trigger("change")},remove:function(){this.graph.removeNode(this)}}),Iframework.Nodes=Backbone.Collection.extend({model:Iframework.Node})}),$(function(){var a='<div class="module" style="left:<%= get("x")-10 %>px;top:<%= get("y")-30 %>px;width:<%= get("w")+20 %>px;height:<%= get("h")+40 %>px;" ><div class="ports ports-in"></div><div class="ports ports-out"></div><h1 class="title">...</h1><button type="button" class="showcontrols">show controls</button><div class="controls"><button type="button" class="remove">remove</button><button type="button" class="refresh">refresh</button><button type="button" class="hidecontrols">hide controls</button></div><iframe class="frame" name="<%= frameIndex %>" src="<%= get("src") %>" style="width:<%= get("w") %>px;height:<%= get("h") %>px;"></iframe></div>';Iframework.NodeView=Backbone.View.extend({tagName:"div",className:"node",template:_.template(a),events:{"dragstart .module":"dragstart","drag .module":"drag","dragstop .module":"dragstop","resizestart .module":"resizestart","resize .module":"resize","resizestop .module":"resizestop","mousedown .module, .title":"mousedown","click .module, .title":"click","click .showcontrols":"showControls","click .hidecontrols":"hideControls","click .refresh":"refresh","click .remove":"removeModel"},initialize:function(){this.render(),this.$(".module").draggable({handle:"h1"}).resizable(),this.$(".showcontrols").button({icons:{primary:"ui-icon-carat-1-w"},text:!1}),this.$(".hidecontrols").button({icons:{primary:"ui-icon-carat-1-e"},text:!1}),this.$(".refresh").button({icons:{primary:"ui-icon-arrowrefresh-1-s"},text:!1}),this.$(".remove").button({icons:{primary:"ui-icon-trash"},text:!1}),this.$("h1").disableSelection()},render:function(){return this.$el.html(this.template(this.model)),this},infoLoaded:function(a){this.$("h1").text(this.model.get("id")+": "+a.title).attr({title:"by "+a.author+": "+a.description})},_relatedEdges:null,relatedEdges:function(){return this._relatedEdges===null&&(this._relatedEdges=this.model.graph.get("edges").filter(function(a){return a.get("source")[0]===this.model.get("id")||a.get("target")[0]===this.model.get("id")},this)),this._relatedEdges},resetRelatedEdges:function(){this._relatedEdges=null,this.relatedEdges()},dragstart:function(a,b){Iframework.maskFrames()},drag:function(a,b){_.each(this.relatedEdges(),function(a){a.view&&a.view.redraw()})},dragstop:function(a,b){Iframework.unmaskFrames(),this.drag(),this.model.set({x:b.offset.left+10+$(".graph").scrollLeft(),y:b.offset.top+30+$(".graph").scrollTop()}),this.model.graph.view.resizeEdgeSVG()},resizestart:function(a,b){Iframework.maskFrames()},resize:function(a,b){this.drag()},resizestop:function(a,b){Iframework.unmaskFrames();var c=b.size.width,d=b.size.height;this.model.set({w:c-20,h:d-40}),this.$(".frame").css({width:c-20,height:d-40}),this.model.graph.view.resizeEdgeSVG(),this.drag()},mousedown:function(a,b){$("div.module").removeClass("active");var c=0;$("div.nodes div.module").each(function(){var a=Number($(this).css("z-index"));a>c&&(c=a)}),this.$(".module").css("z-index",c+1).addClass("active")},click:function(a){a.stopPropagation()},addInput:function(a){this.$(".ports-in").append(a.initializeView().el)},addOutput:function(a){this.$(".ports-out").append(a.initializeView().el)},showControls:function(){this.$(".showcontrols").hide(),this.$(".controls").show()},hideControls:function(){this.$(".showcontrols").show(),this.$(".controls").hide()},refresh:function(){this.$(".frame")[0].src=this.model.get("src")},removeModel:function(){this.model.remove()},remove:function(){this.$el.remove()}})}),$(function(){Iframework.Module=Backbone.Model.extend({defaults:{src:"",info:{},inputs:[],outputs:[]},initialize:function(){},initializeView:function(){return this.view||(this.view=new Iframework.ModuleView({model:this})),this.view},toJSON:function(){return{src:this.get("src"),info:this.get("info"),inputs:this.get("inputs"),outputs:this.get("outputs")}}}),Iframework.Modules=Backbone.Collection.extend({model:Iframework.Module,findOrAdd:function(a){var b;return b=this.find(function(b){return b.get("src")===a.get("src")}),b||(b=new Iframework.Module({node:a}),this.add(b)),b}})}),$(function(){var a='<button class="addnode" type="button">add node</button><h2 class="title"><%= info.title %></h2><p class="description"><%= info.description %></p><p class="src"><%= src %></p><ul class="inputs"></ul><ul class="outputs"></ul>';Iframework.ModuleView=Backbone.View.extend({tagName:"div",className:"librarymodule",template:_.template(a),events:{"click .addnode":"addnode"},initialize:function(){return this.render(),Iframework.$(".panel .library .listing").append(this.el),this.$(".addnode").button({icons:{primary:"ui-icon-plus"},text:!1}),this},render:function(){this.$el.html(this.template(this.model.toJSON()))},addnode:function(){Iframework.shownGraph.addNode(new Iframework.Node({src:this.model.get("src")}))}})}),$(function(){Iframework.Port=Backbone.Model.extend({defaults:{name:"",type:"",description:"","default":null},initialize:function(){this.get("type")===""&&this.set("type","all"),this.set("type_class",this.get("type").split("/")[0].replace(":","_"))},initializeView:function(){return this.view=new Iframework.PortView({model:this})}}),Iframework.Ports=Backbone.Collection.extend({model:Iframework.Ports,findByName:function(a){return this.find(function(b){return b.get("name")===a})}})}),$(function(){var a='<div class="portshown portshown-in"><span class="hole hole-in hole-<%= type_class %>"></span><span class="label"><%= name %></span></div><span class="plugend plugend-in plugend-<%= type_class %>"></span>',b='<div class="portshown portshown-out"><span class="label"><%= name %></span><span class="hole hole-out hole-<%= type_class %>"></span></div><span class="plugend plugend-out plugend-<%= type_class %>"></span>',c='<div class="edge-edit"><button class="close">close</button><h2><%= name %> (<%= type %>)</h2><p><%= description %></p></div>',d='<div class="edge-edit-item" id="<%= model.cid %>"><span><%= label() %></span><button class="disconnect" type="button">disconnect</button></div>';Iframework.PortView=Backbone.View.extend({tagName:"div",className:"port",portInTemplate:_.template(a),portOutTemplate:_.template(b),popupTemplate:_.template(c),edgeEditTemplate:_.template(d),events:{mousedown:"highlightEdge","click .hole":"clickhole","dragstart .hole":"dragstart","drag .hole, .holehelper":"drag","dragstop .hole, .holehelper":"dragstop","dragstart .plugend":"unplugstart","drag .plugend":"unplugdrag","dragstop .plugend":"unplugstop",drop:"drop","click .disconnect":"disconnect","submit .manualinput":"manualinput"},initialize:function(){return this.render(),this},render:function(){this.model.isIn?(this.$el.html(this.portInTemplate(this.model.toJSON())),this.$el.addClass("port-in"),this.$(".hole").draggable({helper:function(a){return $('<span class="holehelper holehelper-out" />')}}),this.$(".plugend").draggable({helper:function(a){return $('<span class="plugendhelper plugendhelper-in" />')}})):(this.$el.html(this.portOutTemplate(this.model.toJSON())),this.$el.addClass("port-out"),this.$(".hole").draggable({helper:function(a){return $('<span class="holehelper holehelper-in" />')}}),this.$(".plugend").draggable({helper:function(a){return $('<span class="plugendhelper plugendhelper-out" />')}})),this.$(".hole").data({model:this.model}).button({icons:{primary:"ui-icon-arrow-1-e"},text:!1});var a="";if(this.model.get("type")==="all")this.model.isIn?a=".hole-out, .plugend-in":a=".hole-in .plugend-out";else{var b=this.model.get("type_class");this.model.isIn?a=".hole-out.hole-all, .hole-out.hole-"+b+", .plugend-in.plugend-all, .plugend-in.plugend-"+b:a=".hole-in.hole-all, .hole-in.hole-"+b+", .plugend-out.plugend-all, .plugend-out.plugend-"+b}this.$el.droppable({hoverClass:"drophover",accept:a}),this.$(".plugend").hide(),this.$(".portshown").disableSelection()},dragstart:function(a,b){Iframework.maskFrames(),$("div.ports-"+(this.model.isIn?"out":"in")+" span.hole-"+this.model.get("type_class")).addClass("highlight");var c=new Iframework.EdgeView;Iframework.edgePreview=c,this.drag(a,b),this.$(".plugend").show(),a.stopPropagation()},drag:function(a,b){if(Iframework.edgePreview){var c=b.offset.left+$(".graph").scrollLeft(),d=b.offset.top+6+$(".graph").scrollTop(),e=this.portOffsetLeft(),f=this.portOffsetTop(),g={fromX:this.model.isIn?c-2:e,fromY:this.model.isIn?d:f,toX:this.model.isIn?e:c+20,toY:this.model.isIn?f:d};Iframework.edgePreview.setPositions(g),Iframework.edgePreview.redraw()}a.stopPropagation()},dragstop:function(a,b){Iframework.unmaskFrames(),$(".hole").removeClass("highlight"),Iframework.edgePreview.remove(),Iframework.edgePreview=undefined,this.relatedEdges().length<1&&this.$(".plugend").hide(),a.stopPropagation()},drop:function(a,b){if(this.armDelete)this.armDelete=!1;else{var c=$(b.draggable).data("model"),d=this.model,e=this.model.isIn?c:d,f=this.model.isIn?d:c,g=new Iframework.Edge({source:[e.node.get("id"),e.get("name")],target:[f.node.get("id"),f.get("name")]});g.graph=this.model.graph,Iframework.edgePreview&&(g._color=Iframework.edgePreview._color),g.graph.addEdge(g)&&g.connect()}a.stopPropagation()},unpluggingEdge:null,armDeleteTimeout:null,armDelete:!1,topConnectedEdge:function(){var a,b=0;return _.each(this.relatedEdges(),function(c){c.view._z>=b&&(b=c.view._z,a=c)},this),a},unplugstart:function(a,b){Iframework.maskFrames();var c=this.topConnectedEdge();if(!c)return!1;this.unpluggingEdge=c,this.unpluggingEdge.view.dim(),this.relatedEdges().length===1&&this.$(".plugend").hide();var d=this.model.isIn?this.unpluggingEdge.source:this.unpluggingEdge.target;this.$(".plugend").data("model",d),$("div.ports-"+(this.model.isIn?"in":"out")+" span.hole-"+this.model.get("type_class")).addClass("highlight");var e=new Iframework.EdgeView;e.setColor(this.unpluggingEdge.view._color),Iframework.edgePreview=e,this.armDelete=!0,a.stopPropagation()},unplugdrag:function(a,b){if(Iframework.edgePreview&&this.unpluggingEdge){var c=b.offset.left+$(".graph").scrollLeft(),d=b.offset.top+6+$(".graph").scrollTop(),e=this.model.isIn?this.unpluggingEdge.source.view:this.unpluggingEdge.target.view,f=e.portOffsetLeft(),g=e.portOffsetTop(),h={fromX:this.model.isIn?f:c-2,fromY:this.model.isIn?g:d,toX:this.model.isIn?c+20:f,toY:this.model.isIn?d:g};Iframework.edgePreview.setPositions(h),Iframework.edgePreview.redraw()}a.stopPropagation()},unplugstop:function(a,b){this.armDelete&&this.unpluggingEdge?this.model.graph.removeEdge(this.unpluggingEdge):(this.$(".plugend").show(),this.unpluggingEdge.view.undim()),this.armDelete=!1,this.unpluggingEdge=null,this.dragstop(a,b)},clickhole:function(a){$("div.edge-edit").remove();var b=this.$(".hole"),c=this.model.isIn,d=this.model.get("name");if(Iframework.selectedPort&&c!==Iframework.selectedPort.isIn){if(c)var e=new Iframework.Edge({source:[Iframework.selectedPort.node.get("id"),Iframework.selectedPort.get("name")],target:[this.model.node.get("id"),this.model.get("name")]});else var e=new Iframework.Edge({source:[this.model.node.get("id"),this.model.get("name")],target:[Iframework.selectedPort.node.get("id"),Iframework.selectedPort.get("name")]});e.graph=Iframework.shownGraph,e.graph.addEdge(e)&&e.connect(),Iframework.edgePreview&&(Iframework.shownGraph.view.$(".edges").children(".preview").remove(),Iframework.edgePreview=undefined),Iframework.selectedPort=null;return}var f=this.popupTemplate(this.model.toJSON());f=$(f),this.$el.append(f),f.children("button.close").button({icons:{primary:"ui-icon-close"},text:!1}).click(function(){$("div.edge-edit").remove(),Iframework.selectedPort=null});var g=this.model.get("type").substring(0,3);if(c){var h=!1,i=$("<form />").attr({id:this.model.node.id+"_"+this.model.get("name"),"class":"manualinput"});if(g==="int"||g==="num")h=!0,i.append($("<input />").attr({type:"number",min:b.data("min"),max:b.data("max"),value:this.model.node.get("state")[this.model.get("name")]}));else if(g==="col"||g==="str")h=!0,i.append($("<input />").attr({type:"text",maxlength:b.data("max"),value:this.model.node.get("state")[this.model.get("name")]}));else if(g==="boo"){h=!0;var j=this.model.node.get("state")[this.model.get("name")];j=Boolean(j)&&j!="false",i.append($("<input />").attr({type:"checkbox",checked:j}))}else g==="ban"&&(i.append("<label>Send bang:</label> "),h=!0);h&&(i.append($("<button></button>").html("send").attr({type:"submit","class":"send",title:"send value to module"}).button({icons:{primary:"ui-icon-check"},text:!1})),f.append(i))}$("#select_"+this.model.id).button({icons:{primary:"ui-icon-power"}}),this.relatedEdges().length>0&&(f.append("<h2>disconnect</h2>"),_.each(this.relatedEdges(),function(a){var b=this.edgeEditTemplate(a.view);f.append(b)},this),$(".disconnect").button({icons:{primary:"ui-icon-scissors"},text:!1})),this.model.get("options")&&this.model.get("options").length>0&&this.$("input").autocomplete({minLength:0,source:this.model.get("options")}),a.stopPropagation()},manualinput:function(a){var b=this.model.get("name"),c=this.$(".manualinput").children("input")?this.$(".manualinput").children("input").val():"bang!";this.$(".manualinput").children("input:checkbox").length>0&&(this.$(".manualinput").children("input:checkbox").is(":checked")?c=!0:c=!1),this.model.get("type")==="int"&&(c=parseInt(c)),this.model.get("type")==="number"&&(c=parseFloat(c));var d={};return d[b]=c,this.model.node.send(d),this.model.node.get("state")[b]=c,this.model.node.trigger("change"),$("div.edge-edit").remove(),!1},disconnect:function(a){var b=this.model.graph.get("edges").getByCid($(a.target).parents(".edge-edit-item").attr("id"));b&&this.model.graph.removeEdge(b),$("div.edge-edit").remove(),Iframework.selectedPort=null,a.stopPropagation()},portOffsetLeft:function(){var a=this.$(".hole").offset();return a?a.left+7+$(".graph").scrollLeft():0},portOffsetTop:function(){var a=this.$(".hole").offset();return a?a.top+7+$(".graph").scrollTop():0},_relatedEdges:null,relatedEdges:function(){return this._relatedEdges===null&&(this._relatedEdges=this.model.graph.get("edges").filter(function(a){return a.source===this.model||a.target===this.model},this),this._relatedEdges.length>=1?this.$(".plugend").show():this.$(".plugend").hide(),this.model.node.view.resetRelatedEdges()),this._relatedEdges},resetRelatedEdges:function(){this._relatedEdges=null,this.relatedEdges()},highlightEdge:function(){this.relatedEdges().length>0&&this.topConnectedEdge().view.highlight()},highlight:function(){var a=this.$(".plugend");a.addClass("highlight"),setTimeout(function(){a.removeClass("highlight")},1e3)}})}),$(function(){Iframework.Edge=Backbone.Model.extend({defaults:{source:[0,"default"],target:[0,"default"]},initialize:function(){},initializeView:function(){return this.view=new Iframework.EdgeView({model:this}),this.view},source:null,target:null,connect:function(){for(var a=0;a<this.graph.get("nodes").length;a++)this.graph.get("nodes").at(a).get("id")===this.get("source")[0]&&(this.source=this.graph.get("nodes").at(a).Outputs.findByName(this.get("source")[1])),this.graph.get("nodes").at(a).get("id")===this.get("target")[0]&&(this.target=this.graph.get("nodes").at(a).Inputs.findByName(this.get("target")[1]));return!this.source||!this.target?!1:(this.source.node.send({connect:{source:[this.source.node.frameIndex,this.get("source")[1]],target:[this.target.node.frameIndex,this.get("target")[1]]}}),this.graph.view&&this.graph.view.addEdge(this),this)},disconnect:function(){this.source&&this.target&&this.source.node.send({disconnect:{source:[this.source.node.frameIndex,this.get("source")[1]],target:[this.target.node.frameIndex,this.get("target")[1]]}}),this.view&&this.view.remove()},remove:function(){this.graph.removeEdge(this)}}),Iframework.Edges=Backbone.Collection.extend({model:Iframework.Edge})}),$(function(){Iframework.EdgeView=Backbone.View.extend({tagName:"div",className:"edge",positions:null,graphSVGElement:null,elementGroup:null,elementWire:null,elementShadow:null,isPreview:!1,initialize:function(){this.graphSVGElement=document.getElementById("edgesSvg"),this.positions={fromX:0,fromY:0,toX:0,toY:0},this.model||(this.isPreview=!0),this.model&&this.model._color&&(this._color=this.model._color),this.render(),this.model&&(this._z=this.model.graph.edgeCount++,$(this.elementWire).data({model:this.model}).click(function(a){$(a.target).data("model").view.click(a)}))},render:function(){return this.calcPositions(),this.elementGroup=this.makeSVG("g",{transform:"translate("+this.svgX()+","+this.svgY()+")","class":"wire-group"+(this.isPreview?" preview":"")}),this.elementShadow=this.makeSVG("path",{"class":"wire-shadow",d:this.svgPathShadow()}),this.elementWire=this.makeSVG("path",{"class":"wire",d:this.svgPath(),stroke:this.color()}),this.elementGroup.appendChild(this.elementShadow),this.elementGroup.appendChild(this.elementWire),this.graphSVGElement.appendChild(this.elementGroup),this.model&&(this.model.source.view.$(".plugend").show(),this.model.target.view.$(".plugend").show()),this},redraw:function(){this.calcPositions(),$(this.elementGroup).attr("transform","translate("+this.svgX()+", "+this.svgY()+")"),$(this.elementWire).attr("d",this.svgPath()),$(this.elementShadow).attr("d",this.svgPathShadow())},remove:function(){$(this.elementGroup).remove()},setPositions:function(a){this.positions=a},calcPositions:function(){if(this.model){var a=this.model.get("source")[1],b=this.model.get("target")[1];this.positions.fromX=this.model.source.view.portOffsetLeft("out",a),this.positions.fromY=this.model.source.view.portOffsetTop("out",a),this.positions.toX=this.model.target.view.portOffsetLeft("in",b),this.positions.toY=this.model.target.view.portOffsetTop("in",b)}},svgX:function(){return Math.min(this.positions.toX,this.positions.fromX)-50},svgY:function(){return Math.min(this.positions.toY,this.positions.fromY)-25},svgW:function(){return Math.abs(this.positions.toX-this.positions.fromX)+100},svgH:function(){return Math.abs(this.positions.toY-this.positions.fromY)+50},pathStraight:35,pathCurve:60,svgPath:function(){var a=this.positions.fromX-this.svgX(),b=this.positions.fromY-this.svgY(),c=this.positions.toX-this.svgX(),d=this.positions.toY-this.svgY();return"M "+a+" "+b+" L "+(a+this.pathStraight)+" "+b+" C "+(a+this.pathCurve)+" "+b+" "+(c-this.pathCurve)+" "+d+" "+(c-this.pathStraight)+" "+d+" L "+c+" "+d},svgPathShadow:function(){var a=this.positions.fromX-this.svgX(),b=this.positions.fromY-this.svgY()+1,c=this.positions.toX-this.svgX(),d=this.positions.toY-this.svgY()+1;return"M "+a+" "+b+" L "+(a+this.pathStraight)+" "+b+" C "+(a+this.pathCurve)+" "+b+" "+(c-this.pathCurve)+" "+d+" "+(c-this.pathStraight)+" "+d+" L "+c+" "+d},color:function(){return this._color?this._color:this.model?this._color=Iframework.getWireColor():Iframework.wireColors[Iframework.wireColorIndex]},setColor:function(a){this._color=a,$(this.elementWire).attr("stroke",a)},label:function(){return this.model.get("source")[0]+":"+this.model.get("source")[1]+'<span class="wiresymbol" style="color:'+this._color+'">&rarr;</span>'+this.model.get("target")[0]+":"+this.model.get("target")[1]},makeSVG:function(a,b){var c=document.createElementNS("http://www.w3.org/2000/svg",a);for(var d in b)d==="xlink:href"?c.setAttributeNS("http://www.w3.org/1999/xlink","href",b[d]):c.setAttribute(d,b[d]);return c},dim:function(){$(this.elementGroup).attr("opacity",.2)},undim:function(){$(this.elementGroup).attr("opacity",1)},click:function(a){this._z<this.model.graph.edgeCount-1&&(this.graphSVGElement.appendChild(this.elementGroup),this._z=this.model.graph.edgeCount++),this.highlight()},highlight:function(){var a=$(this.elementShadow);a.attr("class","wire-shadow highlight"),setTimeout(function(){a.attr("class","wire-shadow")},1e3),this.model.source.view&&this.model.source.view.highlight(),this.model.target.view&&this.model.target.view.highlight()}})});
View
5 iframework.css
@@ -269,12 +269,11 @@ div.module {
right: 3px;
}
span.plugend.highlight {
- /*box-shadow: 10px 10px 5px #888;*/
- border-style: solid;
+ background-color: #FFE87C;
border-color: #FFE87C;
+ border-style: solid;
border-width: 2px 0px;
margin-top: -2px;
- background-color: #FFE87C;
}
div.port span.label {
font-family: 'Nova Flat', monospace;
View
37 js/iframework-port-view.js
@@ -205,29 +205,28 @@ $(function(){
unpluggingEdge: null,
armDeleteTimeout: null,
armDelete: false,
+ topConnectedEdge: function () {
+ var topConnected;
+ var topZ = 0;
+ _.each(this.relatedEdges(), function(edge){
+ if (edge.view._z >= topZ) {
+ topZ = edge.view._z;
+ topConnected = edge;
+ }
+ }, this);
+ return topConnected;
+ },
unplugstart: function (event, ui) {
// Add a mask so that iframes don't steal mouse
Iframework.maskFrames();
// Find top connected wire
- var lastConnected;
- var countConnected = 0;
- var topZ = 0;
- this.model.graph.get("edges").each(function(edge){
- if (edge.source === this.model || edge.target === this.model) {
- countConnected++;
- if (edge.view._z >= topZ) {
- topZ = edge.view._z;
- lastConnected = edge;
- }
- }
- }, this);
-
+ var lastConnected = this.topConnectedEdge();
if (!lastConnected) { return false; }
this.unpluggingEdge = lastConnected;
this.unpluggingEdge.view.dim();
- if (countConnected===1) {
+ if (this.relatedEdges().length===1) {
this.$(".plugend").hide();
}
@@ -506,15 +505,7 @@ $(function(){
highlightEdge: function () {
if (this.relatedEdges().length > 0) {
// Find top connected wire
- var lastConnected;
- var topZ = 0;
- _.each( this.relatedEdges(), function (edge) {
- if (edge.view._z >= topZ) {
- topZ = edge.view._z;
- lastConnected = edge;
- }
- }, this);
- lastConnected.view.highlight();
+ this.topConnectedEdge().view.highlight();
}
},
highlight: function () {

0 comments on commit a866022

Please sign in to comment.
Something went wrong with that request. Please try again.