github.com/aitjcize/Overlord@v0.0.0-20240314041920-104a804cf5e8/overlord/app/common/js/BaseWindow.jsx (about) 1 // Copyright 2016 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 // 5 // Defines common functions of Windows. 6 7 var BaseWindow = { 8 makeDraggable: function (cancel) { 9 var el = this.refs.window; 10 var $el = $(el); 11 $el.draggable({ 12 // Once the window is dragged, make its position fixed. 13 stop: function () { 14 offsets = el.getBoundingClientRect(); 15 $el.css({ 16 position: "fixed", 17 top: offsets.top+"px", 18 left: offsets.left+"px" 19 }); 20 }, 21 cancel: cancel 22 }); 23 }, 24 enableDraggable: function () { 25 $(this.refs.window).draggable('enable'); 26 }, 27 disableDraggable: function () { 28 $(this.refs.window).draggable('disable'); 29 }, 30 onWindowMouseDown: function (event) { 31 this.bringToFront(); 32 }, 33 onCloseMouseUp: function (event) { 34 var callback = this.props.onCloseClicked; 35 if (typeof(callback) != "undefined") { 36 (callback.bind(this))(event); 37 } 38 }, 39 onMinimizeMouseUp: function (event) { 40 var callback = this.props.onMinimizeClicked; 41 if (typeof(callback) != "undefined") { 42 (callback.bind(this))(event); 43 } 44 }, 45 bringToFront: function () { 46 if (typeof(window.maxz) == "undefined") { 47 window.maxz = parseInt($('.navbar').css('z-index')) + 1; 48 } 49 var $el = $(this.refs.window); 50 if ($el.css("z-index") != window.maxz) { 51 window.maxz += 1; 52 $el.css("z-index", window.maxz); 53 } 54 } 55 };