forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchForBug419911_Fx3.7.uc.js
374 lines (325 loc) · 12.7 KB
/
patchForBug419911_Fx3.7.uc.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// ==UserScript==
// @name patchForBug419911_Fx3.7.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description Bug 419911 - Bookmarks submenu is closed immediately during dragging , およびBug 555474 - While bookmark is dragged, the tooltip should not appear を修正
// @include main
// @compatibility Firefox 4.0b2pre
// @author Alice0775
// @version 2013/01/16 12:00 Bug 831008 Disable Mutation Events in chrome/XUL
// ==/UserScript==
// @version 2011/01/04 Bug 583386 - Implement latest Firefox Menu design
// @version 2010/05/06 Bug 528884 - Remove places' menu and toolbar bindings
// @version 2010/03/29 Minefield 3.7a4pre
// @note menu.xmlを修正するのが本当だが....
var bug419911 = {
//-- config --
STAY_OPEN_ONDRAGEXIT_AS_FX2: false, //Firefox2の様にドラッグ終了後メニューを 閉じない:true, 閉じる:[false]
//-- config --
menupopup: ["bookmarksMenuPopup",
'PlacesToolbar',
'BMB_bookmarksPopup',
'appmenu_bookmarksPopup',
'BookmarksMenuToolButtonPopup',
'UnsortedBookmarksFolderToolButtonPopup',
'bookmarksMenuPopup-context'],
timer:[],
count:[],
init: function(){
//window.removeEventListener("load", this, false);
window.addEventListener('unload', this, false);
this.addPrefListener(this.PrefListener);
window.addEventListener("aftercustomization", this, false);
this.initPref();
this.delayedStartup();
},
uninit: function(){
window.removeEventListener('unload', this, false);
this.removePrefListener(this.PrefListener);
window.removeEventListener("aftercustomization", this, false);
for (var i = 0; i < this.menupopup.length; i++){
var menupopup = document.getElementById(this.menupopup[i]);
if (menupopup){
menupopup.removeEventListener('popupshowing', this, false);
menupopup.removeEventListener('popuphiding', this, false);
}
}
},
initPref: function(){
this.STAY_OPEN_ONDRAGEXIT_AS_FX2 =
this.getPref('extensions.bug419911.enable.stay_on_menu_on_dragexit_like_Fx2',
'bool', false);
},
//delayed startup
delayedStartup: function(){
//wait till construction of bookmarksBarContent is completed.
for (var i = 0; i < this.menupopup.length; i++){
this.count[i] = 0;
this.timer[i] = setInterval(function(self, i){
if(++self.count[i] > 50 || document.getElementById(self.menupopup[i])){
clearInterval(self.timer[i]);
var menupopup = document.getElementById(self.menupopup[i]);
if (menupopup) {
menupopup.addEventListener('popupshowing', self, false);
menupopup.addEventListener('popuphiding', self, false);
}
}
}, 250, this, i);
}
},
handleEvent: function(event){
switch (event.type) {
case 'popupshowing':
this.popupshowing(event);
break;
case 'popuphiding':
this.popuphiding(event);
break;
case "aftercustomization":
//After customize toolbar
setTimeout(function(self){self.delayedStartup(self);}, 0, this);
break;
case 'load':
this.init();
break;
case 'unload':
this.uninit();
break;
}
},
popuphiding: function(event) {
var menupopup = event.originalTarget;
menupopup.parentNode.parentNode.openNode = null;
if (menupopup.parentNode.localName == "toolbarbutton") {
menupopup.parentNode.parentNode._openedMenuButton = null;
//patch for Bug 225434 - dragging bookmark from personal toolbar and releasing
// (on same bookmark or elsewhere) or clicking on bookmark menu then cancelling
// leaves button depressed/sunken when hovered
//not yet
if (!PlacesControllerDragHelper.getSession())
// Clear the dragover attribute if present, if we are dragging into a
// folder in the hierachy of current opened popup we don't clear
// this attribute on clearOverFolder. See Notify for closeTimer.
if (menupopup.parentNode.hasAttribute("dragover"))
menupopup.parentNode.removeAttribute("dragover");
}
},
popupshowing: function(event) {
var menupopup = event.originalTarget;
bug419911.debug("popupshowing ===============\n" + menupopup.parentNode.getAttribute('label'));
var parentPopup = menupopup.parentNode.parentNode;
if (!!parentPopup.openNode){
try {
parentPopup.openNode.hidePopup();
} catch(e){}
}
parentPopup.openNode = menupopup;
menupopup.onDragStart = function (event) {
// xxx Bug 555474 - While bookmark is dragged, the tooltip should not appear
bug419911.hideTooltip();
}
menupopup.onDragOver = function (event) {
// xxx Bug 555474 - While bookmark is dragged, the tooltip should not appear
bug419911.hideTooltip();
var target = event.originalTarget;
while (target) {
if (/menupopup/.test(target.localName))
break;
target = target.parentNode;
}
if (this != target)
return;
event.stopPropagation();
bug419911.debug("onDragOver " + "\n" + this.parentNode.getAttribute('label'));
PlacesControllerDragHelper.currentDropTarget = event.target;
let dt = event.dataTransfer;
let dropPoint = this._getDropPoint(event);
if (!dropPoint || !dropPoint.ip ||
!PlacesControllerDragHelper.canDrop(dropPoint.ip, dt)) {
this._indicatorBar.hidden = true;
event.stopPropagation();
return;
}
// Mark this popup as being dragged over.
this.setAttribute("dragover", "true");
if (dropPoint.folderElt) {
// We are dragging over a folder.
// _overFolder should take the care of opening it on a timer.
if (this._overFolder.elt &&
this._overFolder.elt != dropPoint.folderElt) {
// We are dragging over a new folder, let's clear old values
/* this._overFolder.clear();*/
}
if (!this._overFolder.elt) {
this._overFolder.elt = dropPoint.folderElt;
// Create the timer to open this folder.
this._overFolder.openTimer = this._overFolder
.setTimer(this._overFolder.hoverTime);
}
// Since we are dropping into a folder set the corresponding style.
/* dropPoint.folderElt.setAttribute("_moz-menuactive", true);*/
}
else {
// We are not dragging over a folder.
// Clear out old _overFolder information.
/* this._overFolder.clear();*/
}
// Autoscroll the popup strip if we drag over the scroll buttons.
let anonid = event.originalTarget.getAttribute('anonid');
let scrollDir = anonid == "scrollbutton-up" ? -1 :
anonid == "scrollbutton-down" ? 1 : 0;
if (scrollDir != 0) {
this._scrollBox.scrollByIndex(scrollDir, false);
}
// Check if we should hide the drop indicator for this target.
if (dropPoint.folderElt || this._hideDropIndicator(event)) {
this._indicatorBar.hidden = true;
event.preventDefault();
event.stopPropagation();
return;
}
// We should display the drop indicator relative to the arrowscrollbox.
let sbo = this._scrollBox.scrollBoxObject;
let newMarginTop = 0;
if (scrollDir == 0) {
let elt = this.firstChild;
while (elt && event.screenY > elt.boxObject.screenY +
elt.boxObject.height / 2)
elt = elt.nextSibling;
newMarginTop = elt ? elt.boxObject.screenY - sbo.screenY :
sbo.height;
}
else if (scrollDir == 1)
newMarginTop = sbo.height;
// Set the new marginTop based on arrowscrollbox.
newMarginTop += sbo.y - this._scrollBox.boxObject.y;
this._indicatorBar.firstChild.style.marginTop = newMarginTop + "px";
this._indicatorBar.hidden = false;
event.preventDefault();
event.stopPropagation();
}
menupopup.onDragExit = function (event) {
var target = event.originalTarget;
while (target) {
if (/menupopup/.test(target.localName))
break;
target = target.parentNode;
}
if (this != target)
return;
event.stopPropagation();
bug419911.debug("onDragExit");
PlacesControllerDragHelper.currentDropTarget = null;
this.removeAttribute("dragover");
// If we have not moved to a valid new target clear the drop indicator
// this happens when moving out of the popup.
let target = event.relatedTarget;
if (!target)
this._indicatorBar.hidden = true;
// Close any folder being hovered over
if (this._overFolder.elt) {
this._overFolder.closeTimer = this._overFolder
.setTimer(this._overFolder.hoverTime);
}
// The autoopened attribute is set when this folder was automatically
// opened after the user dragged over it. If this attribute is set,
// auto-close the folder on drag exit.
// We should also try to close this popup if the drag has started
// from here, the timer will check if we are dragging over a child.
if (this.hasAttribute("autoopened") ||
/**/ !bug419911.STAY_OPEN_ONDRAGEXIT_AS_FX2 &&
this.hasAttribute("dragstart")) {
this._overFolder.closeMenuTimer = this._overFolder
.setTimer(this._overFolder.hoverTime);
}
event.stopPropagation();
}
menupopup.addEventListener("dragstart", menupopup.onDragStart, true);
menupopup.addEventListener("dragover", menupopup.onDragOver, true);
menupopup.addEventListener("dragleave", menupopup.onDragExit, true);
},
hideTooltip: function() {
["bhTooltip", "btTooltip2"].forEach(function(id) {
var tooltip = document.getElementById(id);
if (tooltip)
tooltip.hidePopup();
});
},
//Fxのバージョン
get getVer(){
const Cc = Components.classes;
const Ci = Components.interfaces;
var info = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
var ver = parseInt(info.version.substr(0,3) * 10,10) / 10;
return ver;
},
debug: function(aMsg){
return;
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(aMsg);
},
getPref: function(aPrefString, aPrefType, aDefault){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefService);
try{
switch (aPrefType){
case 'complex':
return xpPref.getComplexValue(aPrefString, Components.interfaces.nsILocalFile); break;
case 'str':
return xpPref.getCharPref(aPrefString).toString(); break;
case 'int':
return xpPref.getIntPref(aPrefString); break;
case 'bool':
default:
return xpPref.getBoolPref(aPrefString); break;
}
}catch(e){
}
return aDefault;
},
setPref: function(aPrefString, aPrefType, aValue){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefService);
try{
switch (aPrefType){
case 'complex':
return xpPref.setComplexValue(aPrefString, Components.interfaces.nsILocalFile, aValue); break;
case 'str':
return xpPref.setCharPref(aPrefString, aValue); break;
case 'int':
aValue = parseInt(aValue);
return xpPref.setIntPref(aPrefString, aValue); break;
case 'bool':
default:
return xpPref.setBoolPref(aPrefString, aValue); break;
}
}catch(e){
}
return null;
},
//Thanks Piro.
addPrefListener: function(aObserver) {
try {
var pbi = Components.classes['@mozilla.org/preferences;1'].
getService(Components.interfaces.nsIPrefBranch2);
pbi.addObserver(aObserver.domain, aObserver, false);
} catch(e) {}
},
removePrefListener: function(aObserver) {
try {
var pbi = Components.classes['@mozilla.org/preferences;1'].
getService(Components.interfaces.nsIPrefBranch2);
pbi.removeObserver(aObserver.domain, aObserver);
} catch(e) {}
},
PrefListener:{
domain : 'extensions.bug419911.enable.stay_on_menu_on_dragexit_like_Fx2',
observe : function(aSubject, aTopic, aPrefstring) {
if (aTopic == 'nsPref:changed') {
bug419911.initPref();
}
}
}
}
//window.addEventListener("load", bug419911, false);
bug419911.init();