Last active
December 12, 2015 12:19
-
-
Save lsiv568/4771122 to your computer and use it in GitHub Desktop.
dojo DockableComponent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
"dojo/_base/declare", | |
"dojo/_base/lang", | |
"dojo/aspect", | |
"dojo/_base/window", | |
"dojo/dom-attr", | |
"dojo/dom-class", | |
"dojo/dom-construct", | |
"dojo/dom-geometry", | |
"dojo/query", | |
"dijit/focus", | |
"MW/motw/MotwApp" | |
], function (declare, lang, aspect, dojoWindow, domAttr, domClass, domConstruct, domGeometry, query, focus, MotwApp) { | |
return declare([], { | |
DOCKABLE_COMPONENT_CSS: "css/dockableComponent.css", | |
constructor: function () { | |
aspect.after(this, "postCreate", lang.hitch(this, this.init)); | |
}, | |
init: function () { | |
var that = this; | |
var dockButtonDiv = this.dockButtonContainer; | |
this.dockButton = domConstruct.create("button", {}, dockButtonDiv); | |
domClass.add(this.dockButton, "undockable"); | |
domClass.add(dockButtonDiv, "dockButtonContainer"); | |
aspect.after(this.dockButton, "onmousedown", function() { | |
if (domClass.contains(that.dockButton, "undockable")) { | |
MotwApp.layoutService.undockWidget(that); | |
} else { | |
MotwApp.layoutService.dockWidget(that); | |
} | |
}); | |
}, | |
undock: function (window) { | |
var extraCSS = this.getExtraCSS ? this.getExtraCSS() : []; | |
var theHead = query("head", window.document)[0]; | |
extraCSS.push(this.DOCKABLE_COMPONENT_CSS); | |
domClass.remove(this.dockButton, "undockable"); | |
domClass.add(this.dockButton, "dockable"); | |
extraCSS.forEach(function (css) { | |
var theLink = domConstruct.create("link"); | |
domAttr.set(theLink, "rel", "stylesheet"); | |
domAttr.set(theLink, "href", css); | |
domConstruct.place(theLink, theHead); | |
}); | |
this.placeAt(window.document.body); | |
}, | |
dock: function () { | |
domClass.remove(this.dockButton, "dockable"); | |
domClass.add(this.dockButton, "undockable"); | |
}, | |
getPosition: function() { | |
return domGeometry.position(this.domNode, true); | |
} | |
}); | |
} | |
); | |
/** | |
* Created by IntelliJ IDEA. | |
* User: lsivillo | |
* Date: 1/25/13 | |
* Time: 7:53 AM | |
* To change this template use File | Settings | File Templates. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment