|
350 | 350 | self.$desktop = $('.desktop').first(); |
351 | 351 | self.$taskbar = $('.taskbar').first(); |
352 | 352 | self._applyStoredCustomWallpaper(); |
| 353 | + self.frontend = frontend; |
353 | 354 |
|
354 | 355 | var desktopIcons = self._getDesktopIcons(self.options.icons, self.useFolders); |
| 356 | + var renderDesktopIcons = function(iconList) { |
| 357 | + self.$desktop.find('a.emuos-desktop-icon').remove(); |
| 358 | + self._foldersByPath = {}; |
355 | 359 |
|
356 | | - for (var j in desktopIcons) { |
| 360 | + for (var j in iconList) { |
357 | 361 | // noinspection JSUnfilteredForInLoop,JSDuplicatedDeclaration |
358 | | - var icon_options = desktopIcons[j]; |
| 362 | + var icon_options = iconList[j]; |
359 | 363 |
|
360 | 364 | if (typeof icon_options['requires'] === 'object') { |
361 | 365 | var reqs = Object.keys(icon_options['requires']); |
|
560 | 564 | title: $(this).data('name'), |
561 | 565 | credits: $(this).data('credits'), |
562 | 566 | icon: $(this).data('icon'), |
563 | | - src: frontend, |
| 567 | + src: self.frontend, |
564 | 568 | newtab: $(this).data('newtab'), |
565 | 569 | width: $(this).data('width'), |
566 | 570 | height: $(this).data('height') |
|
571 | 575 | self.iframe({ |
572 | 576 | title: $(this).data('name'), |
573 | 577 | icon: $(this).data('icon'), |
574 | | - src: frontend, |
| 578 | + src: self.frontend, |
575 | 579 | newtab: $(this).data('newtab'), |
576 | 580 | width: $(this).data('width'), |
577 | 581 | height: $(this).data('height'), |
|
713 | 717 | } |
714 | 718 | } |
715 | 719 | }); |
716 | | - } |
| 720 | + } |
| 721 | + }; |
| 722 | + |
| 723 | + self.desktopIcons = desktopIcons; |
| 724 | + renderDesktopIcons(self.desktopIcons); |
717 | 725 |
|
718 | 726 | // noinspection JSUnresolvedFunction |
719 | 727 | self.$taskbar.taskbar({ |
|
1071 | 1079 | } |
1072 | 1080 | }); |
1073 | 1081 |
|
1074 | | - self.$html.contextmenu({ |
1075 | | - delegate: '.emuos-desktop, .emuos-taskbar', |
1076 | | - menu: [{ |
1077 | | - title: 'Refresh', |
1078 | | - cmd: 'refresh', |
1079 | | - uiIcon: 'ui-icon-refresh' |
| 1082 | + var hasCustomWallpaper = !!self._getCustomWallpaper(); |
| 1083 | + var desktopMenu = [{ |
| 1084 | + title: 'Refresh', |
| 1085 | + cmd: 'refresh', |
| 1086 | + uiIcon: 'ui-icon-refresh' |
| 1087 | + } , { |
| 1088 | + title: '----' |
| 1089 | + } , { |
| 1090 | + title: 'Custom Wallpaper', |
| 1091 | + cmd: 'custom-wallpaper', |
| 1092 | + uiIcon: 'ui-icon-image' |
| 1093 | + }]; |
| 1094 | + |
| 1095 | + if (hasCustomWallpaper) { |
| 1096 | + desktopMenu.push({ |
| 1097 | + title: 'Remove Custom Wallpaper', |
| 1098 | + cmd: 'remove-custom-wallpaper', |
| 1099 | + uiIcon: 'ui-icon-trash' |
| 1100 | + }); |
| 1101 | + } |
| 1102 | + |
| 1103 | + desktopMenu = desktopMenu.concat([{ |
| 1104 | + title: '----' |
| 1105 | + } , { |
| 1106 | + title: 'Themes', |
| 1107 | + children: [{ |
| 1108 | + title: 'Basic', |
| 1109 | + cmd: 'basic' |
1080 | 1110 | } , { |
1081 | | - title: '----' |
| 1111 | + title: 'Windows 3.1', |
| 1112 | + cmd: 'windows-3' |
1082 | 1113 | } , { |
1083 | | - title: 'Custom Wallpaper...', |
1084 | | - cmd: 'custom-wallpaper', |
1085 | | - uiIcon: 'ui-icon-image' |
| 1114 | + title: 'Windows 95', |
| 1115 | + cmd: 'windows-95' |
1086 | 1116 | } , { |
1087 | | - title: '----' |
| 1117 | + title: 'Windows 98', |
| 1118 | + cmd: 'windows-98' |
1088 | 1119 | } , { |
1089 | | - title: 'Themes', |
1090 | | - children: [{ |
1091 | | - title: 'Basic', |
1092 | | - cmd: 'basic' |
1093 | | - } , { |
1094 | | - title: 'Windows 3.1', |
1095 | | - cmd: 'windows-3' |
1096 | | - } , { |
1097 | | - title: 'Windows 95', |
1098 | | - cmd: 'windows-95' |
1099 | | - } , { |
1100 | | - title: 'Windows 98', |
1101 | | - cmd: 'windows-98' |
1102 | | - } , { |
1103 | | - title: 'Windows ME', |
1104 | | - cmd: 'windows-me' |
1105 | | - }] |
1106 | | - } , { |
1107 | | - title: '----' |
1108 | | - } , { |
1109 | | - title: 'Use Folders', |
1110 | | - cmd: 'toggle-folders', |
1111 | | - uiIcon: self.useFolders ? 'ui-icon-check' : '' |
1112 | | - }], |
| 1120 | + title: 'Windows ME', |
| 1121 | + cmd: 'windows-me' |
| 1122 | + }] |
| 1123 | + } , { |
| 1124 | + title: '----' |
| 1125 | + } , { |
| 1126 | + title: 'Use Folders', |
| 1127 | + cmd: 'toggle-folders', |
| 1128 | + uiIcon: self.useFolders ? 'ui-icon-check' : '' |
| 1129 | + }]); |
| 1130 | + |
| 1131 | + self.$html.contextmenu({ |
| 1132 | + delegate: '.emuos-desktop, .emuos-taskbar', |
| 1133 | + menu: desktopMenu, |
1113 | 1134 | select: function(e, ui) { |
1114 | 1135 | switch (ui.cmd) { |
1115 | 1136 | case 'refresh': |
|
1119 | 1140 | case 'custom-wallpaper': |
1120 | 1141 | self._promptCustomWallpaper(); |
1121 | 1142 | break; |
| 1143 | + case 'remove-custom-wallpaper': |
| 1144 | + self._clearCustomWallpaper(); |
| 1145 | + break; |
1122 | 1146 | case 'toggle-folders': |
1123 | 1147 | self.useFolders = !self.useFolders; |
1124 | 1148 |
|
1125 | 1149 | if (typeof simplestorage !== 'undefined' && typeof simplestorage.set === 'function') { |
1126 | 1150 | simplestorage.set('useFolders', self.useFolders); |
1127 | 1151 | } |
1128 | 1152 |
|
1129 | | - window.location.reload(); |
| 1153 | + self.desktopIcons = self._getDesktopIcons(self.options.icons, self.useFolders); |
| 1154 | + renderDesktopIcons(self.desktopIcons); |
1130 | 1155 | break; |
1131 | 1156 | case 'basic': |
1132 | 1157 | self.$html.removeClass('theme-windows-3 theme-windows-95 theme-windows-98 theme-windows-me').addClass('theme-basic'); |
|
1227 | 1252 | route = route.slice(0, route.lastIndexOf('?')); |
1228 | 1253 | } |
1229 | 1254 |
|
1230 | | - for (var j in desktopIcons) { |
| 1255 | + for (var j in self.desktopIcons) { |
1231 | 1256 | // noinspection JSUnfilteredForInLoop,JSDuplicatedDeclaration |
1232 | | - var icon_options = desktopIcons[j]; |
| 1257 | + var icon_options = self.desktopIcons[j]; |
1233 | 1258 |
|
1234 | 1259 | if (typeof icon_options['link'] !== 'undefined') { |
1235 | 1260 | var icon_link = ''; |
|
1290 | 1315 | simplestorage.set('customWallpaper', dataUrl); |
1291 | 1316 | }; |
1292 | 1317 |
|
| 1318 | + EmuOS.prototype._clearCustomWallpaper = function() { |
| 1319 | + if (typeof simplestorage !== 'undefined' && typeof simplestorage.deleteKey === 'function') { |
| 1320 | + simplestorage.deleteKey('customWallpaper'); |
| 1321 | + } else if (typeof simplestorage !== 'undefined' && typeof simplestorage.set === 'function') { |
| 1322 | + simplestorage.set('customWallpaper', ''); |
| 1323 | + } |
| 1324 | + |
| 1325 | + this.$desktop.css({ |
| 1326 | + 'background-image': '', |
| 1327 | + 'background-size': '', |
| 1328 | + 'background-position': '', |
| 1329 | + 'background-repeat': '' |
| 1330 | + }); |
| 1331 | + }; |
| 1332 | + |
1293 | 1333 | EmuOS.prototype._applyCustomWallpaper = function(dataUrl) { |
1294 | 1334 | if (!dataUrl || typeof dataUrl !== 'string') { |
1295 | 1335 | return; |
|
0 commit comments