update querystring while you search
This commit is contained in:
1 parent
6837bd13fb
commit
e048ba937d
5 files changed
+76
-14
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/*global moment, jQuery, document, _, $ */
|
/*global moment, jQuery, document, _, $, window */
|
||||||
var program_endpoint = 'https://studentersamfundet.no/api/events/get_today/';
|
var program_endpoint = 'https://studentersamfundet.no/api/events/get_today/';
|
||||||
var inside_url = 'https://inside.studentersamfundet.no';
|
var inside_url = 'https://inside.studentersamfundet.no';
|
||||||
var inside_groups_url = inside_url + '/api/groups.php';
|
var inside_groups_url = inside_url + '/api/groups.php';
|
||||||
@@ -11,6 +11,13 @@ var query_params = {
|
|||||||
//count: 10
|
//count: 10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getParameterByName(name) {
|
||||||
|
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
||||||
|
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'),
|
||||||
|
results = regex.exec(location.search);
|
||||||
|
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||||
|
}
|
||||||
|
|
||||||
function format_posts(posts) {
|
function format_posts(posts) {
|
||||||
var html = '';
|
var html = '';
|
||||||
var i=0;
|
var i=0;
|
||||||
@@ -32,7 +39,7 @@ function format_posts(posts) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
function format_results(data) {
|
function format_results(data) {
|
||||||
var header_template = '<table><thead><tr><th>Navn</th><th>Brukernavn</th><th>Epost</th><th>Telefon</th><th>Medlem</th><th>Grupper</th></tr></thead>';
|
var header_template = '<table><thead><tr><th>Navn</th><th>Brukernavn</th><th>Epost</th><th>Telefon</th><th>Har medlemskap</th><th>Grupper</th></tr></thead>';
|
||||||
if(data.error) {
|
if(data.error) {
|
||||||
console.log(data.error);
|
console.log(data.error);
|
||||||
$('.search-result-list').html('');
|
$('.search-result-list').html('');
|
||||||
@@ -55,26 +62,71 @@ function format_results(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function do_search() {
|
function do_search() {
|
||||||
// TODO: add params from toggle
|
|
||||||
var validMembershipToggle = $('.filters [data-search-filter="has_valid_membership"]');
|
var validMembershipToggle = $('.filters [data-search-filter="has_valid_membership"]');
|
||||||
var groupString = '';
|
var groupString = '';
|
||||||
var groupSelect = $('.groups-select').val();
|
var groupSelect = $('.groups-select').val();
|
||||||
if( groupSelect !== null) {
|
if( groupSelect !== null) {
|
||||||
groupString = groupSelect.join();
|
groupString = groupSelect.join();
|
||||||
}
|
}
|
||||||
|
var params = {
|
||||||
|
q: $('.search-field').val(),
|
||||||
|
filter_groups: groupString,
|
||||||
|
has_valid_membership: validMembershipToggle.hasClass('active').toString()
|
||||||
|
};
|
||||||
|
var querystring = $.param(params);
|
||||||
|
window.History.pushState(null, null, '?'+querystring);
|
||||||
|
|
||||||
|
params._wpnonce = $('meta[name=x-inside-api-nonce]').attr('content');
|
||||||
$.getJSON(
|
$.getJSON(
|
||||||
user_search_endpoint,
|
user_search_endpoint,
|
||||||
{
|
params,
|
||||||
q: $('.search-field').val(),
|
|
||||||
filter_groups: groupString,
|
|
||||||
_wpnonce: $('meta[name=x-inside-api-nonce]').attr('content'),
|
|
||||||
has_valid_membership: validMembershipToggle.hasClass('active').toString()
|
|
||||||
},
|
|
||||||
format_results
|
format_results
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function load_initial_values() {
|
||||||
|
var param_set = false;
|
||||||
|
var q = getParameterByName('q');
|
||||||
|
if(q && q.length > 0) {
|
||||||
|
$('.search-field').val(q);
|
||||||
|
param_set = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hvm = getParameterByName('has_valid_membership');
|
||||||
|
if(hvm && hvm === 'true') {
|
||||||
|
$('.filters [data-search-filter="has_valid_membership"]').addClass('active');
|
||||||
|
param_set = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fg = getParameterByName('filter_groups');
|
||||||
|
var groups = [];
|
||||||
|
if(fg && fg.length > 0) {
|
||||||
|
if( fg.indexOf(',') !== -1 ) {
|
||||||
|
// has comma
|
||||||
|
groups = fg.split(',');
|
||||||
|
} else {
|
||||||
|
groups = [fg];
|
||||||
|
}
|
||||||
|
// is every group numeric?
|
||||||
|
var has_invalid_group = false;
|
||||||
|
var i=0;
|
||||||
|
for(i=0; i<groups.length; i++) {
|
||||||
|
var g = groups[i];
|
||||||
|
if( !$.isNumeric(g) ) {
|
||||||
|
has_invalid_group = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!has_invalid_group) {
|
||||||
|
param_set = true;
|
||||||
|
$('.groups-select').val(groups);
|
||||||
|
$('.groups-select').trigger('chosen:updated');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(param_set) {
|
||||||
|
do_search();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
moment.lang('nb');
|
moment.lang('nb');
|
||||||
|
|
||||||
@@ -140,8 +192,10 @@ jQuery(document).ready(function() {
|
|||||||
}).change(function() {
|
}).change(function() {
|
||||||
do_search();
|
do_search();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* Load intial values from url query */
|
||||||
|
load_initial_values();
|
||||||
});
|
});
|
||||||
$('.search-field').focus();
|
|
||||||
$('.search-field').on('keyup keypress', function(e) {
|
$('.search-field').on('keyup keypress', function(e) {
|
||||||
// No <enter>
|
// No <enter>
|
||||||
if (e.keyCode === 10 || e.keyCode === 13) {
|
if (e.keyCode === 10 || e.keyCode === 13) {
|
||||||
|
|||||||
@@ -7,7 +7,13 @@
|
|||||||
"foundation": "~5.3.0",
|
"foundation": "~5.3.0",
|
||||||
"moment": "~2.7.0",
|
"moment": "~2.7.0",
|
||||||
"underscore": "~1.6.0",
|
"underscore": "~1.6.0",
|
||||||
"chosen-bower": "~1.1.0"
|
"chosen-bower": "~1.1.0",
|
||||||
|
"history.js": "~1.8.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {}
|
"devDependencies": {},
|
||||||
|
"overrides": {
|
||||||
|
"history.js": {
|
||||||
|
"main": "./scripts/bundled/html4+html5/native.history.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
"use strict";function format_posts(e){var t="",s=0;if(0===e.length)return"Idag er det stille på huset :-/";for(s=0;s<e.length;s++){var r=e[s];t+='<li class="fadein">',t+='<span class="entry-starttime">'+moment.unix(r.custom_fields._neuf_events_starttime).utc().format("HH.mm")+"</span>: ",t+='<a href="'+r.url+'">'+r.title+"</a>",t+=' <span class="entry-venue">'+r.custom_fields._neuf_events_venue+"</span>",t+="</li>"}return t}function format_results(e){var t="<table><thead><tr><th>Navn</th><th>Brukernavn</th><th>Epost</th><th>Telefon</th><th>Medlem</th><th>Grupper</th></tr></thead>";if(e.error)return console.log(e.error),$(".search-result-list").html(""),void $(".search-results .meta").html("");if(0===e.meta.num_results)return $(".search-result-list").html("Uffda, ingen treff."),void $(".search-results .meta").html("");var s='<tbody><% _.each(results, function(u) { %><tr><td><a href="'+inside_url+'/?page=display-user&userid=<%= u.id %>"><%= u.firstname %> <%= u.lastname %></a></td><td><%= u.username %></td><td><a href="mailto:<%= u.email %>"><%= u.email %></a></td><td><a href="tlf:<%= u.number %>"><%= u.number %></a></td><td><% if(u.is_member != 0) { %>Ja<% } else { %>Nei<% } %></td><td class="groups"><%= u.groups %></td></li> <% }); %></tbody></table>',r=t+_.template(s,e);$(".search-result-list").html(r);var n="Antall treff: <%= meta.num_results %>";$(".search-results .meta").html(_.template(n,e))}function do_search(){var e=$('.filters [data-search-filter="has_valid_membership"]'),t="",s=$(".groups-select").val();null!==s&&(t=s.join()),$.getJSON(user_search_endpoint,{q:$(".search-field").val(),filter_groups:t,_wpnonce:$("meta[name=x-inside-api-nonce]").attr("content"),has_valid_membership:e.hasClass("active").toString()},format_results)}var program_endpoint="https://studentersamfundet.no/api/events/get_today/",inside_url="https://inside.studentersamfundet.no",inside_groups_url=inside_url+"/api/groups.php",user_search_endpoint="/inside-api/",query_params={};jQuery(document).ready(function(){moment.lang("nb");var e=jQuery;e("#menu .menu-toggle").on("click",function(t){t.preventDefault();var s=e("#menu .main-menu, #menu .user-menu-wrap");s.toggleClass("visible")}),e("#menu a.profile-badge").on("click",function(t){t.preventDefault();var s=e("#menu .user-menu");s.toggleClass("visible")}),e("[data-toggle-introduction]").on("click",function(){e(this).parent().fadeOut(600),e.cookie("introduction-dismissed","1")}),"1"!==e.cookie("introduction-dismissed")&&(e(".introduction").show(),e(".introduction").addClass("fadein"));var t=".program-list";e(t).length&&e.getJSON(program_endpoint+"?callback=?",query_params,function(s){if(s&&s.events){var r=format_posts(s.events);e(t).html(r)}}),e(".search-form").length&&(e.getJSON(inside_groups_url,function(t){var s='<select multiple class="groups-select" data-placeholder="Velg en gruppe..."><option value=""></option><% _.each(results, function(g) { %><option value="<%=g.group_id %>"><%= g.group_name %></option><% }); %></select>',r=_.template(s,t);e(".groups-select-wrap").html(r),e(".groups-select").chosen({no_results_text:"Uffda, ingen treff!",allow_single_deselect:!0}).change(function(){do_search()})}),e(".search-field").focus(),e(".search-field").on("keyup keypress",function(e){(10===e.keyCode||13===e.keyCode)&&e.preventDefault()}),e(".search-field").on("keyup keypress",_.debounce(function(){do_search()},300)),e(".roles a").on("click",function(t){t.preventDefault(),e(this).toggleClass("active"),do_search()}))});
|
"use strict";function getParameterByName(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)"),a=t.exec(location.search);return null===a?"":decodeURIComponent(a[1].replace(/\+/g," "))}function format_posts(e){var t="",a=0;if(0===e.length)return"Idag er det stille på huset :-/";for(a=0;a<e.length;a++){var r=e[a];t+='<li class="fadein">',t+='<span class="entry-starttime">'+moment.unix(r.custom_fields._neuf_events_starttime).utc().format("HH.mm")+"</span>: ",t+='<a href="'+r.url+'">'+r.title+"</a>",t+=' <span class="entry-venue">'+r.custom_fields._neuf_events_venue+"</span>",t+="</li>"}return t}function format_results(e){var t="<table><thead><tr><th>Navn</th><th>Brukernavn</th><th>Epost</th><th>Telefon</th><th>Har medlemskap</th><th>Grupper</th></tr></thead>";if(e.error)return console.log(e.error),$(".search-result-list").html(""),void $(".search-results .meta").html("");if(0===e.meta.num_results)return $(".search-result-list").html("Uffda, ingen treff."),void $(".search-results .meta").html("");var a='<tbody><% _.each(results, function(u) { %><tr><td><a href="'+inside_url+'/?page=display-user&userid=<%= u.id %>"><%= u.firstname %> <%= u.lastname %></a></td><td><%= u.username %></td><td><a href="mailto:<%= u.email %>"><%= u.email %></a></td><td><a href="tlf:<%= u.number %>"><%= u.number %></a></td><td><% if(u.is_member != 0) { %>Ja<% } else { %>Nei<% } %></td><td class="groups"><%= u.groups %></td></li> <% }); %></tbody></table>',r=t+_.template(a,e);$(".search-result-list").html(r);var s="Antall treff: <%= meta.num_results %>";$(".search-results .meta").html(_.template(s,e))}function do_search(){var e=$('.filters [data-search-filter="has_valid_membership"]'),t="",a=$(".groups-select").val();null!==a&&(t=a.join());var r={q:$(".search-field").val(),filter_groups:t,has_valid_membership:e.hasClass("active").toString()},s=$.param(r);window.History.pushState(null,null,"?"+s),r._wpnonce=$("meta[name=x-inside-api-nonce]").attr("content"),$.getJSON(user_search_endpoint,r,format_results)}function load_initial_values(){var e=!1,t=getParameterByName("q");t&&t.length>0&&($(".search-field").val(t),e=!0);var a=getParameterByName("has_valid_membership");a&&"true"===a&&($('.filters [data-search-filter="has_valid_membership"]').addClass("active"),e=!0);var r=getParameterByName("filter_groups"),s=[];if(r&&r.length>0){s=-1!==r.indexOf(",")?r.split(","):[r];var n=!1,l=0;for(l=0;l<s.length;l++){var i=s[l];$.isNumeric(i)||(n=!0)}n||(e=!0,$(".groups-select").val(s),$(".groups-select").trigger("chosen:updated"))}e&&do_search()}var program_endpoint="https://studentersamfundet.no/api/events/get_today/",inside_url="https://inside.studentersamfundet.no",inside_groups_url=inside_url+"/api/groups.php",user_search_endpoint="/inside-api/",query_params={};jQuery(document).ready(function(){moment.lang("nb");var e=jQuery;e("#menu .menu-toggle").on("click",function(t){t.preventDefault();var a=e("#menu .main-menu, #menu .user-menu-wrap");a.toggleClass("visible")}),e("#menu a.profile-badge").on("click",function(t){t.preventDefault();var a=e("#menu .user-menu");a.toggleClass("visible")}),e("[data-toggle-introduction]").on("click",function(){e(this).parent().fadeOut(600),e.cookie("introduction-dismissed","1")}),"1"!==e.cookie("introduction-dismissed")&&(e(".introduction").show(),e(".introduction").addClass("fadein"));var t=".program-list";e(t).length&&e.getJSON(program_endpoint+"?callback=?",query_params,function(a){if(a&&a.events){var r=format_posts(a.events);e(t).html(r)}}),e(".search-form").length&&(e.getJSON(inside_groups_url,function(t){var a='<select multiple class="groups-select" data-placeholder="Velg en gruppe..."><option value=""></option><% _.each(results, function(g) { %><option value="<%=g.group_id %>"><%= g.group_name %></option><% }); %></select>',r=_.template(a,t);e(".groups-select-wrap").html(r),e(".groups-select").chosen({no_results_text:"Uffda, ingen treff!",allow_single_deselect:!0}).change(function(){do_search()}),load_initial_values()}),e(".search-field").on("keyup keypress",function(e){(10===e.keyCode||13===e.keyCode)&&e.preventDefault()}),e(".search-field").on("keyup keypress",_.debounce(function(){do_search()},300)),e(".roles a").on("click",function(t){t.preventDefault(),e(this).toggleClass("active"),do_search()}))});
|
||||||
@@ -22437,3 +22437,5 @@ This file is generated by `grunt build`, do not edit it by hand.
|
|||||||
})(AbstractChosen);
|
})(AbstractChosen);
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
typeof JSON!="object"&&(JSON={}),function(){"use strict";function f(e){return e<10?"0"+e:e}function quote(e){return escapable.lastIndex=0,escapable.test(e)?'"'+e.replace(escapable,function(e){var t=meta[e];return typeof t=="string"?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var n,r,i,s,o=gap,u,a=t[e];a&&typeof a=="object"&&typeof a.toJSON=="function"&&(a=a.toJSON(e)),typeof rep=="function"&&(a=rep.call(t,e,a));switch(typeof a){case"string":return quote(a);case"number":return isFinite(a)?String(a):"null";case"boolean":case"null":return String(a);case"object":if(!a)return"null";gap+=indent,u=[];if(Object.prototype.toString.apply(a)==="[object Array]"){s=a.length;for(n=0;n<s;n+=1)u[n]=str(n,a)||"null";return i=u.length===0?"[]":gap?"[\n"+gap+u.join(",\n"+gap)+"\n"+o+"]":"["+u.join(",")+"]",gap=o,i}if(rep&&typeof rep=="object"){s=rep.length;for(n=0;n<s;n+=1)typeof rep[n]=="string"&&(r=rep[n],i=str(r,a),i&&u.push(quote(r)+(gap?": ":":")+i))}else for(r in a)Object.prototype.hasOwnProperty.call(a,r)&&(i=str(r,a),i&&u.push(quote(r)+(gap?": ":":")+i));return i=u.length===0?"{}":gap?"{\n"+gap+u.join(",\n"+gap)+"\n"+o+"}":"{"+u.join(",")+"}",gap=o,i}}typeof Date.prototype.toJSON!="function"&&(Date.prototype.toJSON=function(e){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(e){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;typeof JSON.stringify!="function"&&(JSON.stringify=function(e,t,n){var r;gap="",indent="";if(typeof n=="number")for(r=0;r<n;r+=1)indent+=" ";else typeof n=="string"&&(indent=n);rep=t;if(!t||typeof t=="function"||typeof t=="object"&&typeof t.length=="number")return str("",{"":e});throw new Error("JSON.stringify")}),typeof JSON.parse!="function"&&(JSON.parse=function(text,reviver){function walk(e,t){var n,r,i=e[t];if(i&&typeof i=="object")for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(r=walk(i,n),r!==undefined?i[n]=r:delete i[n]);return reviver.call(e,t,i)}var j;text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),typeof reviver=="function"?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}(),function(e,t){"use strict";var n=e.History=e.History||{};if(typeof n.Adapter!="undefined")throw new Error("History.js Adapter has already been loaded...");n.Adapter={handlers:{},_uid:1,uid:function(e){return e._uid||(e._uid=n.Adapter._uid++)},bind:function(e,t,r){var i=n.Adapter.uid(e);n.Adapter.handlers[i]=n.Adapter.handlers[i]||{},n.Adapter.handlers[i][t]=n.Adapter.handlers[i][t]||[],n.Adapter.handlers[i][t].push(r),e["on"+t]=function(e,t){return function(r){n.Adapter.trigger(e,t,r)}}(e,t)},trigger:function(e,t,r){r=r||{};var i=n.Adapter.uid(e),s,o;n.Adapter.handlers[i]=n.Adapter.handlers[i]||{},n.Adapter.handlers[i][t]=n.Adapter.handlers[i][t]||[];for(s=0,o=n.Adapter.handlers[i][t].length;s<o;++s)n.Adapter.handlers[i][t][s].apply(this,[r])},extractEventData:function(e,n){var r=n&&n[e]||t;return r},onDomLoad:function(t){var n=e.setTimeout(function(){t()},2e3);e.onload=function(){clearTimeout(n),t()}}},typeof n.init!="undefined"&&n.init()}(window),function(e,t){"use strict";var n=e.document,r=e.setTimeout||r,i=e.clearTimeout||i,s=e.setInterval||s,o=e.History=e.History||{};if(typeof o.initHtml4!="undefined")throw new Error("History.js HTML4 Support has already been loaded...");o.initHtml4=function(){if(typeof o.initHtml4.initialized!="undefined")return!1;o.initHtml4.initialized=!0,o.enabled=!0,o.savedHashes=[],o.isLastHash=function(e){var t=o.getHashByIndex(),n;return n=e===t,n},o.isHashEqual=function(e,t){return e=encodeURIComponent(e).replace(/%25/g,"%"),t=encodeURIComponent(t).replace(/%25/g,"%"),e===t},o.saveHash=function(e){return o.isLastHash(e)?!1:(o.savedHashes.push(e),!0)},o.getHashByIndex=function(e){var t=null;return typeof e=="undefined"?t=o.savedHashes[o.savedHashes.length-1]:e<0?t=o.savedHashes[o.savedHashes.length+e]:t=o.savedHashes[e],t},o.discardedHashes={},o.discardedStates={},o.discardState=function(e,t,n){var r=o.getHashByState(e),i;return i={discardedState:e,backState:n,forwardState:t},o.discardedStates[r]=i,!0},o.discardHash=function(e,t,n){var r={discardedHash:e,backState:n,foLine truncated
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<div class="search-form">
|
<div class="search-form">
|
||||||
<h1 class="page-title"><?php wp_title("", true); ?></h1>
|
<h1 class="page-title"><?php wp_title("", true); ?></h1>
|
||||||
<form method="get">
|
<form method="get">
|
||||||
<input type="text" id="id_user_query" class="search-field" name="q" placeholder="Søk på navn, epost, eller brukernavn" />
|
<input type="text" id="id_user_query" class="search-field" name="q" placeholder="Søk på navn, epost, eller brukernavn" autofocus />
|
||||||
<div class="filters">
|
<div class="filters">
|
||||||
<div class="groups">
|
<div class="groups">
|
||||||
<label>Søk på gruppe (forening):</label>
|
<label>Søk på gruppe (forening):</label>
|
||||||
|
|||||||
Reference in new issue
Block a user