adding search to hash (page link)

This commit is contained in:
2016-08-19 21:40:51 +02:00
parent 01e0cac9ea
commit 3775fb372f
2 changed files with 36 additions and 4 deletions

3
.gitignore vendored Normal file → Executable file
View File

@@ -3,4 +3,5 @@
/.settings/ /.settings/
/build.xml /build.xml
/.externalToolBuilders/ /.externalToolBuilders/
/.sass-cache/ /.sass-cache/
/tmp/

View File

@@ -203,6 +203,7 @@ function Ugc()
this.settings = new Settings(); this.settings = new Settings();
this._films = {}; this._films = {};
this._wip = 0; this._wip = 0;
this.hash_sep = '-';
this.$Header = $('header'); this.$Header = $('header');
this.$Nav = $('nav'); this.$Nav = $('nav');
@@ -289,10 +290,13 @@ function Ugc()
this.initSearch = function() this.initSearch = function()
{ {
$("#search") var $SearchInput = $("#search");
$SearchInput
.attr('placeholder', 'Search...') .attr('placeholder', 'Search...')
.on("change paste keyup", function() { .on("change paste keyup", function(){
if($(this).val()=='') $('.film').not('.banned').show(); var sValue = $(this).val();
self.hash('search', sValue);
if(sValue=='') $('.film').not('.banned').show();
}) })
.autocomplete( .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) this.addCinema = function(iCinemaId, hDom)