|
| 1 | + |
| 2 | +function onLoaded() { |
| 3 | + var csInterface = new CSInterface(); |
| 4 | + |
| 5 | + |
| 6 | + var appName = csInterface.hostEnvironment.appName; |
| 7 | + |
| 8 | + if(appName != "FLPR"){ |
| 9 | + loadJSX(); |
| 10 | + } |
| 11 | + |
| 12 | + var appNames = ["IDSN"]; |
| 13 | + for (var i = 0; i < appNames.length; i++) { |
| 14 | + var name = appNames[i]; |
| 15 | + if (appName.indexOf(name) >= 0) { |
| 16 | + var btn = document.getElementById("btn_" + name); |
| 17 | + if (btn) |
| 18 | + btn.disabled = false; |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + |
| 23 | + updateThemeWithAppSkinInfo(csInterface.hostEnvironment.appSkinInfo); |
| 24 | + // Update the color of the panel when the theme color of the product changed. |
| 25 | + csInterface.addEventListener(CSInterface.THEME_COLOR_CHANGED_EVENT, onAppThemeColorChanged); |
| 26 | + |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +/** |
| 32 | + * Update the theme with the AppSkinInfo retrieved from the host product. |
| 33 | + */ |
| 34 | +function updateThemeWithAppSkinInfo(appSkinInfo) { |
| 35 | + |
| 36 | + //Update the background color of the panel |
| 37 | + var panelBackgroundColor = appSkinInfo.panelBackgroundColor.color; |
| 38 | + document.body.bgColor = toHex(panelBackgroundColor); |
| 39 | + |
| 40 | + var styleId = "ppstyle"; |
| 41 | + |
| 42 | + var csInterface = new CSInterface(); |
| 43 | + var appName = csInterface.hostEnvironment.appName; |
| 44 | + |
| 45 | + if(appName == "PHXS"){ |
| 46 | + addRule(styleId, "button, select, input[type=button], input[type=submit]", "border-radius:3px;"); |
| 47 | + } |
| 48 | + if(appName == "PHXS" || appName == "PPRO" || appName == "PRLD") { |
| 49 | + //////////////////////////////////////////////////////////////////////////////////////////////// |
| 50 | + // NOTE: Below theme related code are only suitable for Photoshop. // |
| 51 | + // If you want to achieve same effect on other products please make your own changes here. // |
| 52 | + //////////////////////////////////////////////////////////////////////////////////////////////// |
| 53 | + |
| 54 | + |
| 55 | + var gradientBg = "background-image: -webkit-linear-gradient(top, " + toHex(panelBackgroundColor, 40) + " , " + toHex(panelBackgroundColor, 10) + ");"; |
| 56 | + var gradientDisabledBg = "background-image: -webkit-linear-gradient(top, " + toHex(panelBackgroundColor, 15) + " , " + toHex(panelBackgroundColor, 5) + ");"; |
| 57 | + var boxShadow = "-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);"; |
| 58 | + var boxActiveShadow = "-webkit-box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.6);"; |
| 59 | + |
| 60 | + var isPanelThemeLight = panelBackgroundColor.red > 127; |
| 61 | + var fontColor, disabledFontColor; |
| 62 | + var borderColor; |
| 63 | + var inputBackgroundColor; |
| 64 | + var gradientHighlightBg; |
| 65 | + if(isPanelThemeLight) { |
| 66 | + fontColor = "#000000;"; |
| 67 | + disabledFontColor = "color:" + toHex(panelBackgroundColor, -70) + ";"; |
| 68 | + borderColor = "border-color: " + toHex(panelBackgroundColor, -90) + ";"; |
| 69 | + inputBackgroundColor = toHex(panelBackgroundColor, 54) + ";"; |
| 70 | + gradientHighlightBg = "background-image: -webkit-linear-gradient(top, " + toHex(panelBackgroundColor, -40) + " , " + toHex(panelBackgroundColor,-50) + ");"; |
| 71 | + } else { |
| 72 | + fontColor = "#ffffff;"; |
| 73 | + disabledFontColor = "color:" + toHex(panelBackgroundColor, 100) + ";"; |
| 74 | + borderColor = "border-color: " + toHex(panelBackgroundColor, -45) + ";"; |
| 75 | + inputBackgroundColor = toHex(panelBackgroundColor, -20) + ";"; |
| 76 | + gradientHighlightBg = "background-image: -webkit-linear-gradient(top, " + toHex(panelBackgroundColor, -20) + " , " + toHex(panelBackgroundColor, -30) + ");"; |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | + //Update the default text style with pp values |
| 81 | + |
| 82 | + addRule(styleId, ".default", "font-size:" + appSkinInfo.baseFontSize + "px" + "; color:" + fontColor + "; background-color:" + toHex(panelBackgroundColor) + ";"); |
| 83 | + addRule(styleId, "button, select, input[type=text], input[type=button], input[type=submit]", borderColor); |
| 84 | + addRule(styleId, "button, select, input[type=button], input[type=submit]", gradientBg); |
| 85 | + addRule(styleId, "button, select, input[type=button], input[type=submit]", boxShadow); |
| 86 | + addRule(styleId, "button:enabled:active, input[type=button]:enabled:active, input[type=submit]:enabled:active", gradientHighlightBg); |
| 87 | + addRule(styleId, "button:enabled:active, input[type=button]:enabled:active, input[type=submit]:enabled:active", boxActiveShadow); |
| 88 | + addRule(styleId, "[disabled]", gradientDisabledBg); |
| 89 | + addRule(styleId, "[disabled]", disabledFontColor); |
| 90 | + addRule(styleId, "input[type=text]", "padding:1px 3px;"); |
| 91 | + addRule(styleId, "input[type=text]", "background-color: " + inputBackgroundColor) + ";"; |
| 92 | + addRule(styleId, "input[type=text]:focus", "background-color: #ffffff;"); |
| 93 | + addRule(styleId, "input[type=text]:focus", "color: #000000;"); |
| 94 | + |
| 95 | + } else { |
| 96 | + // For AI, ID and FL use old implementation |
| 97 | + addRule(styleId, ".default", "font-size:" + appSkinInfo.baseFontSize + "px" + "; color:" + reverseColor(panelBackgroundColor) + "; background-color:" + toHex(panelBackgroundColor, 20)); |
| 98 | + addRule(styleId, "button", "border-color: " + toHex(panelBgColor, -50)); |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +function addRule(stylesheetId, selector, rule) { |
| 103 | + var stylesheet = document.getElementById(stylesheetId); |
| 104 | + |
| 105 | + if (stylesheet) { |
| 106 | + stylesheet = stylesheet.sheet; |
| 107 | + if( stylesheet.addRule ){ |
| 108 | + stylesheet.addRule(selector, rule); |
| 109 | + } else if( stylesheet.insertRule ){ |
| 110 | + stylesheet.insertRule(selector + ' { ' + rule + ' }', stylesheet.cssRules.length); |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | + |
| 116 | +function reverseColor(color, delta) { |
| 117 | + return toHex({red:Math.abs(255-color.red), green:Math.abs(255-color.green), blue:Math.abs(255-color.blue)}, delta); |
| 118 | +} |
| 119 | + |
| 120 | +/** |
| 121 | + * Convert the Color object to string in hexadecimal format; |
| 122 | + */ |
| 123 | +function toHex(color, delta) { |
| 124 | + function computeValue(value, delta) { |
| 125 | + var computedValue = !isNaN(delta) ? value + delta : value; |
| 126 | + if (computedValue < 0) { |
| 127 | + computedValue = 0; |
| 128 | + } else if (computedValue > 255) { |
| 129 | + computedValue = 255; |
| 130 | + } |
| 131 | + |
| 132 | + computedValue = computedValue.toString(16); |
| 133 | + return computedValue.length == 1 ? "0" + computedValue : computedValue; |
| 134 | + } |
| 135 | + |
| 136 | + var hex = ""; |
| 137 | + if (color) { |
| 138 | + with (color) { |
| 139 | + hex = computeValue(red, delta) + computeValue(green, delta) + computeValue(blue, delta); |
| 140 | + }; |
| 141 | + } |
| 142 | + return "#" + hex; |
| 143 | +} |
| 144 | + |
| 145 | +function onAppThemeColorChanged(event) { |
| 146 | + // Should get a latest HostEnvironment object from application. |
| 147 | + var skinInfo = JSON.parse(window.__adobe_cep__.getHostEnvironment()).appSkinInfo; |
| 148 | + // Gets the style information such as color info from the skinInfo, |
| 149 | + // and redraw all UI controls of your extension according to the style info. |
| 150 | + updateThemeWithAppSkinInfo(skinInfo); |
| 151 | +} |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | +/** |
| 157 | + * Load JSX file into the scripting context of the product. All the jsx files in |
| 158 | + * folder [ExtensionRoot]/jsx will be loaded. |
| 159 | + */ |
| 160 | +function loadJSX() { |
| 161 | + var csInterface = new CSInterface(); |
| 162 | + var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/"; |
| 163 | + csInterface.evalScript('$._ext.evalFiles("' + extensionRoot + '")'); |
| 164 | +} |
| 165 | + |
| 166 | +function evalScript(script, callback) { |
| 167 | + new CSInterface().evalScript(script, callback); |
| 168 | +} |
| 169 | + |
| 170 | +function onClickButton(ppid) { |
| 171 | + if(ppid == "FLPR"){ |
| 172 | + var jsfl = 'fl.createDocument(); fl.getDocumentDOM().addNewText({left:100, top:100, right:300, bottom:300} , "Hello Flash!" ); '; |
| 173 | + evalScript(jsfl); |
| 174 | + } else { |
| 175 | + var extScript = "$._ext_" + ppid + ".run()"; |
| 176 | + evalScript(extScript); |
| 177 | + } |
| 178 | +} |
0 commit comments