BASIC_URL = './files/assets/basic-html/page-1.html'; BASIC_FIRST_PAGE = '1'; function renderBasic() { function getXHR() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } try { return new ActiveXObject('MSXML2.XMLHTTP.6.0'); } catch (e) { try { // The fallback. return new ActiveXObject('MSXML2.XMLHTTP.3.0'); } catch (e) { alert('This browser is not AJAX enabled.'); return null; } } } var ajax = function (options) { options = options || {}; var type = options.type || 'GET'; var url = options.url; var data = options.data; var xhr = getXHR(); try { xhr.open(type, url, true); xhr.onreadystatechange = function () { var error = false; var content = xhr.responseText; // Parse the JSON before calling success. if (options.dataType === 'json') { try { content = JSON.parse(content); } catch (e) { error = true; } } if (!error && (xhr.status >= 200 && xhr.status < 300)) { // The last two arguments only apply to v0.9.2. if (options.success) options.success(content, xhr.statusText, xhr); } else { // This signature is inconsistent with v0.9.2, but is correct for 1.0.0. if (options.error) options.error(xhr); } }; xhr.onerror = xhr.onabort = function () { if (options.error) options.error(xhr); }; xhr.send(data); } catch (error) { if (options.error) options.error(xhr); } return xhr; }; function getHash() { var match = window.location.href.match(/#(.*)$/); return match ? match[1] : ''; } var queryString = function () { // This function is anonymous, is executed immediately and // the return value is assigned to QueryString! var query_string = {}; var query = window.location.search.substring(1); if (query === "") return query_string; var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { if (vars[i] === "") continue; var pair = vars[i].split("="); // If first entry with this name if (typeof query_string[pair[0]] === "undefined") { query_string[pair[0]] = pair[1]; // If second entry with this name } else if (typeof query_string[pair[0]] === "string") { var arr = [query_string[pair[0]], pair[1]]; query_string[pair[0]] = arr; // If third or later entry with this name } else { query_string[pair[0]].push(pair[1]); } } return query_string; }(); var hash = getHash(); var checkRegExp = /[^A-Za-z0-9\(\)\[\]@.,$€;`~! _-]/g; var hash_split = hash.split("/"); var page = decodeURIComponent(queryString.p || queryString.page || hash_split[0] || window.BASIC_FIRST_PAGE); if (BASIC_URL) { var url = BASIC_URL; if (page != BASIC_FIRST_PAGE) { url = BASIC_URL.replace("page-" + BASIC_FIRST_PAGE, "page-" + page); } ajax({ type: 'OPTIONS', url: url, success: function (text, statusText, xhr) { window.location = url; }, error: function (xhr) { window.location = BASIC_URL; } }); } }