<commit_before>Modules.VERSION = '1.4.3';

this.__defineGetter__('BookmarkingUI', function() { return window.BookmarkingUI; });
this.__defineGetter__('StarUI', function() { return window.StarUI; });
this.__defineGetter__('PlacesCommandHook', function() { return window.PlacesCommandHook; });

this.bookmarkedItem = {
	initialized: false,
	_anchor: false,
	
	get button() { return BookmarkingUI.button; },
	get broadcaster() { return BookmarkingUI.broadcaster; },
	get editPanel() { return $('editBookmarkPanel'); },
	get key() { return $('addBookmarkAsKb'); },
	get light() { return skyLights.get('bookmarkedItem'); },
	
	handleEvent: function(e) {
		switch(e.type) {
			case 'popupshowing':
				if(e.target == this.editPanel) {
					Listeners.remove(window, 'popupshowing', this);
					Listeners.add(e.target, 'AskingForNodeOwner', this);
				}
				break;
			
			case 'AskingForNodeOwner':
				if(!this.initialized || e.target.anchorNode != this.light) {
					e.detail = 'bookmarks-menu-button';
					e.stopPropagation();
				}
				break;
			
			case 'LoadedSkyLights':
				this.init();
				break;
			
			case 'UnloadingSkyLights':
				this.deinit();
				break;
			
			case 'LoadedSlimChromePopups':
				this.popupInit();
				break;
			
			case 'UnloadingSlimChromePopups':
				this.popupDeinit();
				break;
			
			// this is the Ctrl+D handler, we need to choose the best place where to open the panel in this case
			case 'command':
				// if the bookmarked item sky light is active, there's no need to show any of the chrome,
				// we can simply attach the editPanel to the light as if it was clicked
				if(this.light.parentNode
				&& !trueAttribute(slimChrome.container, 'hover')
				&& !trueAttribute(slimChrome.container, 'mini')) {
					this._anchor = this.light;
				}
				
				// follow through with the original command to open the editPanel
				let command = $(this.key.getAttribute('originalcommand'));
				if(!trueAttribute(command, 'disabled')) {
					command.doCommand();
				}
				break;
		}
	},
	
	attrWatcher: function() {
		// no point in over-calling this if more than just one attribute changes,
		// which is often the case as both "starred" and "buttontooltiptext" usually (always?) change together
		Timers.init('bookmarkedItemAttrWatcher', () => { this.update(); }, 0);
	},
	
	init: function() {
		if(this.initialized) { return; }
		this.initialized = true;
		
		setAttribute(this.key, 'originalcommand', this.key.getAttribute('command'));
		removeAttribute(this.key, 'command');
		setAttribute(this.key, 'oncommand', ';'); // the command event won't fire if there isn't "something" to "command"
		Listeners.add(this.key, 'command', this);
		
		Watchers.addAttributeWatcher(this.broadcaster, 'starred', this, false, false);
		Watchers.addAttributeWatcher(this.broadcaster, 'buttontooltiptext', this, false, false);
		
		this.update(true);
	},
	
	deinit: function() {
		if(!this.initialized) { return; }
		this.initialized = false;
		
		Timers.cancel('bookmarkedItemAttrWatcher');
		
		setAttribute(this.key, 'command', this.key.getAttribute('originalcommand'));
		removeAttribute(this.key, 'originalcommand');
		removeAttribute(this.key, 'oncommand');
		Listeners.remove(this.key, 'command', this);
		
		this.remove();
		
		Watchers.removeAttributeWatcher(this.broadcaster, 'starred', this, false, false);
		Watchers.removeAttributeWatcher(this.broadcaster, 'buttontooltiptext', this, false, false);
	},
	
	popupInit: function() {
		// this shouldn't depend on the Sky Light being initialized
		setAttribute(this.button, 'showInMiniBar', 'true');
		
		popups.mini.add('editBookmarkPanel');
		
		// the editBookmarkPanel is only created when first called
		if(bookmarkedItem.editPanel) {
			Listeners.add(this.editPanel, 'AskingForNodeOwner', this);
		} else {
			Listeners.add(window, 'popupshowing', this);
		}
	},
	
	popupDeinit: function() {
		removeAttribute(this.button, 'showInMiniBar');
		
		popups.mini.delete('editBookmarkPanel');
		
		Listeners.remove(this.editPanel, 'AskingForNodeOwner', this);
		Listeners.remove(window, 'popupshowing', this);
	},
	
	update: function(initialize) {
		let starred = trueAttribute(this.broadcaster, 'starred');
		let tooltip = this.broadcaster.getAttribute('buttontooltiptext');
		
		let props = {
			state: starred ? 'starred' : 'unstarred',
			tooltip: tooltip,
			color: starred ? 'rgb(20,103,220)' : 'transparent'
		};
		
		if(initialize) {
			props.label = Strings.get('skyLights', 'bookmarkedItemLabel');
			props.description = Strings.get('skyLights', 'bookmarkedItemDescription');
			props.speed = 250;
			
			// adapted from BookmarkingUI.onCommand() - http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser-places.js#1630
			props.action = (e) => {
				// only left-clicks on the light should bookmark the page
				if(e.button != 0) { return; }
				
				let isBookmarked = BookmarkingUI._itemIds.length > 0;
				
				// Ignore clicks on the star if we are updating its state.
				if(!BookmarkingUI._pendingStmt) {
					if(isBookmarked) {
						this._anchor = bookmarkedItem.light;
					} else {
						// blink the light three times to show that the page was bookmarked
						skyLights.update('bookmarkedItem', { alert: 2 });
					}
					PlacesCommandHook.bookmarkCurrentPage(isBookmarked);
				}
			};
		}
		
		skyLights.update('bookmarkedItem', props);
	},
	
	remove: function() {
		skyLights.remove('bookmarkedItem');
	}
};<commit_msg>disable bookmark light when star icon is disabled<commit_after>Modules.VERSION = '1.4.4';

