This repository has been archived by the owner on Apr 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotoshop-ui-manager.js
94 lines (72 loc) · 2.82 KB
/
photoshop-ui-manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
*
* Photoshop-UI-Manager
* Node.js module that listens to Adobe Photoshop working area brightness change event.
* Author: Antonio Gomez (https://github.com/antonio-gomez)
*
* @@link https://github.com/antonio-gomez/photoshop-ui-manager
* @version v1.0.0
* @license MIT
*
*/
;(function(window) {
'use strict';
var pkg = require('./package.json');
function PhotoshopUIManager() {}
// Public
PhotoshopUIManager.prototype.init = function(params) {
var self = this;
// Params validation
if(params === undefined || typeof params !== 'object') {
throw new Error('Verify your params object containing the target CSS Stylesheets.');
}
// CSInterface validation
if(window.CSInterface === undefined || typeof window.CSInterface !== 'function') {
throw new Error('Include Adobe CSInterface v5.x library to your Adobe Photoshop extension.');
} else {
this._csInterface = new window.CSInterface();
this._extensionId = this._csInterface.getExtensionID();
this.globalEventType = window.CSInterface.THEME_COLOR_CHANGED_EVENT;
this.stylesheets = params;
this.targetLinkElement;
this.appSkinInfo = JSON.parse(window.__adobe_cep__.getHostEnvironment()).appSkinInfo;
this.grayShade = '';
this._createStylesheetNode();
this._setCurrentUIGrayShade();
// Global event listener for THEME_COLOR_CHANGED_EVENT
this._csInterface.addEventListener(this.globalEventType, this._themeColorChangedHandler, { parentContext : self });
}
};
// Public
PhotoshopUIManager.prototype.verson = pkg.version;
// Private
PhotoshopUIManager.prototype._createStylesheetNode = function() {
var domElement = document.createElement('link'),
documentHead = document.getElementsByTagName('head').item(0)
domElement.rel = 'stylesheet';
domElement.id = 'target-stylesheet';
domElement.href = '';
this.targetLinkElement = documentHead.appendChild(domElement);
};
// Private
PhotoshopUIManager.prototype._themeColorChangedHandler = function(csEvent) {
this.parentContext.appSkinInfo = JSON.parse(window.__adobe_cep__.getHostEnvironment()).appSkinInfo;
this.parentContext._setCurrentUIGrayShade();
};
// Private
PhotoshopUIManager.prototype._setCurrentUIGrayShade = function() {
var self = this;
switch(this.appSkinInfo.panelBackgroundColor.color.red) {
case 52 : self.grayShade = 'darkGray'; break;
case 83 : self.grayShade = 'mediumGray'; break;
case 184 : self.grayShade = 'lightGray'; break;
case 214 : self.grayShade = 'original'; break;
}
this._assignCorrespondingStylesheet();
};
// Public
PhotoshopUIManager.prototype._assignCorrespondingStylesheet = function() {
this.targetLinkElement.href = this.stylesheets[this.grayShade];
};
module.exports = new PhotoshopUIManager;
})(window);