|
|
@ -33,6 +33,8 @@ |
|
|
|
|
|
|
|
;(function(root) { |
|
|
|
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
/******************************************************************************/ |
|
|
|
|
|
|
|
var exceptions = {}; |
|
|
@ -45,6 +47,8 @@ var selfieMagic = 'iscjsfsaolnm'; |
|
|
|
var cutoffLength = 256; |
|
|
|
var mustPunycode = /[^a-z0-9.-]/; |
|
|
|
|
|
|
|
var onChangedListeners = []; |
|
|
|
|
|
|
|
/******************************************************************************/ |
|
|
|
|
|
|
|
// In the context of this code, a domain is defined as:
|
|
|
@ -234,6 +238,8 @@ function parse(text, toAscii) { |
|
|
|
} |
|
|
|
crystallize(exceptions); |
|
|
|
crystallize(rules); |
|
|
|
|
|
|
|
callListeners(onChangedListeners); |
|
|
|
} |
|
|
|
|
|
|
|
/******************************************************************************/ |
|
|
@ -302,11 +308,47 @@ function fromSelfie(selfie) { |
|
|
|
} |
|
|
|
rules = selfie.rules; |
|
|
|
exceptions = selfie.exceptions; |
|
|
|
callListeners(onChangedListeners); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/******************************************************************************/ |
|
|
|
|
|
|
|
var addListener = function(listeners, callback) { |
|
|
|
if ( typeof callback !== 'function' ) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if ( listeners.indexOf(callback) === -1 ) { |
|
|
|
listeners.push(callback); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
var removeListener = function(listeners, callback) { |
|
|
|
var pos = listeners.indexOf(callback); |
|
|
|
if ( pos !== -1 ) { |
|
|
|
listeners.splice(pos, 1); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
var callListeners = function(listeners) { |
|
|
|
for ( var i = 0; i < listeners.length; i++ ) { |
|
|
|
listeners[i](); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/******************************************************************************/ |
|
|
|
|
|
|
|
var onChanged = { |
|
|
|
addListener: function(callback) { |
|
|
|
addListener(onChangedListeners, callback); |
|
|
|
}, |
|
|
|
removeListener: function(callback) { |
|
|
|
removeListener(onChangedListeners, callback); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/******************************************************************************/ |
|
|
|
|
|
|
|
// Public API
|
|
|
|
|
|
|
|
root = root || window; |
|
|
@ -317,7 +359,8 @@ root.publicSuffixList = { |
|
|
|
'getDomain': getDomain, |
|
|
|
'getPublicSuffix': getPublicSuffix, |
|
|
|
'toSelfie': toSelfie, |
|
|
|
'fromSelfie': fromSelfie |
|
|
|
'fromSelfie': fromSelfie, |
|
|
|
'onChanged': onChanged |
|
|
|
}; |
|
|
|
|
|
|
|
/******************************************************************************/ |
|
|
|