cached commonly used elements
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 1 Feb 2016 21:24:42 +0000 (16:24 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 1 Feb 2016 21:24:42 +0000 (16:24 -0500)
js/app.js
js/custom/upcp.js

index 2aa6a73..77543c1 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -34,37 +34,48 @@ $(document).ready(function () {
         var expires = "; expires="+date.toGMTString();
         document.cookie = name+"="+value+expires+"; path=/";
     }
+    
+    var gridView = $("#gridView");
+    var listView = $("#listView");
+    var categoriesGridView = $("#categoriesGridView");
+    var categoriesListView = $("#categoriesListView");
+    var productsView = $("#productsView");
+    var categoriesView = $("#categoriesView");
+    var tagBox = $("#tagBox");
+    var grid = $("#grid");
+    var list = $("#list");
+    
    // createCookie("link", "null");
     document.cookie = "catView=grid";
     // don't display products on the main "products page"
     if ((window.location.href.indexOf("products-2") >= 0)){
         if(document.cookie.indexOf("true") >= 0){
-            $("#gridView").css("display", "inherit");
-            $("#listView").css("display", "inherit");
-            $("#categoriesGridView").css("display", "none");
-            $("#categoriesListView").css("display", "none");
-            $("#tagBox").css("display", "none");
+            $(gridView).css("display", "inherit");
+            $(listView).css("display", "inherit");
+            $(categoriesGridView).css("display", "none");
+            $(categoriesListView).css("display", "none");
+            $(tagBox).css("display", "none");
         } else {
-            $("#gridView").css("display", "none");
-            $("#listView").css("display", "none");
+            $(gridView).css("display", "none");
+            $(listView).css("display", "none");
         }
-        $("#grid").on("click", function (e) {
+        $(grid).on("click", function (e) {
             document.cookie = "catView=grid";
             location.reload();
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "catView=list";
             location.reload();
         });
     }
     if ((window.location.href.indexOf("products-3") >= 0)){
-        $("#categoriesGridView").css("display", "none");
-        $("#categoriesListView").css("display", "none");
-        $("#grid").on("click", function (e) {
+        $(categoriesGridView).css("display", "none");
+        $(categoriesListView).css("display", "none");
+        $(grid).on("click", function (e) {
             document.cookie = "catView=grid";
             location.reload();
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "catView=list";
             location.reload();
         });
@@ -72,66 +83,66 @@ $(document).ready(function () {
     
     // hide product display initially
     if ((window.location.href.indexOf("products-2/?michsci_category") >= 0)){
-        $("#productsView").css("display", "inherit");
-        $("#categoriesView").css("display", "none");
-        $("#gridView").css("display", "inherit");
-        $("#listView").css("display", "inherit");
-        $("#categoriesGridView").css("display", "none");
-        $("#categoriesListView").css("display", "none");
+        $(productsView).css("display", "inherit");
+        $(categoriesView).css("display", "none");
+        $(gridView).css("display", "inherit");
+        $(listView).css("display", "inherit");
+        $(categoriesGridView).css("display", "none");
+        $(categoriesListView).css("display", "none");
     }
     if ((window.location.href.indexOf("products-3/?michsci_category") >= 0)){
-        $("#productsView").css("display", "inherit");
-        $("#categoriesView").css("display", "none");
-        $("#gridView").css("display", "inherit");
-        $("#listView").css("display", "inherit");
-        $("#categoriesGridView").css("display", "none");
-        $("#categoriesListView").css("display", "none");
-        $("#blog-side-info-wrapper").insertBefore("#gridView");
+        $(productsView).css("display", "inherit");
+        $(categoriesView).css("display", "none");
+        $(gridView).css("display", "inherit");
+        $(listView).css("display", "inherit");
+        $(categoriesGridView).css("display", "none");
+        $(categoriesListView).css("display", "none");
+        $("#blog-side-info-wrapper").insertBefore(gridView);
     }
 
     // navigate back to products page if on single product page
     if ((window.location.href.indexOf("products-2/?pagename") >= 0)) {
 //        $("#viewBtns").css("display", "none");
-        $("#grid").on("click", function (e) {
+        $(grid).on("click", function (e) {
             document.cookie = "view=grid";
             window.location.href =  window.location.pathname;
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "view=list";
             window.location.href =  window.location.pathname;
         });
-        $("#tagBox").css("display", "none");
+        $(tagBox).css("display", "none");
     }
     // change output view from list to grid
     if (!(window.location.href.indexOf("products-2/?pagename") >= 0)) {
-    $("#grid").on("click", function (e) {
+    $(grid).on("click", function (e) {
         document.cookie = "view=grid";
         location.reload();
     });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "view=list";
             location.reload();
         });
     }
     if ((window.location.href.indexOf("products-3/?pagename") >= 0)) {
         //        $("#viewBtns").css("display", "none");
-        $("#grid").on("click", function (e) {
+        $(grid).on("click", function (e) {
             document.cookie = "view=grid";
             window.location.href =  window.location.pathname;
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "view=list";
             window.location.href =  window.location.pathname;
         });
-        $("#tagBox").css("display", "none");
+        $(tagBox).css("display", "none");
     }
     // change output view from list to grid
     if (!(window.location.href.indexOf("products-3/?pagename") >= 0)) {
-        $("#grid").on("click", function (e) {
+        $(grid).on("click", function (e) {
             document.cookie = "view=grid";
             location.reload();
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "view=list";
             location.reload();
         });
@@ -143,30 +154,30 @@ $(document).ready(function () {
     // show products if filter is selected else only display categories
     $("#tagBox :checkbox").on("click",function() {
         $(".product").hide();
-        $("#gridView").css("display", "inherit");
-        $("#listView").css("display", "inherit");
-        $("#categoriesGridView").hide();
-        $("#categoriesListView").hide();
+        $(gridView).css("display", "inherit");
+        $(listView).css("display", "inherit");
+        $(categoriesGridView).hide();
+        $(categoriesListView).hide();
         $("#tagBox :checkbox:checked").each(function() {
             $("." + $(this).val()).show();
         });
         // hide products on front page, show all products if on products page
         if($("#tagBox :checkbox:checked").length === 0 && !(window.location.href.indexOf("products-2/?michsci_category") >= 0)){
-            $("#categoriesGridView").show();
-            $("#categoriesListView").show();
-            $("#gridView").css("display", "none");
-            $("#listView").css("display", "none");
+            $(categoriesGridView).show();
+            $(categoriesListView).show();
+            $(gridView).css("display", "none");
+            $(listView).css("display", "none");
    
         } else if ($("#tagBox :checkbox:checked").length === 0){
             $(".product").show();
         }
         if($("#tagBox :checkbox:checked").length === 0 && window.location.href.indexOf("products-3/") >= 0){
-            $("#categoriesGridView").show();
-            $("#categoriesListView").show();
-            $("#categoriesGridView").hide();
-            $("#categoriesListView").hide();
-            $("#gridView").css("display", "inherit");
-            $("#listView").css("display", "none");
+            $(categoriesGridView).show();
+            $(categoriesListView).show();
+            $(categoriesGridView).hide();
+            $(categoriesListView).hide();
+            $(gridView).css("display", "inherit");
+            $(listView).css("display", "none");
             $(".product").show();
         } else if ($("#tagBox :checkbox:checked").length === 0){
 //            $(".product").show();
@@ -185,10 +196,10 @@ $(document).ready(function () {
 //        $("#search-icon").css("visibility", "visible");
 //    });
     $("#page-title").append($("#productBreadcrumbs"));
-//    $("#blog-side-info-wrapper").insertBefore("#categoriesGridView");
-//    $("#blog-side-info-wrapper").insertBefore("#categoriesListView");
-    $("#blog-side-info-wrapper").insertBefore("#gridView");
-    $("#blog-side-info-wrapper").insertBefore("#listView");
+//    $("#blog-side-info-wrapper").insertBefore(categoriesGridView);
+//    $("#blog-side-info-wrapper").insertBefore(categoriesListView);
+    $("#blog-side-info-wrapper").insertBefore(gridView);
+    $("#blog-side-info-wrapper").insertBefore(listView);
 
     var link; 
     $('#tags a').click(function() {
@@ -213,10 +224,10 @@ $(document).ready(function () {
         $(":checkbox[value=" + selectedTag + "]").prop("checked", true);
         if($(":checkbox[value=" + selectedTag + "]").prop("checked", true)){
             $(".product").hide();
-            $("#gridView").css("display", "inherit");
-            $("#listView").css("display", "inherit");
-            $("#categoriesGridView").hide();
-            $("#categoriesListView").hide();
+            $(gridView).css("display", "inherit");
+            $(listView).css("display", "inherit");
+            $(categoriesGridView).hide();
+            $(categoriesListView).hide();
             $("#tagBox :checkbox:checked").each(function() {
                 $("." + $(this).val()).show();
             });
@@ -241,7 +252,7 @@ $(document).ready(function () {
     
     if ((window.location.href.indexOf("/?michsci_category") >= 0) || (window.location.href.indexOf("/?pagename") >= 0) ){
         var $bottomText = $("#catelog-content").nextAll();
-        var $bottomText2 = $("#categoriesGridView").nextAll();
+        var $bottomText2 = $(categoriesGridView).nextAll();
         var $bottomText3 = $("#main-content").nextAll();
         $bottomText.hide();
         $bottomText2.hide();
index 7f5001e..a5b7a72 100644 (file)
@@ -14,37 +14,48 @@ $(document).ready(function () {
         var expires = "; expires="+date.toGMTString();
         document.cookie = name+"="+value+expires+"; path=/";
     }
+    
+    var gridView = $("#gridView");
+    var listView = $("#listView");
+    var categoriesGridView = $("#categoriesGridView");
+    var categoriesListView = $("#categoriesListView");
+    var productsView = $("#productsView");
+    var categoriesView = $("#categoriesView");
+    var tagBox = $("#tagBox");
+    var grid = $("#grid");
+    var list = $("#list");
+    
    // createCookie("link", "null");
     document.cookie = "catView=grid";
     // don't display products on the main "products page"
     if ((window.location.href.indexOf("products-2") >= 0)){
         if(document.cookie.indexOf("true") >= 0){
-            $("#gridView").css("display", "inherit");
-            $("#listView").css("display", "inherit");
-            $("#categoriesGridView").css("display", "none");
-            $("#categoriesListView").css("display", "none");
-            $("#tagBox").css("display", "none");
+            $(gridView).css("display", "inherit");
+            $(listView).css("display", "inherit");
+            $(categoriesGridView).css("display", "none");
+            $(categoriesListView).css("display", "none");
+            $(tagBox).css("display", "none");
         } else {
-            $("#gridView").css("display", "none");
-            $("#listView").css("display", "none");
+            $(gridView).css("display", "none");
+            $(listView).css("display", "none");
         }
-        $("#grid").on("click", function (e) {
+        $(grid).on("click", function (e) {
             document.cookie = "catView=grid";
             location.reload();
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "catView=list";
             location.reload();
         });
     }
     if ((window.location.href.indexOf("products-3") >= 0)){
-        $("#categoriesGridView").css("display", "none");
-        $("#categoriesListView").css("display", "none");
-        $("#grid").on("click", function (e) {
+        $(categoriesGridView).css("display", "none");
+        $(categoriesListView).css("display", "none");
+        $(grid).on("click", function (e) {
             document.cookie = "catView=grid";
             location.reload();
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "catView=list";
             location.reload();
         });
@@ -52,66 +63,66 @@ $(document).ready(function () {
     
     // hide product display initially
     if ((window.location.href.indexOf("products-2/?michsci_category") >= 0)){
-        $("#productsView").css("display", "inherit");
-        $("#categoriesView").css("display", "none");
-        $("#gridView").css("display", "inherit");
-        $("#listView").css("display", "inherit");
-        $("#categoriesGridView").css("display", "none");
-        $("#categoriesListView").css("display", "none");
+        $(productsView).css("display", "inherit");
+        $(categoriesView).css("display", "none");
+        $(gridView).css("display", "inherit");
+        $(listView).css("display", "inherit");
+        $(categoriesGridView).css("display", "none");
+        $(categoriesListView).css("display", "none");
     }
     if ((window.location.href.indexOf("products-3/?michsci_category") >= 0)){
-        $("#productsView").css("display", "inherit");
-        $("#categoriesView").css("display", "none");
-        $("#gridView").css("display", "inherit");
-        $("#listView").css("display", "inherit");
-        $("#categoriesGridView").css("display", "none");
-        $("#categoriesListView").css("display", "none");
-        $("#blog-side-info-wrapper").insertBefore("#gridView");
+        $(productsView).css("display", "inherit");
+        $(categoriesView).css("display", "none");
+        $(gridView).css("display", "inherit");
+        $(listView).css("display", "inherit");
+        $(categoriesGridView).css("display", "none");
+        $(categoriesListView).css("display", "none");
+        $("#blog-side-info-wrapper").insertBefore(gridView);
     }
 
     // navigate back to products page if on single product page
     if ((window.location.href.indexOf("products-2/?pagename") >= 0)) {
 //        $("#viewBtns").css("display", "none");
-        $("#grid").on("click", function (e) {
+        $(grid).on("click", function (e) {
             document.cookie = "view=grid";
             window.location.href =  window.location.pathname;
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "view=list";
             window.location.href =  window.location.pathname;
         });
-        $("#tagBox").css("display", "none");
+        $(tagBox).css("display", "none");
     }
     // change output view from list to grid
     if (!(window.location.href.indexOf("products-2/?pagename") >= 0)) {
-    $("#grid").on("click", function (e) {
+    $(grid).on("click", function (e) {
         document.cookie = "view=grid";
         location.reload();
     });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "view=list";
             location.reload();
         });
     }
     if ((window.location.href.indexOf("products-3/?pagename") >= 0)) {
         //        $("#viewBtns").css("display", "none");
-        $("#grid").on("click", function (e) {
+        $(grid).on("click", function (e) {
             document.cookie = "view=grid";
             window.location.href =  window.location.pathname;
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "view=list";
             window.location.href =  window.location.pathname;
         });
-        $("#tagBox").css("display", "none");
+        $(tagBox).css("display", "none");
     }
     // change output view from list to grid
     if (!(window.location.href.indexOf("products-3/?pagename") >= 0)) {
-        $("#grid").on("click", function (e) {
+        $(grid).on("click", function (e) {
             document.cookie = "view=grid";
             location.reload();
         });
-        $("#list").on("click", function (e) {
+        $(list).on("click", function (e) {
             document.cookie = "view=list";
             location.reload();
         });
@@ -123,30 +134,30 @@ $(document).ready(function () {
     // show products if filter is selected else only display categories
     $("#tagBox :checkbox").on("click",function() {
         $(".product").hide();
-        $("#gridView").css("display", "inherit");
-        $("#listView").css("display", "inherit");
-        $("#categoriesGridView").hide();
-        $("#categoriesListView").hide();
+        $(gridView).css("display", "inherit");
+        $(listView).css("display", "inherit");
+        $(categoriesGridView).hide();
+        $(categoriesListView).hide();
         $("#tagBox :checkbox:checked").each(function() {
             $("." + $(this).val()).show();
         });
         // hide products on front page, show all products if on products page
         if($("#tagBox :checkbox:checked").length === 0 && !(window.location.href.indexOf("products-2/?michsci_category") >= 0)){
-            $("#categoriesGridView").show();
-            $("#categoriesListView").show();
-            $("#gridView").css("display", "none");
-            $("#listView").css("display", "none");
+            $(categoriesGridView).show();
+            $(categoriesListView).show();
+            $(gridView).css("display", "none");
+            $(listView).css("display", "none");
    
         } else if ($("#tagBox :checkbox:checked").length === 0){
             $(".product").show();
         }
         if($("#tagBox :checkbox:checked").length === 0 && window.location.href.indexOf("products-3/") >= 0){
-            $("#categoriesGridView").show();
-            $("#categoriesListView").show();
-            $("#categoriesGridView").hide();
-            $("#categoriesListView").hide();
-            $("#gridView").css("display", "inherit");
-            $("#listView").css("display", "none");
+            $(categoriesGridView).show();
+            $(categoriesListView).show();
+            $(categoriesGridView).hide();
+            $(categoriesListView).hide();
+            $(gridView).css("display", "inherit");
+            $(listView).css("display", "none");
             $(".product").show();
         } else if ($("#tagBox :checkbox:checked").length === 0){
 //            $(".product").show();
@@ -165,10 +176,10 @@ $(document).ready(function () {
 //        $("#search-icon").css("visibility", "visible");
 //    });
     $("#page-title").append($("#productBreadcrumbs"));
-//    $("#blog-side-info-wrapper").insertBefore("#categoriesGridView");
-//    $("#blog-side-info-wrapper").insertBefore("#categoriesListView");
-    $("#blog-side-info-wrapper").insertBefore("#gridView");
-    $("#blog-side-info-wrapper").insertBefore("#listView");
+//    $("#blog-side-info-wrapper").insertBefore(categoriesGridView);
+//    $("#blog-side-info-wrapper").insertBefore(categoriesListView);
+    $("#blog-side-info-wrapper").insertBefore(gridView);
+    $("#blog-side-info-wrapper").insertBefore(listView);
 
     var link; 
     $('#tags a').click(function() {
@@ -193,10 +204,10 @@ $(document).ready(function () {
         $(":checkbox[value=" + selectedTag + "]").prop("checked", true);
         if($(":checkbox[value=" + selectedTag + "]").prop("checked", true)){
             $(".product").hide();
-            $("#gridView").css("display", "inherit");
-            $("#listView").css("display", "inherit");
-            $("#categoriesGridView").hide();
-            $("#categoriesListView").hide();
+            $(gridView).css("display", "inherit");
+            $(listView).css("display", "inherit");
+            $(categoriesGridView).hide();
+            $(categoriesListView).hide();
             $("#tagBox :checkbox:checked").each(function() {
                 $("." + $(this).val()).show();
             });
@@ -221,7 +232,7 @@ $(document).ready(function () {
     
     if ((window.location.href.indexOf("/?michsci_category") >= 0) || (window.location.href.indexOf("/?pagename") >= 0) ){
         var $bottomText = $("#catelog-content").nextAll();
-        var $bottomText2 = $("#categoriesGridView").nextAll();
+        var $bottomText2 = $(categoriesGridView).nextAll();
         var $bottomText3 = $("#main-content").nextAll();
         $bottomText.hide();
         $bottomText2.hide();