forked from cbojaca/RappidExample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoint.ui.contextToolbar.min.js
14 lines (8 loc) · 2.24 KB
/
joint.ui.contextToolbar.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*! Rappid v1.7.1 - HTML5 Diagramming Framework - TRIAL VERSION
Copyright (c) 2015 client IO
2016-03-03
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.ContextToolbar=joint.mvc.View.extend({className:"context-toolbar",eventNamespace:"context-toolbar",events:{"click .tool":"onToolPointerdown"},options:{padding:20,autoClose:!0},init:function(){_.bindAll(this,"onDocumentMousedown")},render:function(){return this.constructor.opened&&this.constructor.close(),this.bind(),this.options.type&&this.$el.attr("data-type",this.options.type),$(this.getRoot()).append(this.$el),this.renderContent(),this.position(),this.constructor.opened=this,this},renderContent:function(){var a=$("<div/>",{"class":"tools"});this.options.tools&&_.each(this.options.tools,function(b){var c;c=b.icon?$("<img/>",{src:b.icon}):b.content;var d=$("<button/>",{"class":"tool",html:c,"data-action":b.action});b.attrs&&d.attr(b.attrs),a.append(d)}),this.$el.append(a)},getRoot:function(){return this.options.root||document.documentElement},position:function(){var a=($(this.options.target),joint.util.getElementBBox(this.options.target)),b=joint.util.getElementBBox(this.getRoot()),c=this.$el.outerWidth(),d=(this.$el.outerHeight(),a.x+a.width/2-c/2),e=a.y+a.height+this.options.padding;d-=b.x,e-=b.y,this.$el.css({left:d,top:e})},onRemove:function(){this.unbind(),this.constructor.opened=void 0},bind:function(){$(document).on("mousedown."+this.eventNamespace,this.onDocumentMousedown)},unbind:function(){return $(document).off("mousedown."+this.eventNamespace,this.onDocumentMousedown),this},onToolPointerdown:function(a){var b=$(a.target).closest("[data-action]"),c=b.attr("data-action");c&&this.trigger("action:"+c,a)},onDocumentMousedown:function(a){if(this.options.autoClose){var b=this.options.target;this.el.contains(a.target)||b.contains(a.target)||b===a.target||(this.constructor.close(),this.remove())}}},{opened:void 0,close:function(){this.opened&&(this.opened.remove(),this.opened=void 0)},update:function(){this.opened&&this.opened.position()}});