1(function ($, Drupal) { 2 "use strict"; 3 4 function BoxEffectsClass(opt) { 5 var options = { 6 container: 7 opt && opt.container 8 ? opt.container 9 : ".box-effects-wrapper.enable-effects", 10 item: opt && opt.item ? opt.item : ".box-pattern", 11 portraitClass: opt && opt.portraitClass ? opt.portraitClass : "portrait", 12 singleClass: opt && opt.singleClass ? opt.singleClass : "simple-display", 13 landscapeClass: 14 opt && opt.landscapeClass ? opt.landscapeClass : "landscape", 15 }; 16 17 var lastColumn = 3; 18 var columnWidth = 0; 19 var thisClass = this; 20 21 /** 22 * INIT METHOD 23 */ 24 this.init = function () { 25 var toID = null; 26 if (jQuery(window).width() >= 992) { 27 this.prepareCards(); 28 this.prepareEffects(); 29 } 30 setTimeout(function () { 31 thisClass.resizeAdjusts(); 32 }, 1000); 33 jQuery(window).resize(function () { 34 if (jQuery(window).width() >= 992) { 35 if (toID) { 36 clearTimeout(toID); 37 } 38 toID = setTimeout(function () { 39 thisClass.prepareCards(); 40 thisClass.prepareEffects(); 41 }, 1000); 42 } 43 thisClass.resizeAdjusts(); 44 }); 45 }; 46 47 /** 48 * ADD CLASSES AND ATTRIBUTES 49 */ 50 this.prepareCards = function () { 51 var col = 1; 52 var row = 1; 53 var prevPos = { top: 0, left: 0 }; 54 jQuery(options.container).each(function () { 55 col = 1; 56 row = 1; 57 prevPos = jQuery(this) 58 .find(" > " + options.item + ":first-child") 59 .position(); 60 jQuery(this) 61 .find(" > " + options.item) 62 .each(function () { 63 thisClass.cleanAttributes(jQuery(this)); 64 var currentPos = jQuery(this).position(); 65 if (currentPos.top > prevPos.top) { 66 row += 1; 67 } 68 if (currentPos.left > prevPos.left) { 69 col += 1; 70 } 71 if (currentPos.left < prevPos.left) { 72 col -= 1; 73 } 74 if (currentPos.left == 0) { 75 col = 1; 76 } 77 jQuery(this).data("col", col); 78 jQuery(this).data("row", row); 79 jQuery(this).addClass("box-col-" + col); 80 jQuery(this).addClass("box-row-" + row); 81 prevPos = jQuery(this).position(); 82 if (columnWidth == 0) { 83 columnWidth = jQuery(this).width(); 84 } 85 }); 86 }); 87 }; 88 89 /** 90 * CLEAR CLASSES AND ATTRIBUTES 91 * @param {*} item 92 */ 93 this.cleanAttributes = function (item) { 94 item.removeAttr("data-col"); 95 item.removeAttr("data-row"); 96 item.removeClass("box-force-full-width"); 97 item.removeClass(function (index, className) { 98 return (className.match(/(^|\s)box-col-\S+/g) || []).join(" "); 99 }); 100 item.removeClass(function (index, className) { 101 return (className.match(/(^|\s)box-row-\S+/g) || []).join(" "); 102 }); 103 }; 104 105 /** 106 * FILL GAPS IN MOBILE DEVICES 107 */ 108 this.resizeAdjusts = function () { 109 jQuery(".box-effects-wrapper").each(function () { 110 var firstPos = jQuery(this) 111 .find(" > " + options.item + ":first-child") 112 .position(); 113 var prevBox = null; 114 jQuery(this) 115 .find(" > " + options.item) 116 .each(function () { 117 jQuery(this).removeClass("box-force-full-width"); 118 }); 119 jQuery(this) 120 .find(" > " + options.item) 121 .each(function () { 122 var containerWidth = jQuery(this) 123 .closest(".box-effects-wrapper") 124 .width(); 125 if (jQuery(this).position().left == 0) { 126 if (prevBox != null && prevBox.position().left == 0) { 127 if (prevBox.width() < containerWidth * 0.6) { 128 prevBox.addClass("box-force-full-width"); 129 } 130 } 131 } 132 if (jQuery(this).is(":last-child")) { 133 if (jQuery(this).position().left == firstPos.left) { 134 if (jQuery(this).width() < containerWidth * 0.6) { 135 jQuery(this).addClass("box-force-full-width"); 136 } 137 } 138 } 139 prevBox = jQuery(this); 140 }); 141 }); 142 }; 143 144 /** 145 * MOUSE EVENTS CONTROL 146 */
147 this.prepareEffects = function () { 148 jQuery(options.container + " > " + options.item) 149 .mouseover(function (e) { 150 var item = jQuery(this); 151 thisClass.onHover(item); 152 e.preventDefault(); 153 }) 154 .mouseout(function (e) { 155 var item = jQuery(this); 156 thisClass.onBlur(item); 157 e.preventDefault(); 158 }); 159 }; 160 161 /** 162 * ON HOVER EVENT 163 */ 164 this.onHover = function (item) { 165 var type = thisClass.getType(item); 166 var container = item.closest(options.container); 167 var affected = thisClass.affectedCards( 168 item.data("col"), 169 item.data("row"), 170 type, 171 container 172 ); 173 jQuery.each(affected.smaller, function (k, v) { 174 container.find(v).removeClass("from-bigger"); 175 container.find(v).removeClass("from-smaller"); 176 container.find(v).addClass("make-smaller"); 177 }); 178 item.removeClass("from-bigger"); 179 item.removeClass("from-smaller"); 180 item.addClass("make-bigger"); 181 jQuery.each(affected.bigger, function (k, v) { 182 container.find(v).removeClass("from-bigger"); 183 container.find(v).removeClass("from-smaller"); 184 container.find(v).addClass("make-bigger"); 185 }); 186 }; 187 188 /** 189 * ON BLUR EVENT 190 */ 191 this.onBlur = function (item) { 192 var type = thisClass.getType(item); 193 var container = item.closest(options.container); 194 var affected = thisClass.affectedCards( 195 item.data("col"), 196 item.data("row"), 197 type, 198 container 199 ); 200 jQuery.each(affected.bigger, function (k, v) { 201 container.find(v).removeClass("make-bigger"); 202 if (container.find(v) > columnWidth) { 203 container.find(v).addClass("from-bigger"); 204 } else if (container.find(v) < columnWidth) { 205 container.find(v).addClass("from-smaller"); 206 } 207 }); 208 item.removeClass("make-bigger"); 209 item.addClass("from-bigger"); 210 jQuery.each(affected.smaller, function (k, v) { 211 container.find(v).removeClass("make-smaller"); 212 if (container.find(v) > columnWidth) { 213 container.find(v).addClass("from-bigger"); 214 } else if (container.find(v) < columnWidth) { 215 container.find(v).addClass("from-smaller"); 216 } 217 }); 218 }; 219 220 /** 221 * FIND CARDS AFFECTED BY THE HOVERED OR BLURED ONE 222 */ 223 this.affectedCards = function (col, row, type, container) { 224 var returnArray = { bigger: [], smaller: [] }; 225 if (type == options.singleClass) { 226 if (col == lastColumn) { 227 returnArray.smaller.push(".box-col-" + (col - 1) + ".box-row-" + row); 228 if ( 229 container 230 .find(".box-col-" + (col - 1) + ".box-row-" + (row - 1)) 231 .hasClass(options.portraitClass) 232 ) { 233 returnArray.smaller.push( 234 ".box-col-" + (col - 1) + ".box-row-" + (row - 1) 235 ); 236 } 237 if ( 238 container 239 .find(".box-col-" + (col - 1) + ".box-row-" + row) 240 .hasClass(options.portraitClass) 241 ) { 242 returnArray.bigger.push( 243 ".box-col-" + col + ".box-row-" + (row + 1) 244 ); 245 } 246 if ( 247 container 248 .find(".box-col-" + (col - 1) + ".box-row-" + (row - 1)) 249 .hasClass(options.portraitClass) 250 ) { 251 returnArray.bigger.push( 252 ".box-col-" + col + ".box-row-" + (row - 1) 253 ); 254 } 255 } else { 256 returnArray.smaller.push(".box-col-" + (col + 1) + ".box-row-" + row); 257 if ( 258 container 259 .find(".box-col-" + (col + 1) + ".box-row-" + (row - 1)) 260 .hasClass(options.portraitClass) 261 ) { 262 returnArray.smaller.push( 263 ".box-col-" + (col + 1) + ".box-row-" + (row - 1) 264 ); 265 } 266 } 267 } 268 if (type == options.portraitClass) { 269 if (col == lastColumn) { 270 returnArray.smaller.push(".box-col-" + (col - 1) + ".box-row-" + row); 271 returnArray.smaller.push( 272 ".box-col-" + (col - 1) + ".box-row-" + (row + 1) 273 ); 274 } else { 275 returnArray.smaller.push(".box-col-" + (col + 1) + ".box-row-" + row); 276 returnArray.smaller.push( 277 ".box-col-" + (col + 1) + ".box-row-" + (row + 1) 278 ); 279 } 280 } 281 return returnArray; 282 }; 283 284 /** 285 * GET TYPE OF CARD 286 * @param {*} item 287 */ 288 this.getType = function (item) { 289 var type = item.hasClass(options.portraitClass) 290 ? options.portraitClass 291 : item.hasClass(options.singleClass) 292 ? options.singleClass 293 : options.landscapeClass; 294 295 return type; 296 }; 297 } 298 299 var CPreviewCardsClass = new BoxEffectsClass(); 300 jQuery(function () { 301 CPreviewCardsClass.init(); 302 }); 303})(jQuery, Drupal);
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.