1"use strict"; 2 3var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 4 5function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 6 7/* Generated by CoffeeScript 2.0.1*/ 8(function () { 9 /* Image Picker source*/ 10 /* by Rodrigo Vera*/ 11 12 var ImagePicker, 13 ImagePickerOption, 14 both_array_are_equal, 15 sanitized_options, 16 indexOf = [].indexOf; 17 18 jQuery.fn.extend({ 19 imagepicker: function imagepicker() { 20 var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 21 22 return this.each(function () { 23 var select; 24 select = jQuery(this); 25 if (select.data("picker")) { 26 select.data("picker").destroy(); 27 } 28 select.data("picker", new ImagePicker(this, sanitized_options(opts))); 29 if (opts.initialized != null) { 30 return opts.initialized.call(select.data("picker")); 31 } 32 }); 33 } 34 }); 35 36 sanitized_options = function sanitized_options(opts) { 37 var default_options; 38 default_options = { 39 hide_select: true, 40 show_label: false, 41 initialized: void 0, 42 changed: void 0, 43 clicked: void 0, 44 selected: void 0, 45 limit: void 0, 46 limit_reached: void 0, 47 font_awesome: false 48 }; 49 return jQuery.extend(default_options, opts); 50 }; 51 52 both_array_are_equal = function both_array_are_equal(a, b) { 53 var i, j, len, x; 54 if (!a || !b || a.length !== b.length) { 55 return false; 56 } 57 a = a.slice(0); 58 b = b.slice(0); 59 a.sort(); 60 b.sort(); 61 for (i = j = 0, len = a.length; j < len; i = ++j) { 62 x = a[i]; 63 if (b[i] !== x) { 64 return false; 65 } 66 } 67 return true; 68 }; 69 70 ImagePicker = function () { 71 function ImagePicker(select_element) { 72 var opts1 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 73 74 _classCallCheck(this, ImagePicker); 75 76 this.sync_picker_with_select = this.sync_picker_with_select.bind(this); 77 this.opts = opts1; 78 this.select = jQuery(select_element); 79 this.multiple = this.select.attr("multiple") === "multiple"; 80 if (this.select.data("limit") != null) { 81 this.opts.limit = parseInt(this.select.data("limit")); 82 } 83 this.build_and_append_picker(); 84 } 85 86 _createClass(ImagePicker, [{ 87 key: "destroy", 88 value: function destroy() { 89 var j, len, option, ref; 90 ref = this.picker_options; 91 for (j = 0, len = ref.length; j < len; j++) { 92 option = ref[j]; 93 option.destroy(); 94 } 95 this.picker.remove(); 96 this.select.off("change", this.sync_picker_with_select); 97 this.select.removeData("picker"); 98 return this.select.show(); 99 } 100 }, { 101 key: "build_and_append_picker", 102 value: function build_and_append_picker() { 103 if (this.opts.hide_select) { 104 this.select.hide(); 105 } 106 this.select.on("change", this.sync_picker_with_select); 107 if (this.picker != null) { 108 this.picker.remove(); 109 } 110 this.create_picker(); 111 this.select.after(this.picker); 112 return this.sync_picker_with_select(); 113 } 114 }, { 115 key: "sync_picker_with_select", 116 value: function sync_picker_with_select() { 117 var j, len, option, ref, results; 118 ref = this.picker_options; 119 results = []; 120 for (j = 0, len = ref.length; j < len; j++) { 121 option = ref[j]; 122 if (option.is_selected()) { 123 results.push(option.mark_as_selected()); 124 } else { 125 results.push(option.unmark_as_selected()); 126 } 127 } 128 return results; 129 } 130 }, {
131 key: "create_picker", 132 value: function create_picker() { 133 this.picker = jQuery("<ul class='thumbnails image_picker_selector'></ul>"); 134 this.picker_options = []; 135 this.recursively_parse_option_groups(this.select, this.picker); 136 return this.picker; 137 } 138 }, { 139 key: "recursively_parse_option_groups", 140 value: function recursively_parse_option_groups(scoped_dom, target_container) { 141 var container, j, k, len, len1, option, option_group, ref, ref1, results; 142 ref = scoped_dom.children("optgroup"); 143 for (j = 0, len = ref.length; j < len; j++) { 144 option_group = ref[j]; 145 option_group = jQuery(option_group); 146 container = jQuery("<ul></ul>"); 147 container.append(jQuery("<li class='group_title'>" + option_group.attr("label") + "</li>")); 148 target_container.append(jQuery("<li class='group'>").append(container)); 149 this.recursively_parse_option_groups(option_group, container); 150 } 151 ref1 = function () { 152 var l, len1, ref1, results1; 153 ref1 = scoped_dom.children("option"); 154 results1 = []; 155 for (l = 0, len1 = ref1.length; l < len1; l++) { 156 option = ref1[l]; 157 results1.push(new ImagePickerOption(option, this, this.opts)); 158 } 159 return results1; 160 }.call(this); 161 results = []; 162 for (k = 0, len1 = ref1.length; k < len1; k++) { 163 option = ref1[k]; 164 this.picker_options.push(option); 165 if (!option.has_image()) { 166 continue; 167 } 168 results.push(target_container.append(option.node)); 169 } 170 return results; 171 } 172 }, { 173 key: "has_implicit_blanks", 174 value: function has_implicit_blanks() { 175 var option; 176 return function () { 177 var j, len, ref, results; 178 ref = this.picker_options; 179 results = []; 180 for (j = 0, len = ref.length; j < len; j++) { 181 option = ref[j]; 182 if (option.is_blank() && !option.has_image()) { 183 results.push(option); 184 } 185 } 186 return results; 187 }.call(this).length > 0; 188 } 189 }, { 190 key: "selected_values", 191 value: function selected_values() { 192 if (this.multiple) { 193 return this.select.val() || []; 194 } else { 195 return [this.select.val()]; 196 } 197 } 198 }, { 199 key: "toggle", 200 value: function toggle(imagepicker_option, original_event) { 201 var new_values, old_values, selected_value; 202 old_values = this.selected_values(); 203 selected_value = imagepicker_option.value().toString(); 204 if (this.multiple) { 205 if (indexOf.call(this.selected_values(), selected_value) >= 0) { 206 new_values = this.selected_values(); 207 new_values.splice(jQuery.inArray(selected_value, old_values), 1); 208 this.select.val([]); 209 this.select.val(new_values); 210 } else { 211 if (this.opts.limit != null && this.selected_values().length >= this.opts.limit) { 212 if (this.opts.limit_reached != null) { 213 this.opts.limit_reached.call(this.select); 214 } 215 } else { 216 this.select.val(this.selected_values().concat(selected_value)); 217 } 218 } 219 } else { 220 if (this.has_implicit_blanks() && imagepicker_option.is_selected()) { 221 this.select.val(""); 222 } else { 223 this.select.val(selected_value); 224 } 225 } 226 if (!both_array_are_equal(old_values, this.selected_values())
226) { 227 this.select.change(); 228 if (this.opts.changed != null) { 229 return this.opts.changed.call(this.select, old_values, this.selected_values(), original_event); 230 } 231 } 232 } 233 }]); 234 235 return ImagePicker; 236 }(); 237 238 ImagePickerOption = function () { 239 function ImagePickerOption(option_element, picker) { 240 var opts1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 241 242 _classCallCheck(this, ImagePickerOption); 243 244 this.clicked = this.clicked.bind(this); 245 this.picker = picker; 246 this.opts = opts1; 247 this.option = jQuery(option_element); 248 this.create_node(); 249 } 250 251 _createClass(ImagePickerOption, [{ 252 key: "destroy", 253 value: function destroy() { 254 return this.node.find(".thumbnail").off("click", this.clicked); 255 } 256 }, { 257 key: "has_image", 258 value: function has_image() { 259 return this.option.data("img-src") != null; 260 } 261 }, { 262 key: "is_blank", 263 value: function is_blank() { 264 return !(this.value() != null && this.value() !== ""); 265 } 266 }, { 267 key: "is_selected", 268 value: function is_selected() { 269 var select_value; 270 select_value = this.picker.select.val(); 271 if (this.picker.multiple) { 272 return jQuery.inArray(this.value(), select_value) >= 0; 273 } else { 274 return this.value() === select_value; 275 } 276 } 277 }, { 278 key: "mark_as_selected", 279 value: function mark_as_selected() { 280 return this.node.find(".thumbnail").addClass("selected"); 281 } 282 }, { 283 key: "unmark_as_selected", 284 value: function unmark_as_selected() { 285 return this.node.find(".thumbnail").removeClass("selected"); 286 } 287 }, { 288 key: "value", 289 value: function value() { 290 return this.option.val(); 291 } 292 }, { 293 key: "label", 294 value: function label() { 295 if (this.option.data("img-label")) { 296 return this.option.data("img-label"); 297 } else { 298 return this.option.text(); 299 } 300 } 301 }, { 302 key: "clicked", 303 value: function clicked(event) { 304 305 /*DEVMAN - Reset options if someone clicked on disabled.*/ 306 if(this.node.hasClass('disabled')) { 307 if(!$('a#reset_options').is(':visible')) { 308 $('a#reset_options').click(); 309 } else { 310 return false; 311 } 312 313 } 314 315 this.picker.toggle(this, event); 316 if (this.opts.clicked != null) { 317 this.opts.clicked.call(this.picker.select, this, event); 318 } 319 if (this.opts.selected != null && this.is_selected()) { 320 return this.opts.selected.call(this.picker.select, this, event); 321 } 322 } 323 }, { 324 key: "create_node", 325 value: function create_node() { 326 var image, imgAlt, imgClass, thumbnail; 327 this.node = jQuery("<li/>"); 328 /* font-awesome support*/ 329 if (this.option.data("font_awesome")) { 330 image = jQuery("<i>"); 331 image.attr("class", "fa-fw " + this.option.data("img-src")); 332 } else { 333 image = jQuery("<img class='image_picker_image'/>"); 334 image.attr("src", this.option.data("img-src")); 335 } 336 thumbnail = jQuery("<div class='thumbnail'>"); 337 /* Add custom class*/ 338 imgClass = this.option.data("img-class"); 339 if (imgClass) { 340 this.node.addClass(imgClass); 341 image.addClass(imgClass); 342 thumbnail.addClass(imgClass); 343 } 344 /* Add image alt*/ 345 imgAlt = this.option.data("img-alt"); 346 if (imgAlt) { 347 image.attr('alt', imgAlt); 348 } 349 thumbnail.on("click", this.clicked); 350 thumbnail.append(image); 351 if (this.opts.show_label) { 352 thumbnail.append(jQuery("<p/>").html(this.label())); 353 } 354 this.node.append(thumbnail); 355 return this.node; 356 } 357 }]); 358 359 return ImagePickerOption; 360 }(); 361}).call(undefined); 362 363var replaceElements = function(image, text){ 364 var attrs = { }; 365 366 $.each($(image)[0].attributes, function(idx, attr) { 367 attrs[attr.nodeName] = attr.nodeValue; 368 }); 369 370 $(image).replaceWith(function () { 371 var elem = $("<span />", attrs).append($(this).contents()); 372 elem.text(text); 373 return elem; 374 }); 375}; 376 377function option_combinations_transform_bullets() { 378 $('select[id^="input-option-bullet-"]').each(function(){ 379 var select = $(this); 380 if(select.css('display') != 'none') { 381 $(this).imagepicker({ 382 initialized: function () { 383 /* hack for include images alt message as title and replace images with text only*/ 384 /* because lib does not allow to include directly*/ 385 select.next('ul').find('img.image_picker_image.opt-as-bullet').each(function () { 386 var image = $(this); 387 image.attr('title', image.attr('alt')); 388 if (!image.attr('src') || image.hasClass('type_3')) { 389 var val = image.attr('alt').split(': '); 390 val.shift(); 391 replaceElements(this, val.join(': ')); 392 } 393 }); 394 395 /* set minimal width equal as height*/ 396 select.next('ul').find('span.image_picker_image.opt-as-bullet').each(function () { 397 $(this).parent().css("min-width", $(this).parent().outerHeight() + "px"); 398 }); 399 400 if(typeof extend_option_combinations_transform_bullets == 'function') { 401 extend_option_combinations_transform_bullets(select.next('ul')); 402 } 403 }, 404 selected: function (select, option, event) { 405 var image = $(this).find(':selected').data('card-image'); 406 407 //If image is "no-image" return false. 408 if (image.indexOf("placeholder-") >= 0 || image.indexOf("no_image-") >= 0) 409 return false;
410 411 if($(this).closest('.product-thumb').find('img.img-responsive').length) 412 var main_image = $(this).closest('.product-thumb').find('img.img-responsive'); 413 else if($(this).closest('.product-thumb').find('img.first-image').length) 414 var main_image = $(this).closest('.product-thumb').find('img.first-image'); 415 else if($(this).closest('.product-wrapper').find('img.first-image').length) 416 var main_image = $(this).closest('.product-wrapper').find('img.first-image'); 417 else { 418 console.error("Main image for replace not found. image-picker.min.js"); 419 return false; 420 } 421 422 main_image.attr('src', image); 423 424 var image2x = $(this).find(':selected').data('card-image2x'); 425 if(typeof image2x != 'undefined') 426 main_image.attr('srcset', image + ' 1x, ' + image2x + ' 2x'); 427 428 //Second image on hover, for some themes like journal 2 429 if(main_image.parent().hasClass('has-second-image')) { 430 main_image.parent().css("background", "url("+image+") no-repeat"); 431 } 432 } 433 }); 434 } 435 }); 436} 437 438$(function(){ 439 if($('select[id^="input-option-bullet-"]').length > 0) 440 option_combinations_transform_bullets(); 441});
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.