123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- var config;
- function Config(xhr) {
- function loadPreferences(xhr) {
- var parser = new DOMParser();
- var doc = parser.parseFromString(xhr.responseText, "application/xml");
- var preferences = doc.getElementsByTagName("preference");
- return Array.prototype.slice.call(preferences);
- }
- this.xhr = xhr;
- this.preferences = loadPreferences(this.xhr);
- }
- function readConfig(success, error) {
- var xhr;
- if(typeof config != 'undefined') {
- success(config);
- }
- function fail(msg) {
- console.error(msg);
- if(error) {
- error(msg);
- }
- }
- var xhrStatusChangeHandler = function() {
- if (xhr.readyState == 4) {
- if (xhr.status == 200 || xhr.status == 304 || xhr.status === 0 ) {
- config = new Config(xhr);
- success(config);
- }
- else {
- fail('[Browser][cordova.js][xhrStatusChangeHandler] Could not XHR config.xml: ' + xhr.statusText);
- }
- }
- };
- xhr = new XMLHttpRequest();
- xhr.addEventListener("load", xhrStatusChangeHandler);
- try {
- xhr.open("get", "config.xml", true);
- xhr.send();
- } catch(e) {
- fail('[Browser][cordova.js][readConfig] Could not XHR config.xml: ' + JSON.stringify(e));
- }
- }
- Config.prototype.getPreferenceValue = function getPreferenceValue(preferenceName) {
- var preferenceItem = this.preferences && this.preferences.filter(function(item) {
- return item.attributes.name && item.attributes.name.value === preferenceName;
- });
- if(preferenceItem && preferenceItem[0] && preferenceItem[0].attributes && preferenceItem[0].attributes.value) {
- return preferenceItem[0].attributes.value.value;
- }
- };
- exports.readConfig = readConfig;
|