this.__defineGetter__('BookmarkingUI', function() { return window.BookmarkingUI; });
this.__defineGetter__('StarUI', function() { return window.StarUI; });
this.__defineGetter__('PlacesCommandHook', function() { return window.PlacesCommandHook; });

this.bookmarkedItem = {
	initialized: false,
	_anchor: false,
	
	get button() { return BookmarkingUI.button; },
	get broadcaster() { return BookmarkingUI.broadcaster; },
	get editPanel() { return $('editBookmarkPanel'); },
	get key() { return $('addBookmarkAsKb'); },
	get light() { return skyLights.get('bookmarkedItem'); },
	
	handleEvent: function(e) {
		switch(e.type) {
			case 'popupshowing':
				if(e.target == this.editPanel) {
					Listeners.remove(window, 'popupshowing', this);
					Listeners.add(e.target, 'AskingForNodeOwner', this);
				}
				break;
			
			case 'AskingForNodeOwner':
				if(!this.initialized || e.target.anchorNode != this.light) {
					e.detail = 'bookmarks-menu-button';
					e.stopPropagation();
				}
				break;
			
			case 'LoadedSkyLights':
				this.init();
				break;
			
			case 'UnloadingSkyLights':
				this.deinit();
				break;
			
			case 'LoadedSlimChromePopups':
				this.popupInit();
				break;
			
			case 'UnloadingSlimChromePopups':
				this.popupDeinit();
				break;
			
			// this is the Ctrl+D handler, we need to choose the best place where to open the panel in this case
			case 'command':
				// if the bookmarked item sky light is active, there's no need to show any of the chrome,
				// we can simply attach the editPanel to the light as if it was clicked
				if(this.light.parentNode
				&& !trueAttribute(slimChrome.container, 'hover')
				&& !trueAttribute(slimChrome.container, 'mini')) {
					this._anchor = this.light;
				}
				
				// follow through with the original command to open the editPanel
				let command = $(this.key.getAttribute('originalcommand'));
				if(!trueAttribute(command, 'disabled')) {
					command.doCommand();
				}
				break;
		}
	},
	
	attrWatcher: function() {
		// no point in over-calling this if more than just one attribute changes,
		// which is often the case as both "starred" and "buttontooltiptext" usually (always?) change together
		Timers.init('bookmarkedItemAttrWatcher', () => { this.update(); }, 0);
	},
	
	init: function() {
		if(this.initialized) { return; }
		this.initialized = true;
		
		setAttribute(this.key, 'originalcommand', this.key.getAttribute('command'));
		removeAttribute(this.key, 'command');
		setAttribute(this.key, 'oncommand', ';'); // the command event won't fire if there isn't "something" to "command"
		Listeners.add(this.key, 'command', this);
		
		Watchers.addAttributeWatcher(this.broadcaster, 'starred', this, false, false);
		Watchers.addAttributeWatcher(this.broadcaster, 'buttontooltiptext', this, false, false);
		
		this.update(true);
	},
	
	deinit: function() {
		if(!this.initialized) { return; }
		this.initialized = false;
		
		Timers.cancel('bookmarkedItemAttrWatcher');
		
		setAttribute(this.key, 'command', this.key.getAttribute('originalcommand'));
		removeAttribute(this.key, 'originalcommand');
		removeAttribute(this.key, 'oncommand');
		Listeners.remove(this.key, 'command', this);
		
		this.remove();
		
		Watchers.removeAttributeWatcher(this.broadcaster, 'starred', this, false, false);
		Watchers.removeAttributeWatcher(this.broadcaster, 'buttontooltiptext', this, false, false);
	},
	
	popupInit: function() {
		// this shouldn't depend on the Sky Light being initialized
		setAttribute(this.button, 'showInMiniBar', 'true');
		
		popups.mini.add('editBookmarkPanel');
		
		// the editBookmarkPanel is only created when first called
		if(bookmarkedItem.editPanel) {
			Listeners.add(this.editPanel, 'AskingForNodeOwner', this);
		} else {
			Listeners.add(window, 'popupshowing', this);
		}
	},
	
	popupDeinit: function() {
		removeAttribute(this.button, 'showInMiniBar');
		
		popups.mini.delete('editBookmarkPanel');
		
		Listeners.remove(this.editPanel, 'AskingForNodeOwner', this);
		Listeners.remove(window, 'popupshowing', this);
	},
	
	update: function(initialize) {
		let starred = trueAttribute(this.broadcaster, 'starred');
		let tooltip = this.broadcaster.getAttribute('buttontooltiptext');
		
		let props = {
			state: starred ? 'starred' : 'unstarred',
			tooltip: tooltip,
			color: starred ? 'rgb(20,103,220)' : 'transparent'
		};
		
		if(initialize) {
			props.label = Strings.get('skyLights', 'bookmarkedItemLabel');
			props.description = Strings.get('skyLights', 'bookmarkedItemDescription');
			props.speed = 250;
			
			// adapted from BookmarkingUI.onCommand() - http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser-places.js#1630
			props.action = (e) => {
				// don't do anything if the star button isn't meant to do anything either
				let disabled = trueAttribute(this.broadcaster, 'stardisabled');
				if(disabled) { return; }
				
				// only left-clicks on the light should bookmark the page
				if(e.button != 0) { return; }
				
				let isBookmarked = BookmarkingUI._itemIds.length > 0;
				
				// Ignore clicks on the star if we are updating its state.
				if(!BookmarkingUI._pendingStmt) {
					if(isBookmarked) {
						this._anchor = bookmarkedItem.light;
					} else {
						// blink the light three times to show that the page was bookmarked
						skyLights.update('bookmarkedItem', { alert: 2 });
					}
					PlacesCommandHook.bookmarkCurrentPage(isBookmarked);
				}
			};
		}
		
		skyLights.update('bookmarkedItem', props);
	},
	
	remove: function() {
		skyLights.remove('bookmarkedItem');
	}
};
{'fraction_non_alphanumeric': 0.13687150837988826, 'fraction_numerical': 0.003964678320418093, 'mean_word_length': 3.9002207505518762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136668', 'n_tokens_mistral': 4143, 'n_tokens_neox': 3446, 'n_words': 792}