| 1 |
"use strict"; |
| 2 |
|
| 3 |
(function ($) { |
| 4 |
'use strict'; |
| 5 |
/** |
| 6 |
* All of the code for your public-facing JavaScript source |
| 7 |
* should reside in this file. |
| 8 |
* |
| 9 |
* Note: It has been assumed you will write jQuery code here, so the |
| 10 |
* $ function reference has been prepared for usage within the scope |
| 11 |
* of this function. |
| 12 |
* |
| 13 |
* This enables you to define handlers, for when the DOM is ready: |
| 14 |
* |
| 15 |
* $(function() { |
| 16 |
* |
| 17 |
* }); |
| 18 |
* |
| 19 |
* When the window is loaded: |
| 20 |
* |
| 21 |
* $( window ).load(function() { |
| 22 |
* |
| 23 |
* }); |
| 24 |
* |
| 25 |
* ...and/or other possibilities. |
| 26 |
* |
| 27 |
* Ideally, it is not considered best practise to attach more than a |
| 28 |
* single DOM-ready or window-load handler for a particular page. |
| 29 |
* Although scripts in the WordPress core, Plugins and Themes may be |
| 30 |
* practising this, we should strive to set a better example in our own work. |
| 31 |
*/ |
| 32 |
|
| 33 |
$('.wdk-order').on('change', function () { |
| 34 |
var curr_url = wdk_removeParam('order_by', document.location.toString()); |
| 35 |
|
| 36 |
if (curr_url.indexOf('#') == -1) {// Fine |
| 37 |
} else { |
| 38 |
// Remove this part related |
| 39 |
curr_url = curr_url.substr(0, curr_url.indexOf('#')); |
| 40 |
} |
| 41 |
|
| 42 |
var del_char = '&'; |
| 43 |
if (curr_url.indexOf('?') == -1) del_char = '?'; |
| 44 |
document.location = curr_url + del_char + 'order_by=' + $(this).val() + '#results'; |
| 45 |
}); |
| 46 |
$('.wmvc-view-type a').on('click', function (e) { |
| 47 |
e.preventDefault(); |
| 48 |
var curr_url = wdk_removeParam('wmvc_view_type', document.location.toString()); |
| 49 |
|
| 50 |
if (curr_url.indexOf('#') == -1) {// Fine |
| 51 |
} else { |
| 52 |
// Remove this part related |
| 53 |
curr_url = curr_url.substr(0, curr_url.indexOf('#')); |
| 54 |
} |
| 55 |
|
| 56 |
var del_char = '&'; |
| 57 |
if (curr_url.indexOf('?') == -1) del_char = '?'; |
| 58 |
document.location = curr_url + del_char + 'wmvc_view_type=' + $(this).attr('data-id') + '#results'; |
| 59 |
}); |
| 60 |
})(jQuery); |
| 61 |
|
| 62 |
function wdk_removeParam(key, sourceURL) { |
| 63 |
var rtn = sourceURL.split("?")[0], |
| 64 |
param, |
| 65 |
params_arr = [], |
| 66 |
queryString = sourceURL.indexOf("?") !== -1 ? sourceURL.split("?")[1] : ""; |
| 67 |
|
| 68 |
if (queryString !== "") { |
| 69 |
params_arr = queryString.split("&"); |
| 70 |
|
| 71 |
for (var i = params_arr.length - 1; i >= 0; i -= 1) { |
| 72 |
param = params_arr[i].split("=")[0]; |
| 73 |
|
| 74 |
if (param === key) { |
| 75 |
params_arr.splice(i, 1); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
if (params_arr.length) rtn = rtn + "?" + params_arr.join("&"); |
| 80 |
} |
| 81 |
|
| 82 |
return rtn; |
| 83 |
} |
| 84 |
|
| 85 |
function wdk_splitUrl() { |
| 86 |
var vars = [], |
| 87 |
hash; |
| 88 |
var url = document.URL.split('?')[0]; |
| 89 |
var p = document.URL.split('?')[1]; |
| 90 |
|
| 91 |
if (p != undefined) { |
| 92 |
p = p.split('&'); |
| 93 |
|
| 94 |
for (var i = 0; i < p.length; i++) { |
| 95 |
hash = p[i].split('='); |
| 96 |
vars.push(hash[1]); |
| 97 |
vars[hash[0]] = hash[1]; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
vars['url'] = url; |
| 102 |
return vars; |
| 103 |
} |
| 104 |
|
| 105 |
; |