1/* 2** nopCommerce custom js functions 3*/ 4 5 6 7function OpenWindow(query, w, h, scroll) { 8 var l = (screen.width - w) / 2; 9 var t = (screen.height - h) / 2; 10 11 winprops = 'resizable=0, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w'; 12 if (scroll) winprops += ',scrollbars=1'; 13 var f = window.open(query, "_blank", winprops); 14} 15 16function setLocation(url) { 17 window.location.href = url; 18} 19 20function displayAjaxLoading(display) { 21 // Fix for immediate hiding of modal 22 $("#AjaxLoadingWindowModal").on('shown.bs.modal', function () { 23 if (!display) 24 $('#AjaxLoadingWindowModal').modal('hide'); 25 }); 26 27 return display ? $('#AjaxLoadingWindowModal').modal('show') : $('#AjaxLoadingWindowModal').modal('hide'); 28} 29 30function displayPopupNotification(message, messagetype, modal) { 31 //types: success, error, warning 32 var container; 33 if (messagetype == 'success') { 34 //success 35 container = $('#dialog-notifications-success'); 36 } 37 else if (messagetype == 'error') { 38 //error 39 container = $('#dialog-notifications-error'); 40 } 41 else if (messagetype == 'warning') { 42 //warning 43 container = $('#dialog-notifications-warning'); 44 } 45 else { 46 //other 47 container = $('#dialog-notifications-success'); 48 } 49 50 //we do not encode displayed message 51 var htmlcode = ''; 52 if ((typeof message) == 'string') { 53 htmlcode = '<p>' + message + '</p>'; 54 } else { 55 for (var i = 0; i < message.length; i++) { 56 htmlcode = htmlcode + '<p>' + message[i] + '</p>'; 57 } 58 } 59 60 container.html(htmlcode); 61 62 var isModal = (modal ? true : false); 63 container.dialog({ 64 modal: isModal, 65 width: 350 66 }); 67} 68 69function displayModalNotification(message) { 70 var htmlcode = ''; 71 if ((typeof message) == 'string') { 72 htmlcode = '<p>' + message + '</p>'; 73 } else { 74 for (var i = 0; i < message.length; i++) { 75 htmlcode = htmlcode + '<p>' + message[i] + '</p>'; 76 } 77 } 78 var container = $('#AjaxErrorWindowModal #AjaxErrorWindowContent'); 79 container.html(htmlcode); 80 $("#AjaxErrorWindowModal").on('hidden.bs.modal', function () { 81 container.html(''); 82 }); 83 $("#AjaxErrorWindowModal").modal('show'); 84} 85 86function displayJoinedPopupNotifications(notes) { 87 if (Object.keys(notes).length === 0) return; 88 89 var container = $('#dialog-notifications-success'); 90 var htmlcode = document.createElement('div'); 91 92 for (var note in notes) { 93 if (notes.hasOwnProperty(note)) { 94 var messages = notes[note]; 95 96 for (var i = 0; i < messages.length; ++i) { 97 var elem = document.createElement("div"); 98 elem.innerHTML = messages[i]; 99 elem.classList.add('popup-notification'); 100 elem.classList.add(note); 101 102 htmlcode.append(elem); 103 } 104 } 105 } 106 107 container.html(htmlcode); 108 container.dialog({ 109 width: 350, 110 modal: true 111 }); 112} 113function displayPopupContentFromUrl(url, title, modal, width) { 114 var isModal = (modal ? true : false); 115 var targetWidth = (width ? width : 550); 116 var maxHeight = $(window).height() - 20; 117 118 $('<div></div>').load(url) 119 .dialog({ 120 modal: isModal, 121 width: targetWidth, 122 maxHeight: maxHeight, 123 title: title, 124 close: function(event, ui) { 125 $(this).dialog('destroy').remove(); 126 } 127 }); 128} 129 130function displayBarNotification(message, messagetype, timeout) { 131 var notificationTimeout; 132 133 var messages = typeof message === 'string' ? [message] : message; 134 if (messages.length === 0) 135 return; 136 137 if (messagetype === 'error' && messages.length) { 138 displayModalNotification(messages); 139 return; 140 } 141 142 //types: success, error, warning 143 var cssclass = ['success', 'error', 'warning'].indexOf(messagetype) !== -1 ? messagetype : 'success'; 144 145 //remove previous CSS classes and notifications 146 $('#bar-notification') 147 .removeClass('success') 148 .removeClass('error') 149 .removeClass('warning'); 150 $('.bar-notification').remove(); 151 152 //add new notifications 153 var htmlcode = document.createElement('div'); 154 155 //IE11 Does not support miltiple parameters for the add() & remove() methods 156 htmlcode.classList.add('bar-notification', cssclass); 157 htmlcode.classList.add(cssclass); 158 159 //add close button for notification 160 var close = document.createElement('span'); 161 close.classList.add('close'); 162 close.setAttribute('title', document.getElementById('bar-notification').dataset.close); 163 164 for (var i = 0; i < messages.length; i++) { 165 var content = document.createElement('p'); 166 content.classList.add('content'); 167 content.innerHTML = messages[i]; 168 169 htmlcode.appendChild(content); 170 } 171 172 htmlcode.appendChild(close); 173 174 $('#bar-notification') 175 .append(htmlcode); 176 177 $(htmlcode) 178 .fadeIn('slow') 179 .on('mouseenter', function() { 180 clearTimeout(notificationTimeout); 181 }); 182 183 //callback for notification removing 184 var removeNoteItem = function () { 185 $(htmlcode).remove(); 186 }; 187 188 $(close).on('click', function () { 189 $(htmlcode).fadeOut('slow', removeNoteItem); 190 }); 191 192 //timeout (if set) 193 if (timeout > 0) { 194 notificationTimeout = setTimeout(function () { 195 $(htmlcode).fadeOut('slow', removeNoteItem); 196 }, timeout); 197 } 198} 199 200function htmlEncode(value) { 201 return $('<div/>').text(value).html(); 202} 203 204function htmlDecode(value) { 205 return $('<div/>').html(value).text(); 206} 207 208 209// CSRF (XSRF) security 210function addAntiForgeryToken(data) { 211 //if the object is undefined, create a new one. 212 if (!data) { 213 data = {}; 214 } 215 //add token 216 var tokenInput = $('input[name=__RequestVerificationToken]'); 217 if (tokenInput.length) { 218 data.__RequestVerificationToken = tokenInput.val(); 219 } 220 return data; 221}; 222
223// Product - Menu back link with scroll position memory using sessionStorage 224function activateProductHistoryApi() { 225 $('.js-product-link').on('click', function () { 226 var path = window.location.pathname; 227 sessionStorage.setItem('useHistoryApiProduct', path); 228 }); 229 230 $('.html-product-details-page .js-back-link, .html-product-details-page .js-cancel-btn').on('click', function (event) { 231 redirectWithHistoryApi(event); 232 }); 233} 234 235function redirectWithHistoryApi(event, url) { 236 if (sessionStorage.getItem('useHistoryApiProduct') === null) return; 237 if (url) { 238 return window.history.back(); 239 } 240 event.preventDefault(); 241 window.history.back(); 242} 243 244function connectionSlow() { 245 if (!navigator.connection) return false; // Safari doesn't support navigator.connection, assume a fast connection (loading modals not displayed) 246 return ['slow-2g', '2g', '3g'].includes(navigator.connection.effectiveType); 247} 248 249 250// Init 251$(document).ready(function () { 252 activateProductHistoryApi(); 253});
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.