MCPcopy Index your code
hub / github.com/devote/HTML5-History-API / initialize

Function initialize

history.js:1004–1106  ·  view source on GitHub ↗

* Library initialization * * @return {Boolean} return true if all is well, otherwise return false value

()

Source from the content-addressed store, hash-verified

1002 * @return {Boolean} return true if all is well, otherwise return false value
1003 */
1004 function initialize() {
1005 /**
1006 * Get custom settings from the query string
1007 */
1008 var scripts = document.getElementsByTagName('script');
1009 var src = (scripts[scripts.length - 1] || {}).src || '';
1010 var arg = src.indexOf('?') !== -1 ? src.split('?').pop() : '';
1011 arg.replace(/(\w+)(?:=([^&]*))?/g, function(a, key, value) {
1012 settings[key] = (value || '').replace(/^(0|false)$/, '');
1013 });
1014
1015 /**
1016 * hang up the event handler to listen to the events hashchange
1017 */
1018 addEvent(eventNamePrefix + 'hashchange', onHashChange, false);
1019
1020 // a list of objects with pairs of descriptors/object
1021 var data = [locationDescriptors, locationObject, eventsDescriptors, global, historyDescriptors, historyObject];
1022
1023 // if browser support object 'state' in interface 'History'
1024 if (isSupportStateObjectInHistory) {
1025 // remove state property from descriptor
1026 delete historyDescriptors['state'];
1027 }
1028
1029 // initializing descriptors
1030 for(var i = 0; i < data.length; i += 2) {
1031 for(var prop in data[i]) {
1032 if (data[i].hasOwnProperty(prop)) {
1033 if (typeof data[i][prop] !== 'object') {
1034 // If the descriptor is a simple function, simply just assign it an object
1035 data[i + 1][prop] = data[i][prop];
1036 } else {
1037 // prepare the descriptor the required format
1038 var descriptor = prepareDescriptorsForObject(data[i], prop, data[i][prop]);
1039 // try to set the descriptor object
1040 if (!redefineProperty(data[i + 1], prop, descriptor, function(n, o) {
1041 // is satisfied if the failed override property
1042 if (o === historyObject) {
1043 // the problem occurs in Safari on the Mac
1044 global.history = historyObject = data[i + 1] = n;
1045 }
1046 })) {
1047 // if there is no possibility override.
1048 // This browser does not support descriptors, such as IE7
1049
1050 // remove previously hung event handlers
1051 removeEvent(eventNamePrefix + 'hashchange', onHashChange, false);
1052
1053 // fail to initialize :(
1054 return false;
1055 }
1056
1057 // create a repository for custom handlers onpopstate/onhashchange
1058 if (data[i + 1] === global) {
1059 eventsList[prop] = eventsList[prop.substr(2)] = [];
1060 }
1061 }

Callers 1

history.jsFile · 0.70

Calls 5

redefinePropertyFunction · 0.70
storageInitializeFunction · 0.70
onLoadFunction · 0.70
parseURLFunction · 0.70

Tested by

no test coverage detected