|
| 1 | +version = "2.0.5"; |
| 2 | +counter = 0; |
| 3 | +lego = ""; |
| 4 | +legoMode = false; |
| 5 | + |
| 6 | +function onLoaded() { |
| 7 | + getAUser(); |
| 8 | + $(".update").html("Version " + version); |
| 9 | + checkForUpdates(); |
| 10 | + var a = new CSInterface, |
| 11 | + c = a.hostEnvironment.appName; |
| 12 | + "FLPR" != c && loadJSX(); |
| 13 | + for (var b = ["PHXS"], d = 0; d < b.length; d++) { |
| 14 | + var e = b[d]; |
| 15 | + if (0 <= c.indexOf(e) && (e = document.getElementById("btn_" + e))) e.disabled = !1 |
| 16 | + } |
| 17 | + updateThemeWithAppSkinInfo(a.hostEnvironment.appSkinInfo); |
| 18 | + a.addEventListener(CSInterface.THEME_COLOR_CHANGED_EVENT, onAppThemeColorChanged); |
| 19 | +} |
| 20 | + |
| 21 | +function updateThemeWithAppSkinInfo(a) { |
| 22 | + var c = a.panelBackgroundColor.color; |
| 23 | + document.body.bgColor = toHex(c); |
| 24 | + var b = (new CSInterface).hostEnvironment.appName; |
| 25 | + "PHXS" == b && addRule("ppstyle", "button, select, input[type=button], input[type=submit]", "border-radius:3px;"); |
| 26 | + "PHXS" == b || ("PPRO" == b || "PRLD" == b) || (addRule("ppstyle", ".default", "font-size:" + a.baseFontSize + "px; color:" + reverseColor(c) + "; background-color:" + toHex(c, 20)), addRule("ppstyle", "button", "border-color: " + toHex(panelBgColor, -50))) |
| 27 | +} |
| 28 | + |
| 29 | +function addRule(a, c, b) { |
| 30 | + if (a = document.getElementById(a)) a = a.sheet, a.addRule ? a.addRule(c, b) : a.insertRule && a.insertRule(c + " { " + b + " }", a.cssRules.length) |
| 31 | +} |
| 32 | + |
| 33 | +function reverseColor(a, c) { |
| 34 | + return toHex({ |
| 35 | + red: Math.abs(255 - a.red), |
| 36 | + green: Math.abs(255 - a.green), |
| 37 | + blue: Math.abs(255 - a.blue) |
| 38 | + }, c) |
| 39 | +} |
| 40 | + |
| 41 | +function toHex(a, c) { |
| 42 | + function b(a, c) { |
| 43 | + var b = !isNaN(c) ? a + c : a; |
| 44 | + 0 > b ? b = 0 : 255 < b && (b = 255); |
| 45 | + b = b.toString(16); |
| 46 | + return 1 == b.length ? "0" + b : b |
| 47 | + } |
| 48 | + var d = ""; |
| 49 | + if (a) with(a) d = b(red, c) + b(green, c) + b(blue, c); |
| 50 | + return "#" + d |
| 51 | +} |
| 52 | + |
| 53 | +function onAppThemeColorChanged(a) { |
| 54 | + a = JSON.parse(window.__adobe_cep__.getHostEnvironment()).appSkinInfo; |
| 55 | + updateThemeWithAppSkinInfo(a) |
| 56 | +} |
| 57 | + |
| 58 | +function loadJSX() { |
| 59 | + var a = new CSInterface, |
| 60 | + c = a.getSystemPath(SystemPath.EXTENSION) + "/jsx/"; |
| 61 | + a.evalScript('$._ext.evalFiles("' + c + '")') |
| 62 | +} |
| 63 | + |
| 64 | +function evalScript(a, c) { |
| 65 | + (new CSInterface).evalScript(a, c) |
| 66 | +} |
| 67 | + |
| 68 | +function getAUser() { |
| 69 | + $("#new-user").addClass("active"); |
| 70 | + |
| 71 | + if ($("#men").hasClass("active")) { |
| 72 | + var gender = "&gender=male"; |
| 73 | + } else if ($("#both").hasClass("active")) { |
| 74 | + var gender = ""; |
| 75 | + } else { |
| 76 | + var gender = "&gender=female"; |
| 77 | + } |
| 78 | + $.ajax({ |
| 79 | + url: "http://api.randomuser.me/?" + lego + "extension=true" + gender, |
| 80 | + dataType: "json", |
| 81 | + success: function(a) { |
| 82 | + a.error || (a = a.results[0].user, $(".photo img").attr("src", a.picture.replace("portraits/", "portraits/med/")), $(".new-user").removeClass("active"), $("#name").html(a.name.first + " " + a.name.last), $(".control").removeAttr("disabled"), $(".counter").html(++counter + " user" + ((counter == 1) ? "" : "s") + " generated this session"), evalScript("$._random_image.save('" + a.picture + "')")) |
| 83 | + } |
| 84 | + }) |
| 85 | +} |
| 86 | + |
| 87 | +function addImage() { |
| 88 | + evalScript("$._random_image.open()") |
| 89 | +} |
| 90 | + |
| 91 | +function insertAndClip() { |
| 92 | + evalScript("$._image.clip()") |
| 93 | +}; |
| 94 | + |
| 95 | +function menButton() { |
| 96 | + if (!$("#men").hasClass("active")) { |
| 97 | + $("#men").addClass("active"); |
| 98 | + $("#women").removeClass("active"); |
| 99 | + $("#both").removeClass("active"); |
| 100 | + getAUser(); |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +function bothButton() { |
| 105 | + if (!$("#both").hasClass("active")) { |
| 106 | + $("#men").removeClass("active"); |
| 107 | + $("#both").addClass ("active"); |
| 108 | + $("#women").removeClass("active"); |
| 109 | + getAUser(); |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +function womenButton() { |
| 114 | + if (!$("#women").hasClass("active")) { |
| 115 | + $("#men").removeClass("active"); |
| 116 | + $("#both").removeClass("active"); |
| 117 | + $("#women").addClass("active"); |
| 118 | + getAUser(); |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +function thumbButton() { |
| 123 | + if (!$("#thumb").hasClass("active")) { |
| 124 | + $("#thumb").addClass("active"); |
| 125 | + $("#medium").removeClass("active"); |
| 126 | + $("#large").removeClass("active"); |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +function mediumButton() { |
| 131 | + if (!$("#medium").hasClass("active")) { |
| 132 | + $("#thumb").removeClass("active"); |
| 133 | + $("#medium").addClass("active"); |
| 134 | + $("#large").removeClass ("active"); |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +function largeButton() { |
| 139 | + if (!$("#large").hasClass("active")) { |
| 140 | + $("#thumb").removeClass("active"); |
| 141 | + $("#medium").removeClass("active"); |
| 142 | + $("#large").addClass("active"); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +function checkForUpdates() { |
| 147 | + $.ajax({ |
| 148 | + type: "POST", |
| 149 | + cache: false, |
| 150 | + data: {"version": version}, |
| 151 | + url: "https://randomuser.me/download/version.php", |
| 152 | + dataType: "json", |
| 153 | + success: function(a) { |
| 154 | + setTimeout(function () { |
| 155 | + if (version != a.version) { |
| 156 | + $(".update").html("<font color='#89c63c'>Version " + a.version + " is now available!</font>"); |
| 157 | + } |
| 158 | + }, 1000); |
| 159 | + } |
| 160 | + }) |
| 161 | +} |
| 162 | + |
| 163 | +function legoButton() { |
| 164 | + if (!legoMode) { |
| 165 | + lego = "lego&"; |
| 166 | + $("#legoText").html("Lego mode activated"); |
| 167 | + $("#men").attr("disabled", true); |
| 168 | + $("#both").attr("disabled", true); |
| 169 | + $("#women").attr("disabled", true); |
| 170 | + legoMode = true; |
| 171 | + } else { |
| 172 | + lego = ""; |
| 173 | + $("#legoText").html("Lego mode deactivated"); |
| 174 | + $("#men").removeAttr("disabled"); |
| 175 | + $("#both").removeAttr("disabled"); |
| 176 | + $("#women").removeAttr("disabled"); |
| 177 | + legoMode = false; |
| 178 | + } |
| 179 | + getAUser(); |
| 180 | +} |
0 commit comments