From 26440df33d1feeb8c7f392a573e742470d6f257a Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 3 Oct 2011 08:13:28 +0530 Subject: [PATCH] handle state in js, incorporate history.js, permanent urls work (almost). --- itf/app/models.py | 2 +- itf/insidepages/models.py | 2 +- itf/insidepages/urls.py | 2 +- itf/insidepages/views.py | 13 +- itf/settings.py | 8 ++ itf/static/js/history/amplify.store.js | 1 + .../js/history/history.adapter.jquery.js | 1 + itf/static/js/history/history.html4.js | 1 + itf/static/js/history/history.js | 1 + itf/static/js/history/json2.js | 1 + itf/static/js/insidepage.js | 117 +++++++++++++++--- itf/templates/noel/insidepage.html | 16 ++- requirements.txt | 2 + 13 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 itf/static/js/history/amplify.store.js create mode 100644 itf/static/js/history/history.adapter.jquery.js create mode 100644 itf/static/js/history/history.html4.js create mode 100644 itf/static/js/history/history.js create mode 100644 itf/static/js/history/json2.js diff --git a/itf/app/models.py b/itf/app/models.py index f7d6d04..7f90a15 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -56,7 +56,7 @@ class ItfModel(models.Model): return tab def get_absolute_url(self): - return "%s?tab_id=%d&object_id=%d" % (self.get_module().get_absolute_url(), self.get_tab().id, self.id) + return "%s/?tab=%s&object_id=%d" % (self.get_module().get_absolute_url(), self.get_tab().slug, self.id) def get_module(self): tab = self.get_tab() diff --git a/itf/insidepages/models.py b/itf/insidepages/models.py index 57fe9b5..a9d2290 100644 --- a/itf/insidepages/models.py +++ b/itf/insidepages/models.py @@ -34,7 +34,7 @@ class ModuleTab(models.Model): return self.model.model.model_class() def get_absolute_url(self): #FIXME!! - return self.slug + return "/m/%s/?tab=%s" % (self.module.slug, self.slug,) def get_list(self, options): return self.model_class().get_list(options) diff --git a/itf/insidepages/urls.py b/itf/insidepages/urls.py index e6e8344..58bfda1 100644 --- a/itf/insidepages/urls.py +++ b/itf/insidepages/urls.py @@ -5,5 +5,5 @@ urlpatterns = patterns('', (r'^get_list$', views.get_list), (r'^get_details$', views.get_details), (r'^get_tab$', views.get_tab), - (r'^(?P.*)$', views.main), + (r'^(?P.*)/$', views.main), ) diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py index 775f706..2095b40 100644 --- a/itf/insidepages/views.py +++ b/itf/insidepages/views.py @@ -19,15 +19,16 @@ def main(request, module_slug): }) return render_to_response("noel/insidepage.html", context) + def get_tab(request): - tab_id = request.GET.get("tab_id", 0) - tab = get_object_or_404(ModuleTab, pk=tab_id) + tab_slug = request.GET.get("tab", "") + tab = get_object_or_404(ModuleTab, slug=tab_slug) return render_to_json_response(tab.get_dict()) def get_list(request): - tab_id = request.GET.get("tab_id", 0) - tab = get_object_or_404(ModuleTab, pk=tab_id) + tab_slug = request.GET.get("tab", "") + tab = get_object_or_404(ModuleTab, slug=tab_slug) sortString = request.GET.get("sort", "") if sortString == "" or sortString == 'null': @@ -51,8 +52,8 @@ def get_list(request): def get_details(request): - tab_id = request.GET.get("tab_id", 0) - tab = get_object_or_404(ModuleTab, pk=tab_id) + tab_slug = request.GET.get("tab", '') + tab = get_object_or_404(ModuleTab, slug=tab_slug) model_class = tab.model_class() object_id = request.GET.get("object_id", 0) obj = get_object_or_404(model_class, pk=object_id) diff --git a/itf/settings.py b/itf/settings.py index eed81ec..59ac1aa 100644 --- a/itf/settings.py +++ b/itf/settings.py @@ -8,6 +8,8 @@ DEBUG = True TEMPLATE_DEBUG = DEBUG JSON_DEBUG = DEBUG + + LOCAL_DEVELOPMENT = True LOGGING_INTERCEPT_REDIRECTS = True LOGGING_LOG_SQL = True @@ -18,6 +20,11 @@ PROJECT_PATH = os.path.dirname(__file__) PROJECT_ROOT = PROJECT_PATH SITE_CONFIG = join(PROJECT_ROOT, 'itf.json') +HAYSTACK_SITECONF = 'itf.search_sites' +HAYSTACK_SEARCH_ENGINE = 'whoosh' +HAYSTACK_WHOOSH_PATH = join(PROJECT_PATH, "../whoosh/itf_index") + + CKEDITOR_MEDIA_PREFIX = "/static/ckeditor/" CKEDITOR_UPLOAD_PATH = join(PROJECT_PATH, "static/upload/images/") @@ -161,6 +168,7 @@ INSTALLED_APPS = ( 'user', 'ckeditor', 'fccv', + 'haystack', ) ACCOUNT_ACTIVATION_DAYS = 30 diff --git a/itf/static/js/history/amplify.store.js b/itf/static/js/history/amplify.store.js new file mode 100644 index 0000000..4ae9f2b --- /dev/null +++ b/itf/static/js/history/amplify.store.js @@ -0,0 +1 @@ +(function(a,b){function d(a,d){var e=d.__amplify__?JSON.parse(d.__amplify__):{};c.addType(a,function(f,g,h){var i=g,j=(new Date).getTime(),k,l;if(!f){i={};for(f in e)k=d[f],l=k?JSON.parse(k):{expires:-1},l.expires&&l.expires<=j?(delete d[f],delete e[f]):i[f.replace(/^__amplify__/,"")]=l.data;d.__amplify__=JSON.stringify(e);return i}f="__amplify__"+f;if(g===b){if(e[f]){k=d[f],l=k?JSON.parse(k):{expires:-1};if(l.expires&&l.expires<=j)delete d[f],delete e[f];else return l.data}}else if(g===null)delete d[f],delete e[f];else{l=JSON.stringify({data:g,expires:h.expires?j+h.expires:null});try{d[f]=l,e[f]=!0}catch(m){c[a]();try{d[f]=l,e[f]=!0}catch(m){throw c.error()}}}d.__amplify__=JSON.stringify(e);return i})}JSON.stringify=JSON.stringify||JSON.encode,JSON.parse=JSON.parse||JSON.decode;var c=a.store=function(a,b,d,e){var e=c.type;d&&d.type&&d.type in c.types&&(e=d.type);return c.types[e](a,b,d||{})};c.types={},c.type=null,c.addType=function(a,b){c.type||(c.type=a),c.types[a]=b,c[a]=function(b,d,e){e=e||{},e.type=a;return c(b,d,e)}},c.error=function(){return"amplify.store quota exceeded"};for(var e in{localStorage:1,sessionStorage:1})try{window[e].getItem&&d(e,window[e])}catch(f){}window.globalStorage&&(d("globalStorage",window.globalStorage[window.location.hostname]),c.type==="sessionStorage"&&(c.type="globalStorage")),function(){var a=document.createElement("div"),d="amplify",e;a.style.display="none",document.getElementsByTagName("head")[0].appendChild(a),a.addBehavior&&(a.addBehavior("#default#userdata"),a.load(d),e=a.getAttribute(d)?JSON.parse(a.getAttribute(d)):{},c.addType("userData",function(f,g,h){var i=g,j=(new Date).getTime(),k,l,m;if(!f){i={};for(f in e)k=a.getAttribute(f),l=k?JSON.parse(k):{expires:-1},l.expires&&l.expires<=j?(a.removeAttribute(f),delete e[f]):i[f]=l.data;a.setAttribute(d,JSON.stringify(e)),a.save(d);return i}f=f.replace(/[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g,"-");if(g===b){if(f in e){k=a.getAttribute(f),l=k?JSON.parse(k):{expires:-1};if(l.expires&&l.expires<=j)a.removeAttribute(f),delete e[f];else return l.data}}else g===null?(a.removeAttribute(f),delete e[f]):(m=a.getAttribute(f),l=JSON.stringify({data:g,expires:h.expires?j+h.expires:null}),a.setAttribute(f,l),e[f]=!0);a.setAttribute(d,JSON.stringify(e));try{a.save(d)}catch(n){m===null?(a.removeAttribute(f),delete e[f]):a.setAttribute(f,m),c.userData();try{a.setAttribute(f,l),e[f]=!0,a.save(d)}catch(n){m===null?(a.removeAttribute(f),delete e[f]):a.setAttribute(f,m);throw c.error()}}return i}))}(),d("memory",{})})(this.amplify=this.amplify||{}) \ No newline at end of file diff --git a/itf/static/js/history/history.adapter.jquery.js b/itf/static/js/history/history.adapter.jquery.js new file mode 100644 index 0000000..c72a99f --- /dev/null +++ b/itf/static/js/history/history.adapter.jquery.js @@ -0,0 +1 @@ +(function(a,b){var c=a.History=a.History||{},d=a.jQuery;if(typeof c.Adapter!="undefined")throw new Error("History.js Adapter has already been loaded...");c.Adapter={bind:function(a,b,c){d(a).bind(b,c)},trigger:function(a,b){d(a).trigger(b)},onDomLoad:function(a){d(a)}},typeof c.init!="undefined"&&c.init()})(window) \ No newline at end of file diff --git a/itf/static/js/history/history.html4.js b/itf/static/js/history/history.html4.js new file mode 100644 index 0000000..4a2662a --- /dev/null +++ b/itf/static/js/history/history.html4.js @@ -0,0 +1 @@ +(function(a,b){"use strict";var c=a.document,d=a.setTimeout||d,e=a.clearTimeout||e,f=a.setInterval||f,g=a.History=a.History||{};if(typeof g.initHtml4!="undefined")throw new Error("History.js HTML4 Support has already been loaded...");g.initHtml4=function(){if(typeof g.initHtml4.initialized!="undefined")return!1;g.initHtml4.initialized=!0,g.enabled=!0,g.savedHashes=[],g.isLastHash=function(a){var b=g.getHashByIndex(),c=a===b;return c},g.saveHash=function(a){if(g.isLastHash(a))return!1;g.savedHashes.push(a);return!0},g.getHashByIndex=function(a){var b=null;typeof a=="undefined"?b=g.savedHashes[g.savedHashes.length-1]:a<0?b=g.savedHashes[g.savedHashes.length+a]:b=g.savedHashes[a];return b},g.discardedHashes={},g.discardedStates={},g.discardState=function(a,b,c){var d=g.getHashByState(a),e={discardedState:a,backState:c,forwardState:b};g.discardedStates[d]=e;return!0},g.discardHash=function(a,b,c){var d={discardedHash:a,backState:c,forwardState:b};g.discardedHashes[a]=d;return!0},g.discardedState=function(a){var b=g.getHashByState(a),c=g.discardedStates[b]||!1;return c},g.discardedHash=function(a){var b=g.discardedHashes[a]||!1;return b},g.recycleState=function(a){var b=g.getHashByState(a);g.discardedState(a)&&delete g.discardedStates[b];return!0},g.emulated.hashChange&&(g.hashChangeInit=function(){g.checkerFunction=null;var b="";if(g.isInternetExplorer()){var d="historyjs-iframe",e=c.createElement("iframe");e.setAttribute("id",d),e.style.display="none",c.body.appendChild(e),e.contentWindow.document.open(),e.contentWindow.document.close();var h="",i=!1;g.checkerFunction=function(){if(i)return!1;i=!0;var c=g.getHash()||"",d=g.unescapeHash(e.contentWindow.document.location.hash)||"";c!==b?(b=c,d!==c&&(h=d=c,e.contentWindow.document.open(),e.contentWindow.document.close(),e.contentWindow.document.location.hash=g.escapeHash(c)),g.Adapter.trigger(a,"hashchange")):d!==h&&(h=d,g.setHash(d,!1)),i=!1;return!0}}else g.checkerFunction=function(){var c=g.getHash();c!==b&&(b=c,g.Adapter.trigger(a,"hashchange"));return!0};g.intervalList.push(f(g.checkerFunction,g.options.hashChangeInterval));return!0},g.Adapter.onDomLoad(g.hashChangeInit)),g.emulated.pushState&&(g.onHashChange=function(b){var d=b&&b.newURL||c.location.href,e=g.getHashByUrl(d),f=null,h=null,i=null;if(g.isLastHash(e)){g.busy(!1);return!1}g.doubleCheckComplete(),g.saveHash(e);if(e&&g.isTraditionalAnchor(e)){g.Adapter.trigger(a,"anchorchange"),g.busy(!1);return!1}f=g.extractState(g.getFullUrl(e||c.location.href,!1),!0);if(g.isLastSavedState(f)){g.busy(!1);return!1}h=g.getHashByState(f);var j=g.discardedState(f);if(j){g.getHashByIndex(-2)===g.getHashByState(j.forwardState)?g.back(!1):g.forward(!1);return!1}g.pushState(f.data,f.title,f.url,!1);return!0},g.Adapter.bind(a,"hashchange",g.onHashChange),g.pushState=function(b,d,e,f){if(g.getHashByUrl(e))throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(f!==!1&&g.busy()){g.pushQueue({scope:g,callback:g.pushState,args:arguments,queue:f});return!1}g.busy(!0);var h=g.createStateObject(b,d,e),i=g.getHashByState(h),j=g.getState(!1),k=g.getHashByState(j),l=g.getHash();g.storeState(h),g.expectedStateId=h.id,g.recycleState(h),g.setTitle(h);if(i===k){g.busy(!1);return!1}if(i!==l&&i!==g.getShortUrl(c.location.href)){g.setHash(i,!1);return!1}g.saveState(h),g.Adapter.trigger(a,"statechange"),g.busy(!1);return!0},g.replaceState=function(a,b,c,d){if(g.getHashByUrl(c))throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(d!==!1&&g.busy()){g.pushQueue({scope:g,callback:g.replaceState,args:arguments,queue:d});return!1}g.busy(!0);var e=g.createStateObject(a,b,c),f=g.getState(!1),h=g.getStateByIndex(-2);g.discardState(f,e,h),g.pushState(e.data,e.title,e.url,!1);return!0},g.getHash()&&!g.emulated.hashChange&&g.Adapter.onDomLoad(function(){g.Adapter.trigger(a,"hashchange")}))},g.init()})(window) \ No newline at end of file diff --git a/itf/static/js/history/history.js b/itf/static/js/history/history.js new file mode 100644 index 0000000..48c03c8 --- /dev/null +++ b/itf/static/js/history/history.js @@ -0,0 +1 @@ +(function(a,b){"use strict";var c=a.console||b,d=a.document,e=a.navigator,f=a.amplify||!1,g=a.setTimeout,h=a.clearTimeout,i=a.setInterval,j=a.clearInterval,k=a.JSON,l=a.History=a.History||{},m=a.history;k.stringify=k.stringify||k.encode,k.parse=k.parse||k.decode;if(typeof l.init!="undefined")throw new Error("History.js Core has already been loaded...");l.init=function(){if(typeof l.Adapter=="undefined")return!1;typeof l.initCore!="undefined"&&l.initCore(),typeof l.initHtml4!="undefined"&&l.initHtml4();return!0},l.initCore=function(){if(typeof l.initCore.initialized!="undefined")return!1;l.initCore.initialized=!0,l.options=l.options||{},l.options.hashChangeInterval=l.options.hashChangeInterval||100,l.options.safariPollInterval=l.options.safariPollInterval||500,l.options.doubleCheckInterval=l.options.doubleCheckInterval||500,l.options.storeInterval=l.options.storeInterval||1e3,l.options.busyDelay=l.options.busyDelay||250,l.options.debug=l.options.debug||!1,l.options.initialTitle=l.options.initialTitle||d.title,l.intervalList=[],l.clearAllIntervals=function(){var a,b=l.intervalList;if(typeof b!="undefined"&&b!==null){for(a=0;a")&&c[0]);return a>4?a:!1}();return a},l.isInternetExplorer=function(){var a=l.isInternetExplorer.cached=typeof l.isInternetExplorer.cached!="undefined"?l.isInternetExplorer.cached:Boolean(l.getInternetExplorerMajorVersion());return a},l.emulated={pushState:!Boolean(a.history&&a.history.pushState&&a.history.replaceState&&!/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(e.userAgent)&&!/AppleWebKit\/5([0-2]|3[0-2])/i.test(e.userAgent)),hashChange:Boolean(!("onhashchange"in a||"onhashchange"in d)||l.isInternetExplorer()&&l.getInternetExplorerMajorVersion()<8)},l.enabled=!l.emulated.pushState,l.bugs={setHash:Boolean(!l.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),safariPoll:Boolean(!l.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),ieDoubleCheck:Boolean(l.isInternetExplorer()&&l.getInternetExplorerMajorVersion()<8),hashEscape:Boolean(l.isInternetExplorer()&&l.getInternetExplorerMajorVersion()<7)},l.isEmptyObject=function(a){for(var b in a)return!1;return!0},l.cloneObject=function(a){var b,c;a?(b=k.stringify(a),c=k.parse(b)):c={};return c},l.getRootUrl=function(){var a=d.location.protocol+"//"+(d.location.hostname||d.location.host);if(d.location.port||!1)a+=":"+d.location.port;a+="/";return a},l.getBaseHref=function(){var a=d.getElementsByTagName("base"),b=null,c="";a.length===1&&(b=a[0],c=b.href.replace(/[^\/]+$/,"")),c=c.replace(/\/+$/,""),c&&(c+="/");return c},l.getBaseUrl=function(){var a=l.getBaseHref()||l.getBasePageUrl()||l.getRootUrl();return a},l.getPageUrl=function(){var a=l.getState(!1,!1),b=(a||{}).url||d.location.href,c=b.replace(/\/+$/,"").replace(/[^\/]+$/,function(a,b,c){return/\./.test(a)?a:a+"/"});return c},l.getBasePageUrl=function(){var a=d.location.href.replace(/[#\?].*/,"").replace(/[^\/]+$/,function(a,b,c){return/[^\/]$/.test(a)?"":a}).replace(/\/+$/,"")+"/";return a},l.getFullUrl=function(a,b){var c=a,d=a.substring(0,1);b=typeof b=="undefined"?!0:b,/[a-z]+\:\/\//.test(a)||(d==="/"?c=l.getRootUrl()+a.replace(/^\/+/,""):d==="#"?c=l.getPageUrl().replace(/#.*/,"")+a:d==="?"?c=l.getPageUrl().replace(/[\?#].*/,"")+a:b?c=l.getBaseUrl()+a.replace(/^(\.\/)+/,""):c=l.getBasePageUrl()+a.replace(/^(\.\/)+/,""));return c.replace(/\#$/,"")},l.getShortUrl=function(a){var b=a,c=l.getBaseUrl(),d=l.getRootUrl();l.emulated.pushState&&(b=b.replace(c,"")),b=b.replace(d,"/"),l.isTraditionalAnchor(b)&&(b="./"+b),b=b.replace(/^(\.\/)+/g,"./").replace(/\#$/,"");return b},l.store=f?f.store("History.store")||{}:{},l.store.idToState=l.store.idToState||{},l.store.urlToId=l.store.urlToId||{},l.store.stateToId=l.store.stateToId||{},l.idToState=l.idToState||{},l.stateToId=l.stateToId||{},l.urlToId=l.urlToId||{},l.storedStates=l.storedStates||[],l.savedStates=l.savedStates||[],l.getState=function(a,b){typeof a=="undefined"&&(a=!0),typeof b=="undefined"&&(b=!0);var c=l.getLastSavedState();!c&&b&&(c=l.createStateObject()),a&&(c=l.cloneObject(c),c.url=c.cleanUrl||c.url);return c},l.getIdByState=function(a){var b=l.extractId(a.url);if(!b){var c=l.getStateString(a);if(typeof l.stateToId[c]!="undefined")b=l.stateToId[c];else if(typeof l.store.stateToId[c]!="undefined")b=l.store.stateToId[c];else{for(;;){b=String(Math.floor(Math.random()*1e3));if(typeof l.idToState[b]=="undefined"&&typeof l.store.idToState[b]=="undefined")break}l.stateToId[c]=b,l.idToState[b]=a}}return b},l.normalizeState=function(a){if(!a||typeof a!="object")a={};if(typeof a.normalized!="undefined")return a;if(!a.data||typeof a.data!="object")a.data={};var b={};b.normalized=!0,b.title=a.title||"",b.url=l.getFullUrl(l.unescapeString(a.url||d.location.href)),b.hash=l.getShortUrl(b.url),b.data=l.cloneObject(a.data),b.id=l.getIdByState(b),b.cleanUrl=b.url.replace(/\??\&_suid.*/,""),b.url=b.cleanUrl;var c=!l.isEmptyObject(b.data);if(b.title||c)b.hash=l.getShortUrl(b.url).replace(/\??\&_suid.*/,""),/\?/.test(b.hash)||(b.hash+="?"),b.hash+="&_suid="+b.id;b.hashedUrl=l.getFullUrl(b.hash),(l.emulated.pushState||l.bugs.safariPoll)&&l.hasUrlDuplicate(b)&&(b.url=b.hashedUrl);return b},l.createStateObject=function(a,b,c){var d={data:a,title:b,url:c};d=l.normalizeState(d);return d},l.getStateById=function(a){a=String(a);var c=l.idToState[a]||l.store.idToState[a]||b;return c},l.getStateString=function(a){var b=l.normalizeState(a),c={data:b.data,title:a.title,url:a.url},d=k.stringify(c);return d},l.getStateId=function(a){var b=l.normalizeState(a),c=b.id;return c},l.getHashByState=function(a){var b,c=l.normalizeState(a);b=c.hash;return b},l.extractId=function(a){var b,c,d;c=/(.*)\&_suid=([0-9]+)$/.exec(a),d=c?c[1]||a:a,b=c?String(c[2]||""):"";return b||!1},l.isTraditionalAnchor=function(a){var b=!/[\/\?\.]/.test(a);return b},l.extractState=function(a,b){var c=null;b=b||!1;var d=l.extractId(a);d&&(c=l.getStateById(d));if(!c){var e=l.getFullUrl(a);d=l.getIdByUrl(e)||!1,d&&(c=l.getStateById(d)),!c&&b&&!l.isTraditionalAnchor(a)&&(c=l.createStateObject(null,null,e))}return c},l.getIdByUrl=function(a){var c=l.urlToId[a]||l.store.urlToId[a]||b;return c},l.getLastSavedState=function(){return l.savedStates[l.savedStates.length-1]||b},l.getLastStoredState=function(){return l.storedStates[l.storedStates.length-1]||b},l.hasUrlDuplicate=function(a){var b=!1,c=l.extractState(a.url);b=c&&c.id!==a.id;return b},l.storeState=function(a){l.urlToId[a.url]=a.id,l.storedStates.push(l.cloneObject(a));return a},l.isLastSavedState=function(a){var b=!1;if(l.savedStates.length){var c=a.id,d=l.getLastSavedState(),e=d.id;b=c===e}return b},l.saveState=function(a){if(l.isLastSavedState(a))return!1;l.savedStates.push(l.cloneObject(a));return!0},l.getStateByIndex=function(a){var b=null;typeof a=="undefined"?b=l.savedStates[l.savedStates.length-1]:a<0?b=l.savedStates[l.savedStates.length+a]:b=l.savedStates[a];return b},l.getHash=function(){var a=l.unescapeHash(d.location.hash);return a},l.unescapeString=function(b){var c=b,d;for(;;){d=a.unescape(c);if(d===c)break;c=d}return c},l.unescapeHash=function(a){var b=l.normalizeHash(a);b=l.unescapeString(b);return b},l.normalizeHash=function(a){var b=a.replace(/[^#]*#/,"").replace(/#.*/,"");return b},l.setHash=function(a,b){if(b!==!1&&l.busy()){l.pushQueue({scope:l,callback:l.setHash,args:arguments,queue:b});return!1}var c=l.escapeHash(a);l.busy(!0);var e=l.extractState(a,!0);if(e&&!l.emulated.pushState)l.pushState(e.data,e.title,e.url,!1);else if(d.location.hash!==c)if(l.bugs.setHash){var f=l.getPageUrl();l.pushState(null,null,f+"#"+c,!1)}else d.location.hash=c;return l},l.escapeHash=function(b){var c=l.normalizeHash(b);c=a.escape(c),l.bugs.hashEscape||(c=c.replace(/\%21/g,"!").replace(/\%26/g,"&").replace(/\%3D/g,"=").replace(/\%3F/g,"?"));return c},l.getHashByUrl=function(a){var b=String(a).replace(/([^#]*)#?([^#]*)#?(.*)/,"$2");b=l.unescapeHash(b);return b},l.setTitle=function(a){var b=a.title;if(!b){var c=l.getStateByIndex(0);c&&c.url===a.url&&(b=c.title||l.options.initialTitle)}try{d.getElementsByTagName("title")[0].innerHTML=b.replace("<","<").replace(">",">").replace(" & "," & ")}catch(e){}d.title=b;return l},l.queues=[],l.busy=function(a){typeof a!="undefined"?l.busy.flag=a:typeof l.busy.flag=="undefined"&&(l.busy.flag=!1);if(!l.busy.flag){h(l.busy.timeout);var b=function(){if(!l.busy.flag)for(var a=l.queues.length-1;a>=0;--a){var c=l.queues[a];if(c.length===0)continue;var d=c.shift();l.fireQueueItem(d),l.busy.timeout=g(b,l.options.busyDelay)}};l.busy.timeout=g(b,l.options.busyDelay)}return l.busy.flag},l.fireQueueItem=function(a){return a.callback.apply(a.scope||l,a.args||[])},l.pushQueue=function(a){l.queues[a.queue||0]=l.queues[a.queue||0]||[],l.queues[a.queue||0].push(a);return l},l.queue=function(a,b){typeof a=="function"&&(a={callback:a}),typeof b!="undefined"&&(a.queue=b),l.busy()?l.pushQueue(a):l.fireQueueItem(a);return l},l.clearQueue=function(){l.busy.flag=!1,l.queues=[];return l},l.stateChanged=!1,l.doubleChecker=!1,l.doubleCheckComplete=function(){l.stateChanged=!0,l.doubleCheckClear();return l},l.doubleCheckClear=function(){l.doubleChecker&&(h(l.doubleChecker),l.doubleChecker=!1);return l},l.doubleCheck=function(a){l.stateChanged=!1,l.doubleCheckClear(),l.bugs.ieDoubleCheck&&(l.doubleChecker=g(function(){l.doubleCheckClear(),l.stateChanged||a();return!0},l.options.doubleCheckInterval));return l},l.safariStatePoll=function(){var b=l.extractState(d.location.href),c;if(!l.isLastSavedState(b))c=b;else return;c||(c=l.createStateObject()),l.Adapter.trigger(a,"popstate");return l},l.back=function(a){if(a!==!1&&l.busy()){l.pushQueue({scope:l,callback:l.back,args:arguments,queue:a});return!1}l.busy(!0),l.doubleCheck(function(){l.back(!1)}),m.go(-1);return!0},l.forward=function(a){if(a!==!1&&l.busy()){l.pushQueue({scope:l,callback:l.forward,args:arguments,queue:a});return!1}l.busy(!0),l.doubleCheck(function(){l.forward(!1)}),m.go(1);return!0},l.go=function(a,b){var c;if(a>0)for(c=1;c<=a;++c)l.forward(b);else{if(!(a<0))throw new Error("History.go: History.go requires a positive or negative integer passed.");for(c=-1;c>=a;--c)l.back(b)}return l},l.saveState(l.storeState(l.extractState(d.location.href,!0))),f&&(l.onUnload=function(){var a=f.store("History.store")||{},b;a.idToState=a.idToState||{},a.urlToId=a.urlToId||{},a.stateToId=a.stateToId||{};for(b in l.idToState){if(!l.idToState.hasOwnProperty(b))continue;a.idToState[b]=l.idToState[b]}for(b in l.urlToId){if(!l.urlToId.hasOwnProperty(b))continue;a.urlToId[b]=l.urlToId[b]}for(b in l.stateToId){if(!l.stateToId.hasOwnProperty(b))continue;a.stateToId[b]=l.stateToId[b]}l.store=a,f.store("History.store",a)},l.intervalList.push(i(l.onUnload,l.options.storeInterval)),l.Adapter.bind(a,"beforeunload",l.onUnload),l.Adapter.bind(a,"unload",l.onUnload));if(l.emulated.pushState){var n=function(){};l.pushState=l.pushState||n,l.replaceState=l.replaceState||n}else{l.onPopState=function(b){l.doubleCheckComplete();var c=l.getHash();if(c){var e=l.extractState(c||d.location.href,!0);e?l.replaceState(e.data,e.title,e.url,!1):(l.Adapter.trigger(a,"anchorchange"),l.busy(!1)),l.expectedStateId=!1;return!1}var f=!1;b=b||{},typeof b.state=="undefined"&&(typeof b.originalEvent!="undefined"&&typeof b.originalEvent.state!="undefined"?b.state=b.originalEvent.state||!1:typeof b.event!="undefined"&&typeof b.event.state!="undefined"&&(b.state=b.event.state||!1)),b.state=b.state||!1,b.state?f=l.getStateById(b.state):l.expectedStateId?f=l.getStateById(l.expectedStateId):f=l.extractState(d.location.href),f||(f=l.createStateObject(null,null,d.location.href)),l.expectedStateId=!1;if(l.isLastSavedState(f)){l.busy(!1);return!1}l.storeState(f),l.saveState(f),l.setTitle(f),l.Adapter.trigger(a,"statechange"),l.busy(!1);return!0},l.Adapter.bind(a,"popstate",l.onPopState),l.pushState=function(b,c,d,e){if(l.getHashByUrl(d)&&l.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&l.busy()){l.pushQueue({scope:l,callback:l.pushState,args:arguments,queue:e});return!1}l.busy(!0);var f=l.createStateObject(b,c,d);l.isLastSavedState(f)?l.busy(!1):(l.storeState(f),l.expectedStateId=f.id,m.pushState(f.id,f.title,f.url),l.Adapter.trigger(a,"popstate"));return!0},l.replaceState=function(b,c,d,e){if(l.getHashByUrl(d)&&l.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&l.busy()){l.pushQueue({scope:l,callback:l.replaceState,args:arguments,queue:e});return!1}l.busy(!0);var f=l.createStateObject(b,c,d);l.isLastSavedState(f)?l.busy(!1):(l.storeState(f),l.expectedStateId=f.id,m.replaceState(f.id,f.title,f.url),l.Adapter.trigger(a,"popstate"));return!0},l.bugs.safariPoll&&l.intervalList.push(i(l.safariStatePoll,l.options.safariPollInterval));if(e.vendor==="Apple Computer, Inc."||(e.appCodeName||"")==="Mozilla")l.Adapter.bind(a,"hashchange",function(){l.Adapter.trigger(a,"popstate")}),l.getHash()&&l.Adapter.onDomLoad(function(){l.Adapter.trigger(a,"hashchange")})}},l.init()})(window) \ No newline at end of file diff --git a/itf/static/js/history/json2.js b/itf/static/js/history/json2.js new file mode 100644 index 0000000..704b881 --- /dev/null +++ b/itf/static/js/history/json2.js @@ -0,0 +1 @@ +var JSON;JSON||(JSON={}),function(){function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c>>var foo = {'var1': 'bar', 'var2': 'baz'} +>>> JSONtoQueryString(foo); +'?var1=bar&var2=baz' +*/ +function JSONtoQueryString(obj) { + var s = "?"; + for (var o in obj) { + if (obj.hasOwnProperty(o)) { + s += o + "=" + obj[o] + "&"; + } + } + return s.substring(0, s.length - 1); +} + +/* +>>>var foo = "/something/bla/?var1=bar&var2=baz"; +>>>QueryStringToJSON(foo); +{'var1': 'bar', 'var2': 'baz'} +*/ +function QueryStringToJSON(qstring) { + var qstring = qstring.split("?")[1]; + var args = {}; + var vars = qstring.split('&'); +// console.log(vars); + for (var i=0; i + + + + + {% endblock %} @@ -43,9 +48,9 @@
  • FAQs
  • Guidelines
  • --> -
  • {{ default_tab.title }}
  • +
  • {{ default_tab.title }}
  • {% for t in tabs %} -
  • {{ t.title }}
  • +
  • {{ t.title }}
  • {% endfor %} @@ -71,8 +76,9 @@ --> + - + search-icon @@ -84,9 +90,11 @@
    • Loading...
    • +
    diff --git a/requirements.txt b/requirements.txt index 53290f0..a79bc4d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,5 @@ django-debug-toolbar South django-ckeditor fccv #for comment-spam protection +Whoosh +django-haystack