diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 149904c..4823e29 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /.settings/ /build.xml /.externalToolBuilders/ -/.sass-cache/ \ No newline at end of file +/.sass-cache/ +/tmp/ diff --git a/script/ugc.js b/script/ugc.js index a0273a9..ab56fa4 100755 --- a/script/ugc.js +++ b/script/ugc.js @@ -203,6 +203,7 @@ function Ugc() this.settings = new Settings(); this._films = {}; this._wip = 0; + this.hash_sep = '-'; this.$Header = $('header'); this.$Nav = $('nav'); @@ -289,10 +290,13 @@ function Ugc() this.initSearch = function() { - $("#search") + var $SearchInput = $("#search"); + $SearchInput .attr('placeholder', 'Search...') - .on("change paste keyup", function() { - if($(this).val()=='') $('.film').not('.banned').show(); + .on("change paste keyup", function(){ + var sValue = $(this).val(); + self.hash('search', sValue); + if(sValue=='') $('.film').not('.banned').show(); }) .autocomplete( { @@ -319,6 +323,33 @@ function Ugc() }); } }); + + var asHash = self.hash(); + var sDefaultSearch = asHash.items[0] || ''; + if(asHash.page=='search' && sDefaultSearch!='') + { + $SearchInput.val(sDefaultSearch).autocomplete("search", sDefaultSearch); + } + }; + + this.hash = function(sPage, asItems) + { + sPage = sPage || ''; + asItems = asItems || []; + if(sPage=='') + { + var sHash = decodeURIComponent(window.location.hash.slice(1)); + var asHash = sHash.split(self.hash_sep); + sPage = asHash.shift() || ''; + return {hash:sHash, page:sPage, items:asHash}; + } + else + { + if(typeof asItems == 'string') asItems = [asItems]; + var sItems = (asItems.length > 0)?self.hash_sep+asItems.join(self.hash_sep):''; + if(sItems=='') sPage = ''; + window.location.hash = '#'+encodeURIComponent(sPage+sItems); + } }; this.addCinema = function(iCinemaId, hDom)