-
Notifications
You must be signed in to change notification settings - Fork 5
/
toolbox.js
357 lines (350 loc) · 13.8 KB
/
toolbox.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/**
* Sitecore Author Toolbox
* A Chrome/Edge Extension
* by Ugo Quaisse
* https://uquaisse.io
* ugo.quaisse@gmail.com
*/
/* eslint no-console: ["error", { allow: ["warn", "error", "log", "info", "table", "time", "timeEnd"] }] */
/**
* Load modules
*/
import * as global from "./modules/global.js";
import { log, loadJsFile, getScItemData } from "./modules/helpers.js";
import { initDarkMode, detectSwitchDarkMode } from "./modules/dark.js";
import { addHelptextIcons } from "./modules/help.js";
import { showSnackbar } from "./modules/snackbar.js";
import { checkWorkbox } from "./modules/workbox.js";
import { resumeFromWhereYouLeftOff, historyNavigation } from "./modules/history.js";
import { checkNotificationPermissions, checkPublishNotification } from "./modules/notification.js";
import { initFlagRibbonEE, initLanguageMenuEE, initLanguageMenuCE, initFlagsPublishingWindow, initFlagsPublish } from "./modules/language.js";
import { initCharsCount, initCheckboxes, initDateTimeField, initPasswordField, refreshContentEditor, contentTreeScrollTo, keyEventListeners, resetContentEditor } from "./modules/contenteditor.js";
import { initAppName, initGravatarImage, initUserMenu, initIntroScreen } from "./modules/users.js";
import { initInstantSearch, enhancedSitecoreSearch } from "./modules/search.js";
import { insertModal, insertPanel } from "./modules/insert.js";
import { initMediaExplorer, initMediaCounter, initMediaDragDrop, initMediaViewButtons, initUploadButton, initUploader, initLightbox, initMediaSearchBox } from "./modules/media.js";
import {
initOnboarding,
initExperimentalUi,
initInsertIcon,
initGutter,
initSitecoreRibbon,
initSvgAnimation,
initSvgAnimationPublish,
initEventListeners,
initTitleBarDesktop,
initMaterializeIcons,
insertSavebarEE,
} from "./modules/experimentalui.js";
import { initFavorites } from "./modules/favorites.js";
import { initGroupedErrors } from "./modules/errors.js";
import { enhancedBucketLists } from "./modules/buckets.js";
import { initRteTooltips, initSyntaxHighlighterRte } from "./modules/rte.js";
import { initPreviewButton, listenPreviewTab } from "./modules/preview.js";
import { initLaunchpadIcon, initLaunchpadMenu } from "./modules/launchpad.js";
import { initAutoExpandTree, initTreeGutterTooltips } from "./modules/contenttree.js";
import { initQuerySuggestions } from "./modules/template.js";
import { initPublishingStatus } from "./modules/publishingdashboard.js";
import {
initPreviewButtonsEE,
updateEETitle,
storeCurrentPageEE,
addToolbarEditCE,
addToolbarTooltip,
addPlaceholderTooltip,
resetExperienceEditor,
initRenderingSearchBox,
initOptionalFields,
initGroupedErrorsEE,
} from "./modules/experienceeditor.js";
import { initHorizon } from "./modules/horizon.js";
import { initTabSections } from "./modules/tabs.js";
/**
* Get all user's settings from chrome storage
*/
chrome.storage.sync.get((storage) => {
/*
**********************
* Sitecore detection *
**********************
*/
if (global.isSitecore && global.isSitecoreJs && !global.isEditMode && !global.isLoginPage && !global.isCss) {
log("Sitecore detected", "red");
document.body ? document.body.classList.add("satExtension") : false;
loadJsFile("js/inject.js");
checkNotificationPermissions();
checkPublishNotification(storage);
initAutoExpandTree(storage);
keyEventListeners();
initUserMenu(storage);
initDarkMode(storage);
detectSwitchDarkMode(storage);
/*
**********************
* 1. CE Application *
**********************
*/
if (global.isContentEditor) {
log("**** CE ****", "yellow");
let ScItem = getScItemData();
initTreeGutterTooltips();
refreshContentEditor(storage);
resumeFromWhereYouLeftOff(storage);
initInstantSearch(storage);
initFavorites(storage);
historyNavigation();
showSnackbar(storage);
contentTreeScrollTo();
initLightbox();
initIntroScreen();
if (storage.feature_experimentalui) {
log("**** Experimental ****", "yellow");
initAppName(storage, "Content Editor");
initSvgAnimation(storage);
insertModal(storage, ScItem.id, ScItem.language, ScItem.version);
insertPanel();
initInsertIcon(storage);
initGutter();
initSitecoreRibbon();
initEventListeners();
initTitleBarDesktop();
initOnboarding();
initMaterializeIcons(storage);
}
}
/*
************************
* 2. Sitecore pages *
************************
*/
if (global.isLaunchpad) {
log("**** Launchpad ****", "orange");
initLaunchpadIcon(storage);
checkWorkbox(storage);
showSnackbar(storage);
initIntroScreen();
} else if (global.isDesktop && !global.isGalleryFavorites && !global.isXmlControl) {
log("**** Desktop Shell ****", "orange");
initAppName(storage, "Sitecore Desktop");
initLaunchpadMenu(storage);
checkWorkbox(storage);
showSnackbar(storage);
} else if (global.isUserManager) {
log("**** User Manager ****", "orange");
initAppName(storage, "User Manager");
} else if (global.isSecurityEditor) {
log("**** Security Editor ****", "orange");
initAppName(storage, "Security Editor");
} else if (global.isAccessViewer) {
log("**** Access Viewer ****", "orange");
initAppName(storage, "Access Viewer");
} else if (global.isDomainManager) {
log("**** Domain Manager ****", "orange");
initAppName(storage, "Domain Manager");
} else if (global.isRoleManager) {
log("**** Role Manager ****", "orange");
initAppName(storage, "Role Manager");
} else if (global.isPowerShellIse) {
log("**** PowerShell ISE ****", "orange");
initAppName(storage, "PowerShell ISE");
} else if (global.isPowerShellReports) {
log("**** PowerShell Reports ****", "orange");
initAppName(storage, "PowerShell Reports");
} else if (global.isRecycleBin) {
log("**** Recycle Bin ****", "orange");
initAppName(storage, "Recycle Bin");
} else if (global.isWorkbox) {
log("**** Workbox ****", "orange");
initAppName(storage, "Workbox");
} else if (global.isTemplateBuilder) {
log("**** Template Builder ****", "orange");
initAppName(storage, "Template Builder");
initQuerySuggestions(storage);
} else if (global.isPublishDashboard) {
log("**** Publishing Dashboard ****", "orange");
initAppName(storage, "Publishing Dashboard");
initPublishingStatus(storage);
} else {
log("**** Non identified ****", "green");
log(global.windowLocationHref, "green");
initExperimentalUi(storage);
let appName = document.querySelector("*[data-sc-id=HeaderTitle]");
appName = appName ? appName.innerText : "";
initAppName(storage, appName);
}
/*
************************
* 3. Sitecore iframes *
************************
*/
if (global.isPreviewTab) {
log("**** Preview tab ****", "orange");
initPreviewButton(storage);
listenPreviewTab(storage);
} else if (global.isMediaFolder) {
log("**** Media Folder ****", "orange");
initMediaCounter(storage);
initMediaDragDrop(storage);
initMediaViewButtons(storage);
initMediaExplorer(storage);
initMediaSearchBox(storage);
initMaterializeIcons(storage);
} else if (global.isFieldEditor) {
log("**** Field editor ****", "orange");
initCheckboxes(storage);
initDateTimeField(storage);
initPasswordField(storage);
initCharsCount(storage);
initGroupedErrors(storage);
addHelptextIcons();
enhancedBucketLists();
initMaterializeIcons(storage);
initTabSections(storage);
} else if (global.isExperienceProfile) {
log("**** Experience Profile ****", "orange");
initGravatarImage(storage);
} else if (global.isRichTextEditor || global.isHtmlEditor) {
log("**** Rich Text Editor ****", "orange");
initRteTooltips(storage);
initSyntaxHighlighterRte(storage);
} else if ((global.isContentEditorApp && storage.feature_experimentalui) || (global.isContentEditorApp && storage.feature_instantsearch)) {
log("**** Content Editor App ****", "orange");
document.querySelector("#globalLogo") ? document.querySelector("#globalLogo").setAttribute("target", "_parent") : false;
} else if (global.isSearch) {
log("**** Internal Search ****", "orange");
enhancedSitecoreSearch(storage);
} else if (global.isGalleryLanguage) {
log("**** Languages menu ****", "orange");
initLanguageMenuCE(storage);
} else if (global.isPublishDialog) {
log("**** Publishing window ****", "orange");
initFlagsPublishingWindow(storage);
} else if (global.isPublishWindow || global.isInstallationWizard) {
log("**** Publish / Rebuild / Package ****", "orange");
initCheckboxes(storage);
initFlagsPublish(storage);
initSvgAnimationPublish(storage);
} else if (global.isExportSiteWizard) {
log("**** Export Site Wizard ****", "orange");
initSvgAnimationPublish(storage);
} else if (global.isUploadPackage) {
log("**** Upload Package ****", "orange");
initSvgAnimationPublish(storage);
} else if (global.isUserOptions) {
log("**** User options ****", "orange");
document.querySelectorAll(".scTabs > div > fieldset > div").forEach(function (elem) {
elem.innerText == "Quick info section" ? elem.setAttribute("style", "color:red; font-weight:bold") : false;
elem.innerText == "Item title bar" ? elem.setAttribute("style", "color:red; font-weight:bold") : false;
});
} else if (global.isEditorFolder) {
log("**** Editors folder ****", "orange");
initMaterializeIcons(storage);
} else if (global.isGalleryVersion) {
log("**** Versions menu ****", "orange");
} else if (global.isLayoutDetails) {
log("**** Layout Details ****", "orange");
initMaterializeIcons(storage);
} else if (global.isDialog || global.isLockedItems) {
log("**** Dialog UI ****", "orange");
initMaterializeIcons(storage);
initUploader();
} else if (global.isGalleryFavorites) {
log("**** Favorites ****", "orange");
initMaterializeIcons(storage);
} else if (global.isMediaBrowser) {
log("**** Media Browser ****", "orange");
initUploadButton(storage);
} else if (global.isSelectRendering && !global.isSourceBrowser) {
log("**** Select Rendering ****", "orange");
initAppName(storage, "Select Rendering");
initRenderingSearchBox(storage);
initMaterializeIcons(storage);
} else if (global.isXmlControl && !global.isRichText && !global.isWorkbox) {
log("**** XML Control (Window) ****", "orange");
initCheckboxes(storage);
initTabSections(storage);
initDateTimeField(storage);
initPasswordField(storage);
initMaterializeIcons(storage);
} else if (global.isSourceBrowser) {
log("**** Source Browser ****", "orange");
} else if (global.isGalleryLinks) {
log("**** Links menu ****", "orange");
}
} else {
//Reset default Sitecore
resetContentEditor();
}
/*
*******************************
* Experience Editor detection *
*******************************
*/
if ((global.isEditMode && !global.isLoginPage) || (global.isPreviewMode && !global.isLoginPage) || (global.isSitecoreModule && !global.isLoginPage)) {
log("Experience Editor detected", "red");
document.body ? document.body.classList.add("satExtension") : false;
loadJsFile("js/inject.js");
checkNotificationPermissions();
checkPublishNotification(storage);
keyEventListeners();
initFlagRibbonEE(storage);
initUserMenu(storage, "EE");
initDarkMode(storage);
detectSwitchDarkMode(storage);
/*
******************************
* 4. Sitecore iframes in EE *
******************************
*/
if (global.isRibbon) {
log("**** EE Ribbon ****", "orange");
document.querySelector("body").classList.add("satEEExperimentalUi");
initSitecoreRibbon();
initPreviewButtonsEE(storage);
storeCurrentPageEE();
insertSavebarEE(storage);
initGroupedErrorsEE(storage);
checkWorkbox(storage);
} else if (global.isPreviewMode && global.isEEPreview) {
document.querySelector("#ribbonPreLoadingIndicator").remove();
document.querySelector("#scWebEditRibbon").remove();
document.querySelector("#sc-ext-toggleRibon-button") ? document.querySelector("#sc-ext-toggleRibon-button").remove() : false;
log("**** Preview Mode ****", "orange");
} else if (global.isGalleryLanguageExpEd) {
log("**** Language Menu ****", "orange");
initLanguageMenuEE(storage);
} else if (global.isGalleryVersionExpEd) {
log("**** Version Menu ****", "orange");
} else if (global.isInsertPage) {
log("**** Insert Page ****", "orange");
initMaterializeIcons(storage);
} else if (global.isSitecoreModule) {
log("**** Sitecore Module ****", "orange");
} else if (global.isDialogEE) {
log("**** Dialog ****", "orange");
} else if (global.isNavigationTree) {
log("**** Navigation Tree ****", "orange");
initMaterializeIcons(storage);
} else {
log("**** Website preview in EE ****", "orange");
updateEETitle(storage);
addToolbarEditCE(storage);
addToolbarTooltip(storage);
addPlaceholderTooltip(storage);
//addHideRibbonButton(storage);
resetExperienceEditor(storage);
initMaterializeIcons(storage);
initOptionalFields(storage);
}
}
/*
*********************
* Horizon detection *
*********************
*/
if (global.isHorizon || global.isHorizonFieldBuilder || global.isHorizonExplorer) {
log("Horizon detected", "red");
document.body ? document.body.classList.add("satExtension") : false;
initHorizon(storage);
}
});