aboutsummaryrefslogtreecommitdiff
path: root/js/panels/color/colorpopup-manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/color/colorpopup-manager.js')
-rwxr-xr-xjs/panels/color/colorpopup-manager.js495
1 files changed, 349 insertions, 146 deletions
diff --git a/js/panels/color/colorpopup-manager.js b/js/panels/color/colorpopup-manager.js
index 4667f2b4..717e6fa2 100755
--- a/js/panels/color/colorpopup-manager.js
+++ b/js/panels/color/colorpopup-manager.js
@@ -9,7 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component, 10 Component = require("montage/ui/component").Component,
11 ColorChipPopup = require("js/panels/Color/colorchippopup.reel").ColorChipPopup, 11 ColorChipPopup = require("js/panels/Color/colorchippopup.reel").ColorChipPopup,
12 ColorPanelPopup = require("js/panels/Color/colorpanelpopup.reel").ColorPanelPopup; 12 ColorPanelPopup = require("js/panels/Color/colorpanelpopup.reel").ColorPanelPopup,
13 ColorModel = require("js/models/color-model").ColorModel;
13//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
14//Exporting as ColorPopupManager 15//Exporting as ColorPopupManager
15exports.ColorPopupManager = Montage.create(Component, { 16exports.ColorPopupManager = Montage.create(Component, {
@@ -26,106 +27,125 @@ exports.ColorPopupManager = Montage.create(Component, {
26 //////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////
27 // 28 //
28 init: { 29 init: {
29 enumerable: false,
30 value: function () { 30 value: function () {
31 //////////////////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////
32 //Closing popups on resize 32 //Closing popups on resize
33 window.addEventListener('resize', function (e) { 33 window.addEventListener('resize', function (e) {
34 this.application.ninja.colorController.colorPopupManager.hideColorPopup(); 34 this.application.ninja.colorController.colorPopupManager.hideColorPopup();
35 }.bind(this)); 35 }.bind(this));
36 //Storing limits of popup
37 var top, bottom, left, right;
38 //Closing popups if outside limits 36 //Closing popups if outside limits
39 document.addEventListener('mousedown', function (e) { 37 document.addEventListener('mousedown', function (e) {
40 //Checking for popup to be opened otherwise nothing happens 38 //
41 if (this._popupPanel.opened && this._popupPanel.popup && this._popupPanel.popup.element && !e._event.srcElement.inputType) { 39 if (this._popupBase && !this._popupChipBase && !this._popupGradientChipBase) {
42 //Getting horizontal limits 40 if(!this.popupHitCheck(this._popupBase, e)) {
43 left = parseInt(this._popupPanel.popup.element.style.left) + parseInt(this._popupPanel.popup.element.style.marginLeft); 41 this.hideColorPopup();
44 right = left + parseInt(this._popupPanel.popup.element.offsetWidth); 42 }
45 //Getting vertical limits 43 } else if (!this._popupBase && this._popupChipBase && !this._popupGradientChipBase) {
46 top = parseInt(this._popupPanel.popup.element.style.top) + parseInt(this._popupPanel.popup.element.style.marginTop); 44 if(!this.popupHitCheck(this._popupChipBase, e)) {
47 bottom = left + parseInt(this._popupPanel.popup.element.offsetHeight); 45 this.hideColorChipPopup();
48 //Checking click position in relation to limits 46 }
49 if ((e._event.clientX < left || e._event.clientX > right) || (e._event.clientY < top || e._event.clientY > bottom)) { 47 } else if (this._popupBase && this._popupChipBase && !this._popupGradientChipBase) {
50 //Hides popups since click is outside limits 48 if(!this.popupHitCheck(this._popupBase, e) && !this.popupHitCheck(this._popupChipBase, e)) {
51 this.application.ninja.colorController.colorPopupManager.hideColorPopup(); 49 this.hideColorPopup();
52 } 50 }
53 } 51 } else if (this._popupBase && this._popupChipBase && this._popupGradientChipBase) {
52 if(!this.popupHitCheck(this._popupBase, e) && !this.popupHitCheck(this._popupChipBase, e) && !this.popupHitCheck(this._popupGradientChipBase, e)) {
53 this.hideColorPopup();
54 }
55 } else if (!this._popupBase && this._popupChipBase && this._popupGradientChipBase) {
56 if(!this.popupHitCheck(this._popupChipBase, e) && !this.popupHitCheck(this._popupGradientChipBase, e)) {
57 this.hideColorChipPopup();
58 }
59 } else if (this._popupBase && !this._popupChipBase && this._popupGradientChipBase) {
60 if(!this.popupHitCheck(this._popupBase, e) && !this.popupHitCheck(this._popupGradientChipBase, e)) {
61 this.hideColorPopup();
62 }
63 }
54 }.bind(this)); 64 }.bind(this));
55 //////////////////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////
56 } 66 }
57 }, 67 },
58 //////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////
59 // 69 //
60 _popupPanel: { 70 popupHitCheck: {
61 enumerable: false, 71 value: function (element, e) {
62 value: {} 72 //Prevent any action for button to handle toggling
73 if (e._event.target.inputType || e._event.target.colorMode) return true;
74 //Storing limits of popup
75 var top, bottom, left, right;
76 //Checking for popup to be opened otherwise nothing happens
77 if (element && element.opened && element.popup && element.popup.element) {
78 //Getting horizontal limits
79 left = parseInt(element.popup.element.style.left) + parseInt(element.popup.element.style.marginLeft);
80 right = left + parseInt(element.popup.element.offsetWidth);
81 //Getting vertical limits
82 top = parseInt(element.popup.element.style.top) + parseInt(element.popup.element.style.marginTop);
83 bottom = left + parseInt(element.popup.element.offsetHeight);
84 //Checking click position in relation to limits
85 if ((e._event.clientX < left || e._event.clientX > right) || (e._event.clientY < top || e._event.clientY > bottom)) {
86 //Hides popups since click is outside limits
87 return false;
88 } else {
89 //Keeps popup open since click inside area
90 return true;
91 }
92 } else {
93 //Hides popups since element not detected
94 return false;
95 }
96 }
63 }, 97 },
64 //////////////////////////////////////////////////////////////////// 98 ////////////////////////////////////////////////////////////////////
65 // 99 //
66 _popupChip: { 100 _popupBase: {
67 enumerable: false, 101 value: null
68 value: {}
69 }, 102 },
70 //////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////
71 // 104 //
72 _popupBase: { 105 _popupChipBase: {
73 enumerable: false,
74 value: null 106 value: null
75 }, 107 },
76 //////////////////////////////////////////////////////////////////// 108 ////////////////////////////////////////////////////////////////////
77 // 109 //
78 _popupChipBase: { 110 _popupGradientChipBase: {
79 enumerable: false,
80 value: null 111 value: null
81 }, 112 },
82 //////////////////////////////////////////////////////////////////// 113 ////////////////////////////////////////////////////////////////////
83 //Storing color manager 114 //Storing color manager
84 _colorManager: { 115 _colorManager: {
85 enumerable: false,
86 value: null 116 value: null
87 }, 117 },
88 //////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////
89 // 119 //
90 colorManager: { 120 colorManager: {
91 enumerable: true, 121 get: function() {return this._colorManager;},
92 get: function() { 122 set: function(value) {this._colorManager = value;}
93 return this._colorManager;
94 },
95 set: function(value) {
96 this._colorManager = value;
97 }
98 },
99
100
101
102 //TODO: Remove, figure out offset bug
103 _hackOffset: {
104 enumerable: true,
105 value: false
106 }, 123 },
107 124 ////////////////////////////////////////////////////////////////////
108 125 //
109 _colorPopupDrawing: { 126 _colorPopupDrawing: {
110 enumerable: true,
111 value: false 127 value: false
112 }, 128 },
129 ////////////////////////////////////////////////////////////////////
130 //
113 _colorChipPopupDrawing: { 131 _colorChipPopupDrawing: {
114 enumerable: true,
115 value: false 132 value: false
116 }, 133 },
117 134 ////////////////////////////////////////////////////////////////////
118 135 //
119 136 _colorGradientPopupDrawing: {
137 value: false
138 },
120 //////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////
121 //TODO: Remove and use montage's built in component 140 //TODO: Remove and use montage's built in component
122 showColorPopup: { 141 showColorPopup: {
123 enumerable: true,
124 value: function (x, y, side, align) { 142 value: function (x, y, side, align) {
143 //Check to see if popup is drawing, avoids errors
125 if (this._colorPopupDrawing) { 144 if (this._colorPopupDrawing) {
126 return; 145 return;
127 } 146 }
128 if (this._popupPanel.opened) { 147 //Check for toggling view
148 if (this._popupBase && this._popupBase.opened) {
129 //Toogles if called and opened 149 //Toogles if called and opened
130 this.hideColorPopup(); 150 this.hideColorPopup();
131 } else { 151 } else {
@@ -137,21 +157,14 @@ exports.ColorPopupManager = Montage.create(Component, {
137 this._hasinit = true; 157 this._hasinit = true;
138 } 158 }
139 //////////////////////////////////////////////////// 159 ////////////////////////////////////////////////////
140 //Creating popup from m-js component 160 //Creating popup
141 var popup = document.createElement('div'); 161 var popup = document.createElement('div');
142 document.body.appendChild(popup);