MCPcopy Index your code
hub / github.com/zxlie/FeHelper / _initToolbar

Function _initToolbar

apps/json-format/content-script.js:1027–1103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1025 };
1026
1027 let _initToolbar = () => {
1028 showToolBar = formatOptions.JSON_TOOL_BAR_ALWAYS_SHOW;
1029 let cspSafe = _checkContentSecurityPolicy();
1030 if (cspSafe) {
1031 // =============================排序:获取上次记录的排序方式
1032 if (formatOptions.ENABLE_JSON_KEY_SORT) {
1033 formatOptions.sortType = parseInt(localStorage.getItem(JSON_SORT_TYPE_KEY) || 0);
1034 // 排序选项初始化
1035 $('[name=jsonsort][value=' + formatOptions.sortType + ']').prop('checked', true);
1036 } else {
1037 formatOptions.sortType = 0;
1038 $('#jfToolbar .x-sort').hide();
1039 }
1040 _syncSortMenuState();
1041
1042 // =============================事件初始化
1043 $('[name=jsonsort]').click(function (e) {
1044 let sortType = parseInt(this.value);
1045 if (sortType !== formatOptions.sortType) {
1046 formatOptions.sortType = sortType;
1047 _didFormat();
1048 }
1049 _syncSortMenuState();
1050 localStorage.setItem(JSON_SORT_TYPE_KEY, sortType);
1051 });
1052 } else {
1053 $('#jfToolbar .x-sort').hide();
1054 }
1055
1056 _syncFormatterEscapeState();
1057
1058 // =============================乱码修正
1059 if (!formatOptions.FIX_ERROR_ENCODING) {
1060 $('#jfToolbar .x-fix-encoding').hide();
1061 }
1062
1063 // =============================工具栏的显示与隐藏控制
1064 let tgBtn = $('.fe-feedback #toggleBtn');
1065 _applyToolbarDisplayState();
1066 tgBtn.click(function (e) {
1067 e.preventDefault();
1068 e.stopPropagation();
1069
1070 showToolBar = !showToolBar;
1071 formatOptions.JSON_TOOL_BAR_ALWAYS_SHOW = showToolBar;
1072 _applyToolbarDisplayState();
1073 _saveJsonFormatOptions({JSON_TOOL_BAR_ALWAYS_SHOW: showToolBar});
1074 });
1075 $('.fe-feedback .fh-collapse-icon').on('click', function (e) {
1076 e.preventDefault();
1077 e.stopPropagation();
1078 tgBtn.trigger('click');
1079 });
1080 $('.fe-feedback .fh-collapse-icon').on('keydown', function (e) {
1081 if (e.key !== 'Enter' && e.key !== ' ') {
1082 return;
1083 }
1084 e.preventDefault();

Callers 1

_formatTheSourceFunction · 0.85

Calls 11

_syncSortMenuStateFunction · 0.85
_didFormatFunction · 0.85
_saveJsonFormatOptionsFunction · 0.85
_createSettingPanelFunction · 0.85
_getCorrectContentFunction · 0.85
_bindOmniToolbarFunction · 0.85
hideMethod · 0.80
$Function · 0.50

Tested by

no test coverage detected