Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*!
- * A set of JS and jQuery functions/executions. For plugins, see plugins.min.js.
- */
- // This allows quick retrieval of URL parameters
- function GetURLParameter(sParam) {
- var sPageURL = window.location.search.substring(1);
- var sURLVariables = sPageURL.split('&');
- for (var i = 0; i < sURLVariables.length; i++)
- {
- var sParameterName = sURLVariables[i].split('=');
- if (sParameterName[0] == sParam)
- {
- return sParameterName[1];
- }
- }
- }
- jQuery(function($) {
- /** This function sets the up & down arrow & sort parameters on click in the front end **/
- // Set variables for possible URL parameters used in the script
- var orderby = GetURLParameter('orderby');
- var order = GetURLParameter('order');
- var active = GetURLParameter('active');
- // Now that we know what parameters are used, let's build our output string. Note that
- // we don't care about the "order" parameter because we're building this to control the
- // arrow itself -- it's manually assigned in the switch (later).
- function BuildURL() {
- var findParams = [];
- var iteration = 0;
- var target = "";
- // Find out which params are defined and build the full strings into an array
- if(typeof (orderby) != 'undefined' && orderby != null ) {
- findParams.push("orderby=" + orderby);
- }
- if(typeof (active) != 'undefined' && orderby != null ) {
- findParams.push("active=" + active);
- }
- // Loop over the array and insert the appropriate separators
- $.each(findParams, function(key,value) {
- iteration++;
- if ( iteration === 1 ) {
- target += "?";
- } else {
- target += "&";
- }
- target += value;
- });
- // Set final seperators depending on what was defined then return the result
- if(typeof (target) != 'undefined' && target != '' && target != null) {
- target = target + "&";
- return target;
- } else {
- target = "?";
- return target;
- }
- }
- // Grab the sort buttons for manipulation
- var sortBar = $('.sortbar');
- var sortButton = sortBar.find('div');
- var byPrice = $('div.byprice');
- var theURL = window.location.href.split('?');
- // Check which button is active and add it to a variable
- switch(orderby) {
- case 'property_price' :
- byPrice.addClass('active');
- break;
- case 'property_revenue' :
- $('.byrev').addClass('active');
- break;
- case 'adjusted_sde' :
- $('.bysde').addClass('active');
- break;
- default :
- // default sort is by price
- byPrice.addClass('active');
- }
- // On the active button, check the sort order
- var activeSort = sortButton.find('.active');
- switch(order) {
- case 'asc' :
- sortBar.find('.active').find('i').removeClass('fa-sort-desc').addClass('fa-sort-asc');
- sortBar.find('.active').find('a').attr('href', theURL[0] + BuildURL() + "order=desc");
- break;
- case 'desc' :
- sortBar.find('.active').find('a').attr('href', theURL[0] + BuildURL() + "order=asc");
- break;
- default :
- sortBar.find('.active').find('a').attr('href', theURL[0] + BuildURL() + "order=asc");
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement