exports.listen = function listen(window, node, event, func, capture) { // Default to use capture if (capture == null) capture = true; node.addEventListener(event, func, capture); function undoListen() { node.removeEventListener(event, func, capture); } // Undo the listener on unload and provide a way to undo everything let undoUnload = unload(undoListen, window); return function() { undoListen(); undoUnload(); }; }
function CompletionMenu( configObject ) { try{ let window = configObject.window; this.window = window; let { document, gBrowser} = window; let {change, createNode, listen, unload} = makeWindowHelpers(window); this.createNode = createNode; let menu = createNode("menupopup"); menu.setAttribute("ignorekeys", "true"); document.getElementById("mainPopupSet").appendChild(menu); unload(function() { menu.parentNode.removeChild(menu); }); this.generalSeparator = createNode("menuseparator"); menu.appendChild(this.generalSeparator); this.contextSeparator = createNode("menuseparator"); menu.appendChild(this.contextSeparator); this.contextItem = createNode("menuitem"); this.contextItem.setAttribute("label", "Use current page for suggestions"); this.contextItem.setAttribute("checked", preferences.get( COMPLETION_MENU_USE_CONTEXT , "false")); this.contextItem.setAttribute("type", "checkbox"); this.contextItem.addEventListener("command", function( event ) { preferences.set( COMPLETION_MENU_USE_CONTEXT , this.contextItem.hasAttribute("checked") ); event.stopPropagation(); }.bind( this )); // Per Blekko request - context sensetive suggestions are turned off // to turn them on make default value for "checked" attribute true and // uncomment line bellow //menu.appendChild(this.contextItem); this.previewItem = createNode("menuitem"); this.previewItem.setAttribute("label", "Preview highlighted terms"); this.previewItem.setAttribute("checked", preferences.get( COMPLETION_MENU_PREVIEW , "true")); this.previewItem.setAttribute("type", "checkbox"); this.previewItem.addEventListener("command", function( event ) { preferences.set( COMPLETION_MENU_PREVIEW , this.previewItem.hasAttribute("checked") ); event.stopPropagation(); event.preventDefault(); }.bind( this )); menu.appendChild(this.previewItem); this.preselectItem = createNode("menuitem"); this.preselectItem.setAttribute("label", "Preselect first term"); this.preselectItem.setAttribute("checked", preferences.get( COMPLETION_MENU_PRESELECT , "true")); this.preselectItem.setAttribute("type", "checkbox"); this.preselectItem.addEventListener("command", function( event ) { preferences.set( COMPLETION_MENU_PRESELECT , this.preselectItem.hasAttribute("checked") ); event.stopPropagation(); event.preventDefault(); }.bind( this )); menu.appendChild(this.preselectItem); this.menu = menu; this.generalItems = []; this.contextItems = []; this.activeItem = null; this.onItemClick = configObject.onItemClick; this.onItemActivation = configObject.onItemActivation; // add listerners menu.addEventListener("DOMAttrModified", function({attrName, target}) { if (attrName != "_moz-menuactive") return; // Track the newly activated item if (target.hasAttribute("_moz-menuactive")) { // Mouse event activated a different target, so clear the previous item if (this.activeItem != null && this.activeItem != target) { this.activeItem.removeAttribute("_moz-menuactive"); } this.activeItem = target; // do a bit of delay to stop flurry of page loads in preview //this.window.setTimeout( function( ) { // // make sure the target is still selected // if( this.isOpen( ) && target.hasAttribute("_moz-menuactive") && !this.isConfigItem( target )) { // configObject.onItemActivation( this.getActiveItemData( ) ); // } // }.bind( this ) , 10 ); // call it directly if( this.isOpen( ) && target.hasAttribute("_moz-menuactive") && !this.isConfigItem( target )) { configObject.onItemActivation( this.getActiveItemData( ) ); } } // Item is deactivating, so untrack if it's the one else if (target == this.activeItem) { this.activeItem = null; } }.bind( this )); if( configObject.onMenuHide ) { menu.addEventListener("popuphidden", function( event ) { configObject.onMenuHide( event ); } ); } if( configObject.onMenuShow ) { menu.addEventListener("popupshown", function( event ) { configObject.onMenuShow( event ); } ); } } catch ( ex ) { trace( "ERROR " + ex ); } }