1/* 2 * Gridder - v1.4.2 3 * A jQuery plugin that displays a thumbnail grid expanding preview similar to the effect seen on Google Images. 4 * http://www.oriongunning.com/ 5 * 6 * Made by Orion Gunning 7 * Under MIT License 8 */ 9;(function($) { 10 11 //Ensures there will be no 'console is undefined' errors in IE 12 window.console = window.console || (function(){ 13 var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function(){}; 14 return c; 15 })(); 16 17 /* Custom Easing */ 18 $.fn.extend($.easing,{ 19 def:"easeInOutExpo", easeInOutExpo:function(e,f,a,h,g){if(f===0){return a;}if(f===g){return a+h;}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a;}return h/2*(-Math.pow(2,-10*--f)+2)+a;} 20 }); 21 22 /* KEYPRESS LEFT & RIGHT ARROW */ 23 /* This will work only if a current gridder is opened. */ 24 $(document).keydown(function(e) { 25 var keycode = e.keyCode; 26 var $current_gridder = $(".currentGridder"); 27 var $current_target = $current_gridder.find(".wpsm-gridder-show"); 28 if($current_gridder.length){ 29 if ( keycode === 37 ) { 30 //console.log("Pressed Left Arrow"); 31 $current_target.prev().prev().trigger("click"); 32 e.preventDefault(); 33 } 34 if ( keycode === 39 ) { 35 //console.log("Pressed Right Arrow"); 36 $current_target.next().trigger("click"); 37 e.preventDefault(); 38 } 39 }else{ 40 //console.log("No active gridder."); 41 } 42 }); 43 44 $.fn.gridderExpander = function(options) { 45 46 /* GET DEFAULT OPTIONS OR USE THE ONE PASSED IN THE FUNCTION */ 47 var settings = $.extend( {}, $.fn.gridderExpander.defaults, options ); 48 49 return this.each(function() { 50 51 var mybloc; 52 var _this = $(this); 53 var visible = false; 54 55 // START CALLBACK 56 settings.onStart(_this); 57 58 // CLOSE FUNCTION 59 function closeExpander(base) { 60 61 // SCROLL TO CORRECT POSITION FIRST 62 if(settings.scroll){ 63 $("html, body").animate({ 64 scrollTop: base.find(".selectedItem").offset().top - settings.scrollOffset 65 }, { 66 duration: 200, 67 easing: settings.animationEasing 68 }); 69 } 70 71 _this.removeClass("hasSelectedItem"); 72 73 // REMOVES GRIDDER EXPAND AREA 74 visible = false; 75 base.find(".selectedItem").removeClass("selectedItem"); 76 77 base.find(".wpsm-gridder-show").slideUp(settings.animationSpeed, settings.animationEasing, function() { 78 base.find(".wpsm-gridder-show").remove(); 79 settings.onClosed(base); 80 }); 81 82 /* REMOVE CURRENT ACTIVE GRIDDER */ 83 $(".currentGridder").removeClass("currentGridder"); 84 } 85 86 // OPEN EXPANDER 87 function openExpander(myself) { 88 89 /* CURRENT ACTIVE GRIDDER */ 90 $(".currentGridder").removeClass("currentGridder"); 91 _this.addClass("currentGridder"); 92 93 /* ENSURES THE CORRECT BLOC IS ACTIVE */ 94 if (!myself.hasClass("selectedItem")) { 95 _this.find(".selectedItem").removeClass("selectedItem"); 96 myself.addClass("selectedItem"); 97 } else { 98 // THE SAME IS ALREADY OPEN, LET"S CLOSE IT 99 closeExpander(_this, settings); 100 return; 101 } 102 103 /* REMOVES PREVIOUS BLOC */ 104 _this.find(".wpsm-gridder-show").remove(); 105 106 107 /* ADD CLASS TO THE GRIDDER CONTAINER 108 * So you can apply global style when item selected. 109 */ 110 if (!_this.hasClass("hasSelectedItem")) { 111 _this.addClass("hasSelectedItem"); 112 } 113 114 /* ADD LOADING BLOC */ 115 var $htmlcontent = $("<div class=\"wpsm-gridder-show loading\"></div>"); 116 mybloc = $htmlcontent.insertAfter(myself); 117 118 /* GET CONTENT VIA AJAX OR #ID*/ 119 var thecontent = ""; 120 121 if( myself.data("griddercontent").indexOf("#") === 0 ) { 122 123 // Load #ID Content 124 thecontent = $(myself.data("griddercontent")).html(); 125 processContent(myself, thecontent); 126 }else{ 127 128 // Load AJAX Content 129 $.ajax({ 130 type: "GET", 131 url: myself.data("griddercontent"), 132 success: function(data) { 133 thecontent = data; 134 processContent(myself, thecontent); 135 }, 136 error: function (request) { 137 thecontent = request.responseText; 138 processContent(myself, thecontent); 139 } 140 }); 141 } 142 } 143 144 // PROCESS CONTENT 145 function processContent(myself, thecontent){ 146 147 /* FORMAT OUTPUT */ 148 var htmlcontent = "<div class=\"wpsm-gridder-padding\">"; 149 150 if(settings.showNav){ 151 152 /* CHECK IF PREV AND NEXT BUTTON HAVE ITEMS */ 153 var prevItem = ($(".selectedItem").prev()); 154 var nextItem = ($(".selectedItem").next().next()); 155 156 htmlcontent += "<div class=\"wpsm-gridder-navigation\">"; 157 htmlcontent += "<a href=\"#\" class=\"gridder-nav prev "+(!prevItem.length?"disabled":"")+"\">"+settings.prevText+"</a>"; 158 htmlcontent += "<a href=\"#\" class=\"gridder-nav next "+(!nextItem.length?"disabled":"")+"\">"+settings.nextText+"</a>"; 159 htmlcontent += "<a href=\"#\" class=\"gridder-close\">"+settings.closeText+"</a>"; 160 htmlcontent += "</div>"; 161 } 162 163 htmlcontent += "<div class=\"wpsm-expanded-content\">"; 164 htmlcontent += thecontent; 165 htmlcontent += "</div>"; 166 htmlcontent += "</div>"; 167 168 // IF EXPANDER IS ALREADY EXPANDED 169 if (!visible) { 170 mybloc.hide().append(htmlcontent).slideDown(settings.animationSpeed, settings.animationEasing, function () { 171 visible = true; 172 /* AFTER EXPAND CALLBACK */ 173 if ($.isFunction(settings.onContent)) { 174 settings.onContent(mybloc); 175 } 176 }); 177 } else { 178 mybloc.html(htmlcontent); 179 mybloc.find(".wpsm-gridder-padding").fadeIn(settings.animationSpeed, settings.animationEasing, function () { 180 visible = true; 181 /* CHANGED CALLBACK */ 182 if ($.isFunction(settings.onContent)) { 183 settings.onContent(mybloc); 184 } 185 }); 186 } 187 188 /* SCROLL TO CORRECT POSITION AFTER */ 189 if (settings.scroll) { 190 var offset = (settings.scrollTo === "panel" ? myself.offset().top + myself.height() - settings.scrollOffset : myself.offset().top - settings.scrollOffset); 191 $("html, body").animate({ 192 scrollTop: offset 193 }, { 194 duration: settings.animationSpeed, 195 easing: settings.animationEasing 196 }); 197 } 198 199 /* REMOVE LOADING CLASS */ 200 mybloc.removeClass("loading"); 201 } 202 203 /* CLICK EVENT */ 204 _this.on("click", ".gridder-list", function (e) { 205 e.preventDefault(); 206 var myself = $(this); 207 openExpander(myself); 208 }); 209 210 /* NEXT BUTTON */ 211 _this.on("click", ".gridder-nav.next", function(e) { 212 e.preventDefault(); 213 $(this).parents(".wpsm-gridder-show").next().trigger("click"); 214 }); 215 216 /* PREVIOUS BUTTON */ 217 _this.on("click", ".gridder-nav.prev", function(e) { 218 e.preventDefault(); 219 $(this).parents(".wpsm-gridder-show").prev().prev().trigger("click"); 220 }); 221 222 /* CLOSE BUTTON */ 223 _this.on("click", ".gridder-close", function(e) { 224 e.preventDefault(); 225 closeExpander(_this); 226 }); 227 }); 228 }; 229 230 // Default Options 231 $.fn.gridderExpander.defaults = { 232 scroll: true, 233 scrollOffset: 30, 234 scrollTo: "panel", // panel or listitem 235 animationSpeed: 400, 236 animationEasing: "easeInOutExpo", 237 showNav: true, 238 nextText: "Next", 239 prevText: "Previous", 240 closeText: "Close", 241 onStart: function(){}, 242 onContent: function(){}, 243 onClosed: function(){} 244 }; 245 246 $('.gridder a').click(function(e) { 247 event.stopPropagation(); 248 }); 249 250})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.