global.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /**
  2. * @version 7.10 [rev.7.10.03]
  3. */
  4. (function ($) {
  5. // postage calculator jquery plugin
  6. $.fn.calculatePostage = function (data) {
  7. // the data that will be used by the function to output the postage options
  8. var settings = $.extend({
  9. selector: null,
  10. btn: null,
  11. postUrl: null,
  12. ids: null,
  13. quantity: null,
  14. locationId: null,
  15. postCode: null,
  16. postageId: null,
  17. enableSelection: null
  18. }, data);
  19. if (settings.btn !== null) {
  20. settings.btn.button('loading');
  21. }
  22. // shortcut method
  23. if (settings.selector !== null) {
  24. // no overrides for the settings
  25. if (settings.ids === null) {
  26. settings.ids = $(settings.selector).find('.ids').map(function () {
  27. return $(this).val();
  28. }).get();
  29. }
  30. if (settings.quantity === null) {
  31. settings.quantity = $(settings.selector).find('.qty').map(function () {
  32. return $(this).val();
  33. }).get();
  34. }
  35. if (settings.locationId === null) {
  36. settings.locationId = $(settings.selector).find('select[name="locationId"]').val();
  37. }
  38. if (settings.postCode === null) {
  39. settings.postCode = $(settings.selector).find('input[name="postCode"]').val();
  40. }
  41. if (settings.enableSelection === null) {
  42. settings.enableSelection = $(settings.selector).find('input[name="enableSelection"]').val();
  43. }
  44. if (settings.postageId === null) {
  45. settings.postageId = $(settings.selector).find('input[name="postage_id"]').val();
  46. }
  47. }
  48. var selector = this;
  49. $.post(
  50. settings.postUrl,
  51. {
  52. ids: settings.ids,
  53. quantity: settings.quantity,
  54. locationId: settings.locationId,
  55. postCode: settings.postCode,
  56. enableSelection: settings.enableSelection,
  57. postageId: settings.postageId
  58. },
  59. function (data) {
  60. if (settings.btn !== null) {
  61. setTimeout(function () {
  62. settings.btn.button('reset')
  63. }, 500);
  64. }
  65. return selector.each(function () {
  66. selector.html(data);
  67. });
  68. }
  69. );
  70. }
  71. })(jQuery);
  72. jQuery(document).ready(function ($) {
  73. $('.alert-box').on('blur', function (e) {
  74. e.preventDefault();
  75. var message = $(this).attr('data-message');
  76. bootbox.alert(message);
  77. });
  78. $('.dialog-box').on('click', function (e) {
  79. e.preventDefault();
  80. var href = $(this).attr('href');
  81. var title = $(this).attr('title');
  82. $.get(href, function (data) {
  83. bootbox.dialog({
  84. title: title,
  85. message: data,
  86. buttons: {
  87. main: {
  88. label: msgs.close,
  89. className: "btn-default"
  90. }
  91. }
  92. });
  93. });
  94. });
  95. $('.confirm-box').on('click', function (e) {
  96. e.preventDefault();
  97. var href = $(this).attr('href');
  98. var message = msgs.confirmThisAction;
  99. if ($(this).attr('data-message')) {
  100. message = $(this).attr('data-message');
  101. }
  102. bootbox.confirm({
  103. buttons: {
  104. confirm: {
  105. label: msgs.ok,
  106. className: "btn-primary"
  107. },
  108. cancel: {
  109. label: msgs.cancel,
  110. className: "btn-default"
  111. }
  112. },
  113. message: message,
  114. callback: function (result) {
  115. if (result) {
  116. window.location.replace(href);
  117. }
  118. }
  119. // title: "You can also add a title"
  120. });
  121. });
  122. $('.confirm-form').on('click', function (e) {
  123. e.preventDefault();
  124. var message = msgs.confirmThisAction;
  125. if ($(this).attr('data-message')) {
  126. message = $(this).attr('data-message');
  127. }
  128. var option = $(this).val();
  129. var form = $(this).closest('form');
  130. bootbox.confirm({
  131. buttons: {
  132. confirm: {
  133. label: msgs.ok,
  134. className: "btn-primary"
  135. },
  136. cancel: {
  137. label: msgs.cancel,
  138. className: "btn-default"
  139. }
  140. },
  141. message: message,
  142. callback: function (result) {
  143. if (result) {
  144. form.find('[name="option"]').val(option);
  145. form.submit();
  146. }
  147. }
  148. // title: "You can also add a title"
  149. });
  150. });
  151. // checkboxes - select all/none
  152. $('[name="selectAll"]').click(function () {
  153. var checked = $(this).prop('checked');
  154. $('.select-all').prop('checked', checked);
  155. });
  156. // postage calculator from listing details page
  157. $('#calculate-postage').click(function () {
  158. $('#postage-calculator').find('.result').calculatePostage({
  159. selector: '#postage-calculator',
  160. postUrl: paths.calculatePostage,
  161. btn: $(this)
  162. });
  163. });
  164. $('.masonry').masonry({
  165. itemSelector: '.item'
  166. });
  167. // list grid cookie
  168. var cc = $.cookie('list_grid');
  169. if (cc === 'g') {
  170. $('#browse').find('.listings').find('.list').removeClass('list').addClass('grid col-sm-3 col-xs-6');
  171. } else {
  172. $('#browse').find('.listings').find('.grid').removeClass('grid col-sm-3 col-xs-6').addClass('list');
  173. }
  174. // list grid toggle
  175. $('#grid').click(function () {
  176. $('#browse').find('.listings').fadeOut(400, function () {
  177. $(this).find('.list').removeClass('list').addClass('grid col-sm-3 col-xs-6');
  178. $(this).fadeIn(400);
  179. $.cookie('list_grid', 'g', {path: baseUrl, expires: 30});
  180. });
  181. return false;
  182. });
  183. $('#list').click(function () {
  184. $('#browse').find('.listings').fadeOut(400, function () {
  185. $(this).find('.grid').removeClass('grid col-sm-3 col-xs-6').addClass('list');
  186. $(this).fadeIn(400);
  187. $.cookie('list_grid', null, {path: baseUrl});
  188. });
  189. return false;
  190. });
  191. /* sidebar nav offcanvas toggle */
  192. $('[data-toggle=offcanvas]').click(function () {
  193. $('.row-offcanvas').toggleClass('active', 400);
  194. $('footer').toggle(); // workaround for footer overlapping
  195. });
  196. /* attach loading modal behavior to button */
  197. $('.btn-loading-modal').on('click', function () {
  198. $('body').addClass('loading');
  199. });
  200. if (!modRewrite) {
  201. // workaround for posting get forms when mod rewrite is not available
  202. $('form').submit(function (e) {
  203. if ($(this).attr('method').toLowerCase() === 'get') {
  204. e.preventDefault();
  205. $(this).attr('method', 'post');
  206. $(this).submit();
  207. }
  208. });
  209. }
  210. $('pre').each(function () {
  211. $(this).text($(this).html()); //makes the html into plaintext
  212. });
  213. /* jquery table rows filter */
  214. $('.table-filter').keyup(function () {
  215. var rex = new RegExp($(this).val(), 'i');
  216. var table = $(this).closest('table');
  217. table.find('.searchable tr').hide();
  218. table.find('.searchable tr').filter(function () {
  219. return rex.test($(this).text());
  220. }).show();
  221. });
  222. // @version 7.6
  223. // open form in a bootbox modal
  224. $('.jq-popup-form').on('click', function (e) {
  225. e.preventDefault();
  226. $('body').addClass('loading');
  227. var title = $(this).attr('title');
  228. var onCloseRedirect = $(this).attr('data-close-redirect');
  229. var url = null;
  230. var method = 'GET';
  231. var data = null;
  232. if ($(this).is(':submit')) {
  233. var form = $(this).closest('form');
  234. var formMethod = form.attr('method');
  235. if (formMethod !== '' && $.type(formMethod) !== 'undefined') {
  236. method = formMethod;
  237. }
  238. url = $(this).attr('formaction');
  239. if (url === '' || $.type(url) === 'undefined') {
  240. url = form.attr('action');
  241. }
  242. data = form.serialize();
  243. }
  244. else {
  245. url = $(this).attr('href');
  246. }
  247. $.ajax({
  248. url: url,
  249. data: data,
  250. method: method,
  251. success: function (data) {
  252. bootbox.dialog({
  253. title: title,
  254. message: data,
  255. closeButton: false,
  256. buttons: {
  257. main: {
  258. label: msgs.close,
  259. className: "btn-default",
  260. callback: function () {
  261. if (onCloseRedirect !== '' && $.type(onCloseRedirect) !== 'undefined') {
  262. $('body').addClass('loading');
  263. window.location.reload(onCloseRedirect);
  264. }
  265. }
  266. }
  267. }
  268. });
  269. $('body').removeClass('loading');
  270. }
  271. });
  272. });
  273. // full size images gallery
  274. $('.jq-gallery').magnificPopup({
  275. type: 'image',
  276. gallery: {
  277. enabled: true
  278. }
  279. });
  280. // ajax load pages in popup - use href as ajax load destination
  281. $('.ajax-popup').magnificPopup({
  282. type: 'ajax'
  283. });
  284. // workaround so that slides do not display unless the slick slider library has been loaded
  285. $('.jq-loading-slider')
  286. .on('init', function (slick) {
  287. $(this).find('.jq-slide').removeClass('hidden');
  288. });
  289. // slick carousel implementation for the listing details page main image and thumbnails
  290. $('#jq-mainImage')
  291. .slick({
  292. slidesToShow: 1,
  293. slidesToScroll: 1,
  294. arrows: false,
  295. asNavFor: '#jq-thumbnails'
  296. })
  297. .find('img')
  298. .on('click', function () {
  299. var thumbId = $(this).attr('data-gallery-id');
  300. $('.jq-gallery').eq(thumbId).trigger('click');
  301. });
  302. $('#jq-thumbnails')
  303. .slick({
  304. slidesToShow: 4,
  305. slidesToScroll: 4,
  306. asNavFor: '#jq-mainImage',
  307. dots: true,
  308. arrows: false,
  309. focusOnSelect: true
  310. });
  311. // slick carousel implementation for home page slider
  312. $('.jq-slider')
  313. .slick({
  314. dots: true,
  315. arrows: false,
  316. autoplay: true
  317. });
  318. // left side search checkboxes - submit on click
  319. $('#left-side-search').find('input[type="checkbox"]').on('click', function () {
  320. $(this).closest('form').trigger('submit');
  321. });
  322. // left side and mobile search boxes
  323. $('.btn-icon-search').on('click', function () {
  324. $(this).closest('form').trigger('submit');
  325. });
  326. // if submitting the header search form with only a category selected and no keywords, change the submission url
  327. // to the category's url
  328. $('#form-header-search').on('submit', function (e) {
  329. var srcForm = $(this).closest('form');
  330. var keywords = srcForm.find('input[name="keywords"]').val();
  331. if (keywords === '') {
  332. var parentId = srcForm.find('input[name="parent_id"]').val();
  333. if (parentId !== '') {
  334. var category = srcForm.find('[data-id=' + parentId + ']');
  335. if (category !== undefined) {
  336. var href = category.attr('href');
  337. if (href !== '' && href !== undefined) {
  338. e.preventDefault();
  339. window.location.replace(href);
  340. }
  341. }
  342. }
  343. }
  344. })
  345. });