update library
This commit is contained in:
parent
fda2d6e4cc
commit
caa7bfce9b
@ -1,7 +1,45 @@
|
|||||||
/**
|
/**
|
||||||
* @fileOverview Tab Related Confirimation Library for Firefox 3.5 or later
|
* @fileOverview Tab Related Confirimation Library for Firefox 3.5 or later
|
||||||
* @author SHIMODA "Piro" Hiroshi
|
* @author SHIMODA "Piro" Hiroshi
|
||||||
* @version 3
|
* @version 4
|
||||||
|
* Basic usage:
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Components.utils.import('resource://my-modules/confirmWithTab.js');
|
||||||
|
*
|
||||||
|
* var checkbox = {
|
||||||
|
* label : 'Never ask me',
|
||||||
|
* checked : false
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* confirmWithTab({
|
||||||
|
* tab : gBrowser.selectedTab, // the related tab
|
||||||
|
* label : 'Ara you ready?', // the message
|
||||||
|
* value : 'treestyletab-undo-close-tree', // the internal key (optional)
|
||||||
|
* buttons : ['Yes', 'No'], // button labels
|
||||||
|
* checkbox : checkbox, // checkbox definition (optional)
|
||||||
|
* cancelEvents : ['SSTabRestoring'] // events to cancel this deferred (optional)
|
||||||
|
* })
|
||||||
|
* .next(function(aButtonIndex) {
|
||||||
|
* // the next callback receives the index of the clicked button.
|
||||||
|
* switch (aButtonIndex) {
|
||||||
|
* case 0: // Yes
|
||||||
|
* ...
|
||||||
|
* break;
|
||||||
|
* case 1: // No
|
||||||
|
* ...
|
||||||
|
* break;
|
||||||
|
* }
|
||||||
|
* // after the notification bar is closed, "checked" indicates
|
||||||
|
* // the state of the checkbox when the user clicks a button.
|
||||||
|
* var checked = checkbox.checked;
|
||||||
|
* ...
|
||||||
|
* })
|
||||||
|
* .error(function(aError) {
|
||||||
|
* // if the tab is closed, or any event in the cancelEvents array
|
||||||
|
* // is fired, then an exception is raised.
|
||||||
|
* ...
|
||||||
|
* });
|
||||||
*
|
*
|
||||||
* @license
|
* @license
|
||||||
* The MIT License, Copyright (c) 2010-2011 SHIMODA "Piro" Hiroshi
|
* The MIT License, Copyright (c) 2010-2011 SHIMODA "Piro" Hiroshi
|
||||||
@ -34,7 +72,7 @@ if (typeof namespace.Deferred == 'undefined')
|
|||||||
|
|
||||||
var confirmWithTab;
|
var confirmWithTab;
|
||||||
(function() {
|
(function() {
|
||||||
const currentRevision = 3;
|
const currentRevision = 4;
|
||||||
|
|
||||||
var loadedRevision = 'confirmWithTab' in namespace ?
|
var loadedRevision = 'confirmWithTab' in namespace ?
|
||||||
namespace.confirmWithTab.revision :
|
namespace.confirmWithTab.revision :
|
||||||
@ -49,6 +87,19 @@ var confirmWithTab;
|
|||||||
confirmWithTab = function confirmWithTab(aOptions)
|
confirmWithTab = function confirmWithTab(aOptions)
|
||||||
{
|
{
|
||||||
var deferred = new namespace.Deferred();
|
var deferred = new namespace.Deferred();
|
||||||
|
if (!aOptions.buttons) {
|
||||||
|
return deferred
|
||||||
|
.next(function() {
|
||||||
|
throw new Error('confirmWithTab requires one or more buttons!');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
aOptions.cancelEvents = (aOptions.cancelEvents || [])
|
||||||
|
.concat(['TabClose'])
|
||||||
|
.sort()
|
||||||
|
.join('\n')
|
||||||
|
.replace(/^(.+)$\n(\1\n)+/gm, '$1\n')
|
||||||
|
.split('\n');
|
||||||
|
|
||||||
var tab = aOptions.tab;
|
var tab = aOptions.tab;
|
||||||
var b = getTabBrowserFromChild(tab);
|
var b = getTabBrowserFromChild(tab);
|
||||||
@ -57,8 +108,8 @@ var confirmWithTab;
|
|||||||
var numericAccessKey = 0;
|
var numericAccessKey = 0;
|
||||||
var notification = box.appendNotification(
|
var notification = box.appendNotification(
|
||||||
aOptions.label,
|
aOptions.label,
|
||||||
aOptions.value,
|
aOptions.value || 'confirmWithTab-'+encodeURIComponent(aOptions.label),
|
||||||
aOptions.image,
|
aOptions.image || null,
|
||||||
(aOptions.priority ?
|
(aOptions.priority ?
|
||||||
(typeof aOptions.priority == 'number' ? aOptions.priority : box[aOptions.priority] ) :
|
(typeof aOptions.priority == 'number' ? aOptions.priority : box[aOptions.priority] ) :
|
||||||
box.PRIORITY_INFO_MEDIUM
|
box.PRIORITY_INFO_MEDIUM
|
||||||
@ -124,7 +175,7 @@ var confirmWithTab;
|
|||||||
|
|
||||||
var strip = b.tabContainer || b.mTabContainer;
|
var strip = b.tabContainer || b.mTabContainer;
|
||||||
var handleEvent = function handleEvent(aEvent) {
|
var handleEvent = function handleEvent(aEvent) {
|
||||||
if (aEvent.type == 'DOMNodeRemoved' && !aEvent.target != notification)
|
if (aEvent.type == 'DOMNodeRemoved' && aEvent.target != notification)
|
||||||
return;
|
return;
|
||||||
if (aOptions.cancelEvents)
|
if (aOptions.cancelEvents)
|
||||||
aOptions.cancelEvents.forEach(function(aEventType) {
|
aOptions.cancelEvents.forEach(function(aEventType) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user