personalization.html 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="mobile-web-app-capable" content="yes">
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  6. <meta charset="UTF-8">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <script src="../../script/jquery.min.js"></script>
  9. <script src="../../script/semantic/semantic.min.js"></script>
  10. <script src="../../script/ao_module.js"></script>
  11. <script type="text/javascript" src="../../script/applocale.js"></script>
  12. <style>
  13. .hidden{
  14. display:none;
  15. }
  16. .backgroundpreview{
  17. border: 1px solid #898989;
  18. }
  19. .colorpallete{
  20. border: 1px solid transparent;
  21. cursor: pointer;
  22. }
  23. .colorpallete:hover{
  24. border: 1px solid white;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div class="ui tabular menu" style="position:fixed; top:0px; left:0px; width: 100%;">
  30. <div class="active item" data-tab="wallpaper" locale="menu/wallpaper">Wallpaper</div>
  31. <div class="item" data-tab="sound" locale="menu/sound">Sound</div>
  32. <div class="item" data-tab="theme" locale="menu/theme">Theme</div>
  33. <div class="item" data-tab="advance" locale="menu/advance">Advance</div>
  34. </div>
  35. <div style="position:fixed; top: 42px; left:0px; width: 100%; height: calc(100% - 42px); overflow-y:auto;">
  36. <div class="ui active tab" data-tab="wallpaper">
  37. <!-- Wallpaper Functions -->
  38. <br>
  39. <div class="ui container">
  40. <h3 class="ui header">
  41. <i class="image outline icon"></i>
  42. <div class="content">
  43. <span locale="wallpaper/title">Wallpapers</span>
  44. <div locale="wallpaper/desc" class="sub header">Manage your desktop preferences</div>
  45. </div>
  46. </h3>
  47. <div class="ui divider"></div>
  48. <div class="ui grid">
  49. <div class="ten wide column">
  50. <img id="mainBackground" class="ui fluid image backgroundpreview" src="">
  51. </div>
  52. <div class="six wide column">
  53. </div>
  54. </div>
  55. <div class="ui divider"></div>
  56. <div id="backgroundPreviewList" class="ui grid">
  57. <div class="four wide column">
  58. <img class="ui fluid image backgroundpreview" src="">
  59. </div>
  60. <div class="four wide column">
  61. <img class="ui fluid image backgroundpreview" src="">
  62. </div>
  63. <div class="four wide column">
  64. <img class="ui fluid image backgroundpreview" src="">
  65. </div>
  66. <div class="four wide column">
  67. <img class="ui fluid image backgroundpreview" src="">
  68. </div>
  69. </div>
  70. <div class="ui divider"></div>
  71. <h4 class="ui header">
  72. <span locale="wallpaper/title">Background Wallpaper</span>
  73. <div locale="wallpaper/desc" class="sub header">Set your desktop background wallpaper theme.</div>
  74. </h4>
  75. <select id="wallpaperlist" class="ui fluid dropdown allowSelectDefaultThemes" onchange="handleBackgroundSelectionChange(this.value);">
  76. <option value="" locale="wallpaper/option/title">Wallpaper Packs</option>
  77. </select>
  78. <small locale="wallpaper/option/desc">This option will be disabled by default if you have set your "User Defined Wallpaper" in Advance tab.</small>
  79. <br> <br>
  80. <button class="ui small green right floated button allowSelectDefaultThemes" onclick="applyWallpaper();" locale="wallpaper/option/apply"><i class="checkmark icon"></i> Apply Wallpaper</button>
  81. <br><br><br>
  82. <div class="ui green segment" style="display:none" id="wallpaperChangeConfirm">
  83. <h4 class="ui header">
  84. <i class="checkmark green icon"></i>
  85. <div class="content">
  86. <span locale="wallpaper/option/updated">Wallpaper Updated</span>
  87. <div class="sub header" locale="wallpaper/option/updateddesc">You should be seeing your desktop wallpaper change in a moment.</div>
  88. </div>
  89. </h4>
  90. </div>
  91. <!-- Wallpaper change interval-->
  92. <div class="ui divider"></div>
  93. <h4 class="ui header">
  94. <span locale="wallpaper/option/interval">Wallpaper Interval</span>
  95. <div class="sub header" locale="wallpaper/option/intervaldesc">Set the interval between the wallpaper image cycles.</div>
  96. </h4>
  97. <select id="changeInterval" class="ui fluid dropdown" onchange="handleIntervalChange(this.value);">
  98. <option value="10" locale="wallpaper/interval/10s">10 seconds</option>
  99. <option value="30" locale="wallpaper/interval/30s">30 seconds</option>
  100. <option value="60" locale="wallpaper/interval/60s">60 seconds</option>
  101. <option value="180" locale="wallpaper/interval/3min">3 minutes</option>
  102. <option value="300" locale="wallpaper/interval/5min">5 minutes</option>
  103. <option value="600" locale="wallpaper/interval/10min">10 minutes</option>
  104. <option value="1800" locale="wallpaper/interval/30min">30 minutes</option>
  105. <option value="3600" locale="wallpaper/interval/1h">1 hour</option>
  106. </select>
  107. <div class="ui green segment" style="display:none" id="interfaceChangeConfirm">
  108. <h4 class="ui header">
  109. <i class="checkmark green icon"></i>
  110. <div class="content">
  111. <span locale="wallpaper/interval/succ">Wallpaper Interval Updated</span>
  112. <div class="sub header" locale="wallpaper/interval/succdesc">This setting will only apply to this browser</div>
  113. </div>
  114. </h4>
  115. </div>
  116. </div>
  117. <br><br><br>
  118. </div>
  119. <div class="ui tab" data-tab="sound">
  120. <br>
  121. <div class="ui container">
  122. <h3 class="ui header">
  123. <i class="music icon"></i>
  124. <div class="content">
  125. <span locale="sound/title">System Sound</span>
  126. <div class="sub header" locale="sound/desc">Customize system sound effect</div>
  127. </div>
  128. </h3>
  129. <div class="ui divider"></div>
  130. <h4 class="ui header">
  131. <span locale="sound/custom/title">Custom Startup Sound</span>
  132. <div class="sub header" locale="sound/custom/desc">User defined startup sound to play when login to the web desktop</div>
  133. </h4>
  134. <h3 id="userSelectedStartupSound" locale="sound/custom/disable">Disabled</h3>
  135. <button class="ui small right floated button" onclick="clearStartupAudioSelection()"><i class="remove icon"></i> <span locale="sound/custom/clear">Clear Selection</span></button>
  136. <button class="ui small black right floated button" onclick="selectStartupAudio();"><i class="folder open icon"></i> <span locale="sound/custom/select">Select File</span></button>
  137. <br><br>
  138. <div class="ui divider"></div>
  139. </div>
  140. </div>
  141. <div class="ui tab" data-tab="theme">
  142. <!-- Theme Color Related !-->
  143. <br>
  144. <div class="ui container">
  145. <h3 class="ui header">
  146. <i class="paint brush icon"></i>
  147. <div class="content">
  148. <span locale="themecolor/title">Theme Color</span>
  149. <div class="sub header" locale="themecolor/desc">Change the system theme color settings</div>
  150. </div>
  151. </h3>
  152. <div class="ui divider"></div>
  153. <div class="ui container">
  154. <div id="colorgrid">
  155. Loading...
  156. </div>
  157. </div>
  158. <br>
  159. <div class="ui divider"></div>
  160. <button class="ui small basic black button" onclick="restoreDefaultThemeColor();" locale="themecolor/color/Default">Restore Default</button>
  161. <br><br><br>
  162. </div>
  163. </div>
  164. <div class="ui tab" data-tab="advance">
  165. <!-- Advance User Customization !-->
  166. <br>
  167. <div class="ui container">
  168. <h3 class="ui header">
  169. <i class="setting icon"></i>
  170. <div class="content">
  171. <span locale="advance/title">Advance Customization</span>
  172. <div class="sub header" locale="advance/desc">Manage your desktop preferences</div>
  173. </div>
  174. </h3>
  175. <div class="ui divider"></div>
  176. <h4 class="ui header">
  177. <i class="image icon" style="display:inline-block;"></i> <span locale="advance/wallpaper/title">User Defined Wallpaper</span>
  178. <div class="sub header" locale="advance/wallpaper/desc">Advanced user customization function for desktop interface</div>
  179. </h4>
  180. <h3 id="userSelectedFolderPath" locale="advance/wallpaper/disabled">Disabled</h3>
  181. <p locale="advance/wallpaper/reminder">If you have set a folder for loading desktop wallpapers, the image files from that folder will be used instead of the system build in wallpapers.</p>
  182. <button class="ui small right floated button" onclick="clearUserSelectedFolder();"><i class="remove icon"></i><span locale="advance/wallpaper/clear">Clear Selection</span></button>
  183. <button class="ui small black right floated button" onclick="selectUserFolder();"><i class="folder open icon"></i> <span locale="advance/wallpaper/select">Select Folder</span></button>
  184. <br><br>
  185. <div class="ui divider"></div>
  186. <h4 class="ui header">
  187. <i class="external square alternate icon" style="display:inline-block;" ></i> <span locale="advance/mobile/shorcut/title">Mobile Desktop Shortcuts</span>
  188. <div class="sub header" locale="advance/mobile/shorcut/subtitle">Change the default four shortcuts for mobile desktop interface</div>
  189. </h4>
  190. <p locale="advance/mobile/shorcut/instruction">Please pick your shortcut from left to right</p>
  191. <div>
  192. <div class="ui fluid search selection moduledropbox dropdown">
  193. <input type="hidden" id="shortcut1">
  194. <i class="dropdown icon"></i>
  195. <div class="default text" locale="advance/mobile/shorcut/shortcut/1">Shortcut 1</div>
  196. <div class="webapplist menu">
  197. </div>
  198. </div>
  199. <br>
  200. <div class="ui fluid search selection moduledropbox dropdown">
  201. <input type="hidden" id="shortcut2">
  202. <i class="dropdown icon"></i>
  203. <div class="default text" locale="advance/mobile/shorcut/shortcut/2">Shortcut 2</div>
  204. <div class="webapplist menu">
  205. </div>
  206. </div>
  207. <br>
  208. <div class="ui fluid search selection moduledropbox dropdown">
  209. <input type="hidden" id="shortcut3">
  210. <i class="dropdown icon"></i>
  211. <div class="default text" locale="advance/mobile/shorcut/shortcut/3">Shortcut 3</div>
  212. <div class="webapplist menu">
  213. </div>
  214. </div>
  215. <br>
  216. <div class="ui fluid search selection moduledropbox dropdown">
  217. <input type="hidden" id="shortcut4">
  218. <i class="dropdown icon"></i>
  219. <div class="default text" locale="advance/mobile/shorcut/shortcut/4">Shortcut 4</div>
  220. <div class="webapplist menu">
  221. </div>
  222. </div>
  223. </div>
  224. <br>
  225. <button class="ui small green right floated button" onclick="saveShortcuts();" locale="advance/mobile/shorcut/save"><i class="checkmark icon"></i> Save Shortcuts</button>
  226. <br><br>
  227. <div class="ui green segment" style="display:none" id="shortcutChangeSaved">
  228. <h4 class="ui header">
  229. <i class="checkmark green icon"></i>
  230. <div class="content">
  231. <span locale="advance/mobile/shorcut/updated">Shorcuts Updated</span>
  232. <div class="sub header" locale="advance/mobile/shorcut/updateddesc">Open the mobile interface via your phone to view the changes</div>
  233. </div>
  234. </h4>
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. <br><br>
  240. <script>
  241. var desktopThemeList = [];
  242. var isStartingUp = true;
  243. var cancelColorRestore = false; //If the user clicked on the target color pallete, do not restore the desktop to its original color before selection
  244. $(".dropdown").dropdown();
  245. $('.tabular.menu .item').tab();
  246. try{
  247. applocale.init("../locale/personalization.json", function(){
  248. applocale.translate();
  249. init();
  250. });
  251. }catch(ex){
  252. //fail to load localization file. Use default
  253. init()
  254. }
  255. function init(){
  256. //Startup process
  257. initDefaultBackgroundChangeValue();
  258. initUserDefinedWallpaperFolder(function(themeName){
  259. initCurrentBackgroundPreview(themeName);
  260. });
  261. generateColorGrids();
  262. getStartupAudio();
  263. initModuleList();
  264. }
  265. //Return the data stored in the theme settings
  266. //Will return either theme pack name or path for user defined folder
  267. function initUserDefinedWallpaperFolder(callback = undefined){
  268. $.get("../../system/desktop/theme?get=true", function(data) {
  269. if (data.includes(":/")){
  270. //This is a path
  271. $("#userSelectedFolderPath").text(data);
  272. $(".allowSelectDefaultThemes").addClass("disabled");
  273. }else{
  274. $("#userSelectedFolderPath").text(applocale.getString("advance/wallpaper/disabled", "Disabled"));
  275. }
  276. if (callback != undefined){
  277. callback(data);
  278. }
  279. });
  280. }
  281. function initModuleList(){
  282. $.get("../../system/modules/list", function(data){
  283. $(".webapplist").html('');
  284. data.forEach(app => {
  285. if (app.Group != "Interface Module" && app.Group != "IME" && app.StartDir != ""){
  286. $(".webapplist").append(`<div class="item" data-value="${app.Name}">${app.Name}</div>`);
  287. }
  288. });
  289. $(".moduledropbox").dropdown();
  290. //Get selected preferences
  291. readPreference("ao/mobile/shorcut/1", function(data){
  292. if (data != ""){
  293. $("#shortcut1").val(data);
  294. $("#shortcut1").parent().dropdown("set selected", data);
  295. }
  296. });
  297. readPreference("ao/mobile/shorcut/2", function(data){
  298. if (data != ""){
  299. $("#shortcut2").val(data);
  300. $("#shortcut2").parent().dropdown("set selected", data);
  301. }
  302. });
  303. readPreference("ao/mobile/shorcut/3", function(data){
  304. if (data != ""){
  305. $("#shortcut3").val(data);
  306. $("#shortcut3").parent().dropdown("set selected", data);
  307. }
  308. });
  309. readPreference("ao/mobile/shorcut/4", function(data){
  310. if (data != ""){
  311. $("#shortcut4").val(data);
  312. $("#shortcut4").parent().dropdown("set selected", data);
  313. }
  314. });
  315. })
  316. }
  317. function saveShortcuts(){
  318. var sc1 = $("#shortcut1").val();
  319. var sc2 = $("#shortcut2").val();
  320. var sc3 = $("#shortcut3").val();
  321. var sc4 = $("#shortcut4").val();
  322. if (sc1 != ""){
  323. writePreference("ao/mobile/shorcut/1", sc1);
  324. }
  325. if (sc2 != ""){
  326. writePreference("ao/mobile/shorcut/2", sc2);
  327. }
  328. if (sc3 != ""){
  329. writePreference("ao/mobile/shorcut/3", sc3);
  330. }
  331. if (sc4 != ""){
  332. writePreference("ao/mobile/shorcut/4", sc4);
  333. }
  334. $("#shortcutChangeSaved").stop().finish().slideDown("fast").delay(3000).slideUp("fast", function(){
  335. if (parent != undefined && parent.initShortcuts != undefined){
  336. parent.initShortcuts();
  337. }
  338. });
  339. }
  340. function initDefaultBackgroundChangeValue(){
  341. if (localStorage.getItem("ao/desktop/backgroundInterval") == null){
  342. //No background interval set.
  343. $("#changeInterval").dropdown("set selected", "30");
  344. }else{
  345. //There is already a setting for background interval change. Use that instead
  346. var changeInterval = localStorage.getItem("ao/desktop/backgroundInterval");
  347. $("#changeInterval").dropdown("set selected", changeInterval);
  348. }
  349. }
  350. //Startup sound
  351. function selectStartupAudio(){
  352. ao_module_openFileSelector(setStartupAudio, undefined,"file",{
  353. filter: ["mp3", "aac", "ogg", "wav"]
  354. });
  355. }
  356. function setStartupAudio(filedata){
  357. var filename = filedata[0].filename;
  358. var filepath = filedata[0].filepath;
  359. $("#userSelectedStartupSound").text(filepath);
  360. $.ajax({
  361. url: "../../system/desktop/preference",
  362. method: "POST",
  363. data: {preference: "startup-audio", value: filepath},
  364. success: function(data){
  365. console.log(data);
  366. }
  367. });
  368. }
  369. function getStartupAudio(callback=undefined){
  370. $.ajax({
  371. url: "../../system/desktop/preference",
  372. method: "POST",
  373. data: {preference: "startup-audio"},
  374. success: function(data){
  375. if (data != undefined && data != ""){
  376. $("#userSelectedStartupSound").text(data);
  377. }
  378. if (callback != undefined){
  379. callback(data);
  380. }else{
  381. console.log(data);
  382. }
  383. }
  384. });
  385. }
  386. function clearStartupAudioSelection(){
  387. $.ajax({
  388. url: "../../system/desktop/preference",
  389. method: "POST",
  390. data: {preference: "startup-audio", remove: "true"},
  391. success: function(data){
  392. $("#userSelectedStartupSound").text(applocale.getString("sound/disabled", "Disabled"));
  393. }
  394. });
  395. }
  396. //Change the interval to the given
  397. function handleIntervalChange(newInterval){
  398. //Show change finsihed
  399. if (isStartingUp){
  400. //Ignore startup change
  401. return;
  402. }
  403. //Save interval to localStorage
  404. localStorage.setItem("ao/desktop/backgroundInterval", newInterval)
  405. $("#interfaceChangeConfirm").slideDown('fast').delay(3000).slideUp('fast');
  406. //Restart desktop background changer interval
  407. if (ao_module_virtualDesktop){
  408. console.log("Restarting desktop background changer interval")
  409. if (parent.backgroundIntervalCounter){
  410. parent.clearInterval(parent.backgroundIntervalCounter);
  411. }
  412. parent.initBackgroundSwitchingAnimation();
  413. }
  414. }
  415. function selectUserFolder(){
  416. ao_module_openFileSelector(folderSelected, undefined,"folder",false);
  417. }
  418. function folderSelected(filedata){
  419. for (var i=0; i < filedata.length; i++){
  420. var filename = filedata[i].filename;
  421. var filepath = filedata[i].filepath;
  422. //Save the overwrite folder path
  423. $("#userSelectedFolderPath").text(filepath);
  424. $.get("../../system/desktop/theme?set=" + filepath, function(data) {
  425. //Reload desktop background pack
  426. if (ao_module_virtualDesktop){
  427. parent.changeDesktopTheme(filepath);
  428. }
  429. //Disable change to system build in themes
  430. $(".allowSelectDefaultThemes").addClass("disabled");
  431. //Load the preview
  432. initCurrentBackgroundPreview();
  433. });
  434. }
  435. }
  436. function clearUserSelectedFolder(){
  437. //Clear user selected folder
  438. $.get("../../system/desktop/theme?set=default", function(data) {
  439. //Reload desktop background pack
  440. if (ao_module_virtualDesktop){
  441. parent.changeDesktopTheme("default");
  442. }
  443. //Re-enable the default theme seelct
  444. $(".allowSelectDefaultThemes").removeClass("disabled");
  445. $("#userSelectedFolderPath").text(applocale.getString("advance/wallpaper/select", "Disabled"));
  446. initUserDefinedWallpaperFolder();
  447. initCurrentBackgroundPreview();
  448. });
  449. }
  450. function initCurrentBackgroundPreview(){
  451. //Get the list of theme in the system
  452. $.get("../../system/desktop/theme", function(data) {
  453. desktopThemeList = data;
  454. //Generate the wallpaper list
  455. $("#wallpaperlist").html("");
  456. var deftaultData = "";
  457. desktopThemeList.forEach(themepack => {
  458. var encodedData = encodeURIComponent(JSON.stringify(themepack));
  459. var themeName = themepack.Theme.charAt(0).toUpperCase() + themepack.Theme.slice(1);
  460. $("#wallpaperlist").append(`<option value="${encodedData}">${themeName}</option>`);
  461. if (themepack.Theme == "default"){
  462. deftaultData = encodedData;
  463. }
  464. });
  465. //Get the one the user is currently using
  466. $.get("../../system/desktop/theme?get=true", function(data) {
  467. //Get the user theme settings
  468. $(".backgroundpreview").attr('src','../../img/desktop/bg/nobg.jpg');
  469. //Check if the theme is custom path
  470. if (data.includes(":/")){
  471. //Is path. Load path preview
  472. $.get("../../system/desktop/theme?load=" + data, function(imagelist){
  473. //Load background preview
  474. loadBackgroundPreviewForCustomFolder(imagelist);
  475. //End of startup process
  476. isStartingUp = false;
  477. });
  478. }else{
  479. //Check if the theme exists
  480. var themeExists = false;
  481. var targetThemeObject;
  482. desktopThemeList.forEach(theme => {
  483. if (theme.Theme == data){
  484. //Theme exists
  485. themeExists = true;
  486. targetThemeObject = theme;
  487. }
  488. });
  489. if (themeExists == false){
  490. //This theme not exists. Do not load preview
  491. $("#wallpaperlist").dropdown("set selected","Default");
  492. }else{
  493. loadBackgroundPreview(targetThemeObject);
  494. var themeName = data.charAt(0).toUpperCase() + data.slice(1)
  495. $("#wallpaperlist").dropdown("set selected",themeName);
  496. }
  497. //End of startup process
  498. isStartingUp = false;
  499. }
  500. });
  501. });
  502. }
  503. function loadBackgroundPreviewForCustomFolder(imageList){
  504. $("#backgroundPreviewList").html("");
  505. $("#mainBackground").attr("src","../../media/?file=" + imageList[0]);
  506. for (var i = 1; i < imageList.length; i++){
  507. $("#backgroundPreviewList").append(`<div class="four wide column">
  508. <img class="ui fluid image backgroundpreview" src="${"../../media/?file=" + imageList[i]}">
  509. </div>`);
  510. }
  511. }
  512. function loadBackgroundPreview(targetThemeObject){
  513. $("#backgroundPreviewList").html("");
  514. var imageList = targetThemeObject.Bglist;
  515. $("#mainBackground").attr("src","../../img/desktop/bg/" + targetThemeObject.Theme + "/" + imageList[0]);
  516. for (var i = 1; i < imageList.length; i++){
  517. $("#backgroundPreviewList").append(`<div class="four wide column">
  518. <img class="ui fluid image backgroundpreview" src="${"../../img/desktop/bg/" + targetThemeObject.Theme + "/" + imageList[i]}">
  519. </div>`);
  520. }
  521. }
  522. function handleBackgroundSelectionChange(value){
  523. var targetThemeObject = JSON.parse(decodeURIComponent(value));
  524. loadBackgroundPreview(targetThemeObject);
  525. }
  526. function generateColorGrids(){
  527. $("#colorgrid").html("");
  528. $.getJSON("./colors.json", function(data){
  529. for (let key in data) {
  530. let colorcodes = data[key];
  531. let thisSection = '';
  532. let thisColorKey = key.charAt(0).toUpperCase() + key.slice(1);
  533. thisSection += (`<div class="ui grid">`);
  534. thisSection += (`<div class="five wide column">
  535. ${applocale.getString("themecolor/color/" + thisColorKey, thisColorKey)}
  536. </div>`);
  537. for (let colorIndex in colorcodes) {
  538. if (colorIndex < 300){
  539. //Skip all the light colors
  540. continue;
  541. }
  542. let colorHexCoxde = colorcodes[colorIndex];
  543. thisSection += (`<div class="one wide column colorpallete" hex="${colorHexCoxde}" material="${colorIndex}" style="background-color: ${colorHexCoxde}; text-align: center;"><br></div>`);
  544. }
  545. thisSection += "</div>"
  546. $("#colorgrid").append(thisSection);
  547. }
  548. //Bind events to change the color for preview
  549. let previousColorCode = {};
  550. $(".colorpallete").on({
  551. mouseover: function() {
  552. event.preventDefault();
  553. $(this).animate({opacity: 0.25}, 100);
  554. //Save the current color
  555. var thisColorCode = $(this).attr("hex");
  556. var parentDocument = parent.window.document;
  557. previousColorCode["floatWindow"] = $(parentDocument).find(".floatWindow .controls").css("background-color");
  558. previousColorCode["statusbar"] = $(parentDocument).find("#statusbar").css("background-color");
  559. previousColorCode["navimenu"] = $(parentDocument).find("#navimenu").css("background-color");
  560. //Set the preview color
  561. if (ao_module_virtualDesktop){
  562. $(parentDocument).find(".floatWindow .controls").css("background-color",hexToRgbA(thisColorCode, 0.25));
  563. $(parentDocument).find("#statusbar").css("background-color",thisColorCode );
  564. $(parentDocument).find("#navimenu").css("background-color",hexToRgbA(thisColorCode, 0.5));
  565. }
  566. },
  567. mouseout: function() {
  568. event.preventDefault();
  569. $(this).animate({opacity: 1}, 100);
  570. $(".themeColorSolid").css("background-color", "");
  571. //Restore the original color
  572. var parentDocument = parent.window.document;
  573. if (ao_module_virtualDesktop && !cancelColorRestore){
  574. $(parentDocument).find(".floatWindow .controls").css("background-color",previousColorCode["floatWindow"]);
  575. $(parentDocument).find("#statusbar").css("background-color",previousColorCode["statusbar"]);
  576. $(parentDocument).find("#navimenu").css("background-color",previousColorCode["navimenu"]);
  577. }else if (cancelColorRestore){
  578. cancelColorRestore = false;
  579. }
  580. }
  581. });
  582. //Setting the current theme
  583. $(".colorpallete").on("click", function(){
  584. var colorCode = $(this).attr("hex");
  585. writePreference("themecolor",colorCode, function(data){
  586. if (data.error != undefined){
  587. alert(data.error);
  588. }
  589. //Tick the current using color
  590. tickTheCurrentSelectedThemeColor();
  591. //Update the desktop theme color
  592. if (ao_module_virtualDesktop){
  593. cancelColorRestore=true;
  594. parent.setThemeColor(colorCode);
  595. }
  596. });
  597. });
  598. tickTheCurrentSelectedThemeColor();
  599. });
  600. }
  601. function restoreDefaultThemeColor(){
  602. $.ajax({
  603. url: "../../system/file_system/preference",
  604. data: {key: "themecolor", remove: true},
  605. success: function(data){
  606. if (data.error !== undefined){
  607. console.log(data.error);
  608. }else{
  609. if (ao_module_virtualDesktop){
  610. //Just emulate the restored effect first,
  611. //The theme color will restore after refresh
  612. parent.setThemeColor("#262626");
  613. }
  614. }
  615. }
  616. });
  617. }
  618. function tickTheCurrentSelectedThemeColor(){
  619. //Tick the one that is currently using
  620. readPreference("themecolor", function(data){
  621. if (data.error == undefined){
  622. //See if there is a colorpallete match the hex string
  623. $(".colorpallete").each(function(){
  624. if ($(this).attr("hex") == data){
  625. //This is the pallete to tick
  626. $(this).html(`<i style="color:white; margin-left: -4px;" class="checkmark icon"></i>`);
  627. }else{
  628. $(this).html(`<br>`);
  629. }
  630. })
  631. }
  632. })
  633. }
  634. function readPreference(key, callback=undefined){
  635. $.ajax({
  636. url: "../../system/desktop/preference",
  637. data: {preference: key},
  638. method: "POST",
  639. success: function(data){
  640. if (callback != undefined){
  641. callback(data);
  642. }
  643. }
  644. });
  645. }
  646. function writePreference(key, value, callback=undefined){
  647. $.ajax({
  648. url: "../../system/desktop/preference",
  649. data: {preference: key, value: value},
  650. method: "POST",
  651. success: function(data){
  652. if (callback != undefined){
  653. callback(data);
  654. }
  655. }
  656. })
  657. }
  658. function hexToRgbA(hex, transparent=1){
  659. var c;
  660. if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
  661. c= hex.substring(1).split('');
  662. if(c.length== 3){
  663. c= [c[0], c[0], c[1], c[1], c[2], c[2]];
  664. }
  665. c= '0x'+c.join('');
  666. return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',' + transparent + ')';
  667. }
  668. throw new Error('Bad Hex');
  669. }
  670. function applyWallpaper(){
  671. var targetWallpaper =JSON.parse(decodeURIComponent($("#wallpaperlist").val()));
  672. $.get("../../system/desktop/theme?set=" + targetWallpaper.Theme, function(data) {
  673. if (ao_module_virtualDesktop == true){
  674. parent.changeDesktopTheme(targetWallpaper.Theme);
  675. }
  676. if (data.includes("Error")) {
  677. console.log(data);
  678. return;
  679. }
  680. //Reload the preview
  681. initCurrentBackgroundPreview();
  682. //Show change finsihed
  683. $("#wallpaperChangeConfirm").slideDown('fast').delay(3000).slideUp('fast');
  684. });
  685. }
  686. </script>
  687. </body>
  688. </html>