text: /*! Rappid v2.0.1 - HTML5 Diagramming Framework - TRIAL VERSION
  
  Copyright (c) 2015 client IO
  
   2017-02-01 
  
  
  This Source Code Form is subject to the terms of the Rappid Trial License
  , v. 2.0. If a copy of the Rappid License was not distributed with this
  file, You can obtain one at http://jointjs.com/license/rappid_v2.txt
   or from the Rappid archive as was distributed by client IO. See the LICENSE file.*/
  
  
  joint.ui.SelectBox=joint.mvc.View.extend({className:"select-box",events:{"click .select-box-selection":"onToggle"},options:{options:[],width:void 0,openPolicy:"auto",target:null,keyboardNavigation:!0,selected:void 0,selectBoxOptionsClass:void 0,disabled:!1},init:function(){this.options.target=this.options.target||document.body,_.bindAll(this,"onOutsideClick","onOptionSelect"),$(document).on("click.selectBox",this.onOutsideClick),this.$el.data("view",this),_.isUndefined(this.options.selected)?this.selection=_.findWhere(this.options.options,{selected:!0})||this.options.options[0]:this.selection=this.options.options[this.options.selected]},render:function(){return this.$el.empty(),this.$selection=null,this.renderSelection(this.selection),this.options.width&&this.$el.css("width",this.options.width),this.options.disabled&&this.disable(),this.$el.append(this.$options),this},renderOptions:function(){this.removeOptions();var a={selectBoxView:this,parentClassName:_.result(this,"className")||null,extraClassName:_.result(this.options,"selectBoxOptionsClass")||null,options:this.options.options};this.options.width&&(a.width=this.options.width),this.optionsView=new this.constructor.OptionsView(a),this.optionsView.render(),this.listenTo(this.optionsView,"option:select",this.onOptionSelect),this.listenTo(this.optionsView,"option:hover",this.onOptionHover),this.listenTo(this.optionsView,"options:mouseout",this.onOptionsMouseOut),this.$options=this.optionsView.$el,this.$optionsArrow=this.optionsView.$arrow,this.$target=$(this.options.target)},onOptionHover:function(a,b){this.trigger("option:hover",a,b)},onOptionsMouseOut:function(a){this.trigger("options:mouseout",a)},onOptionSelect:function(a,b){this.select(a,b)},removeOptions:function(){this.optionsView&&(this.stopListening(this.optionsView),this.optionsView.remove(),this.optionsView=null)},renderSelection:function(a){if(this.$selection||(this.$selection=$("<div/>",{"class":"select-box-selection"}),this.$el.append(this.$selection)),this.$selection.empty(),a){var b=this.constructor.OptionsView.prototype.renderOptionContent.call(void 0,a);this.$selection.append(b)}else if(this.options.placeholder){var c=$("<div/>",{"class":"select-box-placeholder",html:this.options.placeholder});this.$selection.append(c)}},onToggle:function(a){this.toggle()},onOutsideClick:function(a){!this.el.contains(a.target)&&this.$el.hasClass("opened")&&this.close()},getSelection:function(){return this.selection},getSelectionValue:function(a){return a=a||this.selection,a&&(_.isUndefined(a.value)?a.content:a.value)},getSelectionIndex:function(){return _.findIndex(this.options.options,this.selection)},select:function(a,b){this.selection=this.options.options[a],this.renderSelection(this.selection),this.trigger("option:select",this.selection,a,b),this.close()},selectByValue:function(a,b){for(var c=this.options.options||[],d=0;d<c.length;d++){var e=c[d];if(_.isUndefined(e.value)&&e.content===a)return this.select(d,b);if(!_.isUndefined(e.value)&&_.isEqual(e.value,a))return this.select(d,b)}},isOpen:function(){return this.$el.hasClass("opened")},toggle:function(){this.isOpen()?this.close():this.open()},position:function(){var a=this.$(".select-box-selection"),b=a.outerHeight(),c=a.offset(),d=c.left,e=c.top,f=this.$options.outerHeight(),g={left:0,top:0};this.options.target!==document.body?(g=this.$target.offset(),g.width=this.$target.outerWidth(),g.height=this.$target.outerHeight(),g.left-=this.$target.scrollLeft(),g.top-=this.$target.scrollTop()):(g.width=$(window).width(),g.height=$(window).height());var h=d,i="auto",j=this.options.openPolicy;switch("selected"!==j||this.selection||(j="auto"),j){case"above":i=e-f;break;case"coverAbove":i=e-f+b;break;case"below":i=e+b;break;case"coverBelow":i=e;break;case"selected":var k=this.$options.find(".selected").position();i=e-k.top;break;default:var l=e-this.$target.scrollTop()+f>g.top+g.height;i=l?e-f+b:e}h-=g.left,i-=g.top,this.$options.css({left:h,top:i})},open:function(){this.isDisabled()||(this.renderOptions(),this.$options.appendTo(this.options.target),this.$options.addClass("rendered"),this.position(),this.$el.addClass("opened"),this.respectWindowBoundaries(),this.alignOptionsArrow())},respectWindowBoundaries:function(){var a=this.calculateElOverflow(this.$options),b={left:0,top:0};this.$options.outerWidth()<=this.$target.innerWidth()&&(a.left&&a.right||(a.left?b.left=a.left:a.right&&(b.left=-a.right))),this.$options.outerHeight()<=this.$target.innerHeight()&&(a.top&&a.bottom||(a.top?b.top=a.top:a.bottom&&(b.top=-a.bottom))),this.$options.css({left:"+="+b.left,top:"+="+b.top})},alignOptionsArrow:function(){var a=this.$el[0].getBoundingClientRect(),b=this.$options[0].getBoundingClientRect(),c=a.left+a.width/2;c-=b.left,c-=this.$optionsArrow.outerWidth()/2,this.$optionsArrow.css({left:c})},close:function(){this.removeOptions(),this.$el.removeClass("opened"),this.trigger("close")},onRemove:function(){this.removeOptions(),$(document).off(".selectBox",this.onOutsideClick)},isDisabled:function(){return this.$el.hasClass("disabled")},enable:function(){this.$el.removeClass("disabled")},disable:function(){this.close(),this.$el.addClass("disabled")},onSetTheme:function(a,b){this.$options&&(a&&this.$options.removeClass(this.themeClassNamePrefix+a),this.$options.addClass(this.themeClassNamePrefix+b))},calculateElOverflow:function(a,b){b||(b=window),a instanceof jQuery&&(a=a[0]),b instanceof jQuery&&(b=b[0]);var c,d={},e=a.getBoundingClientRect();if(b===window){var f=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,g=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;c={width:f,height:g,left:0,top:0,right:f,bottom:g}}else c=b.getBoundingClientRect();return _.each(["left","top"],function(a){d[a]=Math.min(0,e[a]-c[a])}),_.each(["right","bottom"],function(a){d[a]=Math.min(0,c[a]-e[a])}),_.each(d,function(a,b){d[b]=Math.abs(Math.round(a))}),d}},{OptionsView:joint.mvc.View.extend({events:{"mouseover .select-box-option":"onOptionHover","click .select-box-option":"onOptionClick"},className:function(){var a=["select-box-options"],b=this.options.parentClassName;return b&&a.push(b),a.join(" ")},init:function(){_.bindAll(this,"onMouseout","onKeydown"),$(document).on({"keydown.selectBoxOptions":this.onKeydown,"mouseleave.selectBoxOptions mouseout.selectBoxOptions":this.onMouseout})},render:function(){var a=this.options.extraClassName;return a&&this.$el.addClass(a),this.options.width&&this.$el.css("width",this.options.width),_.each(this.options.options,function(a,b){var c=this.renderOption(a,b);this.options.selectBoxView.selection===a&&c.addClass("selected hover"),this.$el.append(c)},this),this.$arrow=$("<div/>").addClass("select-box-options-arrow").appendTo(this.$el),this},renderOption:function(a,b){var c=this.renderOptionContent(a);return c.addClass("select-box-option"),c.data("index",b),c},renderOptionContent:function(a){var b=$("<div/>",{"class":"select-box-option-content",html:a.content});return a.icon&&b.prepend($("<img/>",{"class":"select-box-option-icon",src:a.icon})),b},select:function(a,b){this.trigger("option:select",a,b)},hover:function(a){var b=this.options.options[a];this.markOptionHover(a),this.trigger("option:hover",b,a)},onOptionClick:function(a){var b=this.getOptionIndex(a.target);this.select(b,{ui:!0})},onOptionHover:function(a){var b=this.getOptionIndex(a.target);this.hover(b)},onMouseout:function(a){this.trigger("options:mouseout",a)},onKeydown:function(a){var b=this.options.selectBoxView;if(b.options.keyboardNavigation&&b.isOpen()){var c;switch(a.which){case 39:case 40:c=1;break;case 38:case 37:c=-1;break;case 13:var d=this.getOptionHoverIndex();return void(d>=0&&this.select(d));case 27:return this.close();default:return}a.preventDefault();var e=this.getOptionHoverIndex(),f=e+c,g=this.options.options;f<0&&(f=g.length-1),f>=g.length&&(f=0),this.hover(f)}},onRemove:function(){$(document).off(".selectBoxOptions")},markOptionHover:function(a){this.$el.find(".hover").removeClass("hover"),$(this.$el.find(".select-box-option")[a]).addClass("hover")},getOptionHoverIndex:function(){return this.$el.find(".select-box-option.hover").index()},getOptionIndex:function(a){return $(a).closest(".select-box-option").data("index")}})});