PluginProbe
PostNL for WooCommerce / 2.5.1
PostNL for WooCommerce v2.5.1
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / assets / delivery-options / js / postnl.js

postnl.js in PostNL for WooCommerce 2.5.1, at assets/delivery-options/js/postnl.js

660 lines 25.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // Generated by CoffeeScript 1.10.0
2
3 /*
4 * Constants
5 */
6
7 (function() {
8 var $, AO_DEFAULT_TEXT, Application, CARRIER, DAYS_OF_THE_WEEK, DAYS_OF_THE_WEEK_TRANSLATED, DEFAULT_DELIVERY, DISABLED, EVENING_DELIVERY, HVO_DEFAULT_TEXT, MORNING_DELIVERY, MORNING_PICKUP, NATIONAL, NORMAL_PICKUP, PICKUP, PICKUP_EXPRESS, PICKUP_TIMES, POST_NL_TRANSLATION, Slider, checkCombination, displayOtherTab, jquery, obj1, orderOpeningHours, preparePickup, renderDeliveryOptions, renderExpressPickup, renderPage, renderPickup, renderPickupLocation, showDefaultPickupLocation, sortLocationsOnDistance, updateDelivery, updateInputField,
9 bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
10
11 DISABLED = 'disabled';
12
13 HVO_DEFAULT_TEXT = 'Handtekening voor ontvangst';
14
15 AO_DEFAULT_TEXT = 'Alleen geadresseerde';
16
17 NATIONAL = 'NL';
18
19 CARRIER = 1;
20
21 MORNING_DELIVERY = 'morning';
22
23 DEFAULT_DELIVERY = 'default';
24
25 EVENING_DELIVERY = 'night';
26
27 PICKUP = 'pickup';
28
29 PICKUP_EXPRESS = 'pickup_express';
30
31 POST_NL_TRANSLATION = {
32 morning: 'morning',
33 standard: 'default',
34 night: 'night'
35 };
36
37 DAYS_OF_THE_WEEK = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
38
39 DAYS_OF_THE_WEEK_TRANSLATED = ['ma', 'di', 'wo', 'do', 'vr', 'za', 'zo'];
40
41 MORNING_PICKUP = '08:30:00';
42
43 NORMAL_PICKUP = '16:00:00';
44
45 PICKUP_TIMES = (
46 obj1 = {},
47 obj1["" + MORNING_PICKUP] = 'morning',
48 obj1["" + NORMAL_PICKUP] = 'normal',
49 obj1
50 );
51
52 this.PostNL = Application = (function() {
53
54 /*
55 * Setup initial variables
56 */
57 function Application(options) {
58 var base;
59 moment.locale(NATIONAL);
60 if (window.post == null) {
61 window.post = {
62 settings: {}
63 };
64 }
65 if ((base = window.post.settings).base_url == null) {
66 base.base_url = "//localhost:8080/api/delivery_options";
67 }
68 this.el = document.getElementById('postnl');
69
70 this.$el = jquery('postnl');
71 if (this.shadow == null) {
72 this.shadow = this.el.createShadowRoot();
73 }
74 this.render();
75 this.expose(this.updatePage, 'updatePage');
76 this.expose(this, 'activeInstance');
77 }
78
79
80 /*
81 * Reloads the HTML form the template.
82 */
83
84 Application.prototype.render = function() {
85 var error, ref;
86 this.shadow.innerHTML = document.getElementById('postnl-template').innerHTML;
87 try {
88 if ((ref = WebComponents.ShadowCSS) != null) {
89 ref.shimStyling(shadow, 'postnl');
90 }
91 } catch (error) {
92 console.log('Cannot shim CSS');
93 }
94 return this.bindInputListeners();
95 };
96
97
98 /*
99 * Puts function in window.post effectively exposing the function.
100 */
101
102 Application.prototype.expose = function(fn, name) {
103 var base;
104 if ((base = window.post).fn == null) {
105 base.fn = {};
106 }
107 return window.post.fn[name] = fn;
108 };
109
110
111 /*
112 * Adds the listeners for the inputfields.
113 */
114
115 Application.prototype.bindInputListeners = function() {
116 jquery('#post-signed', parent.document).on('change', (function(_this) {
117 return function(e) {
118 return $('#post-signed', parent.document).prop('checked', jquery('#post-signed', parent.document).prop('checked'));
119 };
120 })(this));
121 jquery('#post-recipient-only', parent.document).on('change', (function(_this) {
122 return function(e) {
123 return $('#post-only-recipient', parent.document).prop('checked', jquery('#post-recipient-only', parent.document).prop('checked'));
124 };
125 })(this));
126 return jquery('#post-input').on('change', (function(_this) {
127 return function(e) {
128 var el, i, json, len, ref;
129 json = jquery('#post-input', parent.document).val();
130 if (json === '') {
131 $('input[name=post-delivery-time]:checked').prop('checked', false);
132 $('input[name=post-delivery-type]:checked').prop('checked', false);
133 return;
134 }
135 ref = $('input[name=post-delivery-time]');
136 for (i = 0, len = ref.length; i < len; i++) {
137 el = ref[i];
138 if ($(el).val() === json) {
139 $(el).prop('checked', true);
140 return;
141 }
142 }
143 };
144 })(this));
145 };
146
147
148 /*
149 * Fetches devliery options and an overall page update.
150 */
151
152 Application.prototype.updatePage = function(postal_code, number, street) {
153 var item, key, options, ref, settings, urlBase;
154 ref = window.post.settings.price;
155 for (key in ref) {
156 item = ref[key];
157 if (!(typeof item === 'string' || typeof item === 'function')) {
158 throw new Error('Price needs to be of type string');
159 }
160 }
161 settings = window.post.settings;
162 urlBase = settings.base_url;
163 if (number == null) {
164 number = settings.number;
165 }
166 if (postal_code == null) {
167 postal_code = settings.postal_code;
168 }
169 if (street == null) {
170 street = settings.street;
171 }
172 if (!((street != null) || (postal_code != null) || (number != null))) {
173 $('#post-no-options').html('Geen adres opgegeven');
174 $('.post-overlay').removeClass('post-hidden');
175 return;
176 }
177 $('#post-no-options').html('Bezig met laden...');
178 $('.post-overlay').removeClass('post-hidden');
179 $('.post-location').html(street + " " + number);
180 options = {
181 url: urlBase,
182 data: {
183 cc: NATIONAL,
184 carrier: CARRIER,
185 number: number,
186 postal_code: postal_code,
187 delivery_time: settings.delivery_time != null ? settings.delivery_time : void 0,
188 delivery_date: settings.delivery_date != null ? settings.delivery_date : void 0,
189 cutoff_time: settings.cutoff_time != null ? settings.cutoff_time : void 0,
190 dropoff_days: settings.dropoff_days != null ? settings.dropoff_days : void 0,
191 dropoff_delay: settings.dropoff_delay != null ? settings.dropoff_delay : void 0,
192 deliverydays_window: settings.deliverydays_window != null ? settings.deliverydays_window : void 0,
193 exclude_delivery_type: settings.exclude_delivery_type != null ? settings.exclude_delivery_type : void 0,
194 version: Math.random()
195 },
196 success: renderPage,
197 error: hidePostNLOptions
198 };
199 return jquery.ajax(options);
200 };
201
202 return Application;
203
204 })();
205
206 Slider = (function() {
207
208 /*
209 * Renders the available days for delivery
210 */
211 function Slider(deliveryDays) {
212 this.slideRight = bind(this.slideRight, this);
213 this.slideLeft = bind(this.slideLeft, this);
214 var $el, $tabs, date, delivery, deliveryTimes, html, i, index, len, ref;
215 this.deliveryDays = deliveryDays;
216 if (deliveryDays.length < 1) {
217 $('post-delivery-row').addClass('post-hidden');
218 return;
219 }
220 $('post-delivery-row').removeClass('post-hidden');
221 deliveryDays.sort(this.orderDays);
222 deliveryTimes = window.post.sortedDeliverytimes = {};
223 $el = $('#post-tabs').html('');
224 window.post.deliveryDays = deliveryDays.length;
225 index = 0;
226 ref = this.deliveryDays;
227 for (i = 0, len = ref.length; i < len; i++) {
228 delivery = ref[i];
229 deliveryTimes[delivery.date] = delivery.time;
230 date = moment(delivery.date);
231 html = "<input type=\"radio\" id=\"post-date-" + index + "\" class=\"post-date\" name=\"date\" checked value=\"" + delivery.date + "\">\n<label for='post-date-" + index + "' class='post-tab active'>\n <span class='day-of-the-week'>" + (date.format('dddd')) + "</span>\n <br>\n <span class='date'>" + (date.format('DD MMMM')) + "</span>\n</label>";
232 $el.append(html);
233 index++;
234 }
235 $tabs = $('.post-tab');
236 if ($tabs.length > 0) {
237 $tabs.bind('click', updateDelivery);
238 $tabs[0].click();
239 }
240 // this should fix iOS canvas size issues but seems to break webcomponents in Safari:
241 // $("#post-tabs-container").attr('style', "width:" + ($("#post-tabs-container").width()) + "px");
242 $("#post-tabs").attr('style', "width:" + (this.deliveryDays.length * 105) + "px");
243 this.makeSlider();
244 }
245
246
247 /*
248 * Initializes the slider
249 */
250
251 Slider.prototype.makeSlider = function() {
252 this.slider = {};
253 this.slider.currentBar = 0;
254 this.slider.bars = window.post.deliveryDays * 105 / $('#post-tabs-container')[0].offsetWidth;
255 $('post-tabs').attr('style', "width:" + (window.post.deliveryDays * 105) + "px;");
256 $('#post-date-slider-right').removeClass('post-slider-disabled');
257 $('#post-date-slider-left').unbind().bind('click', this.slideLeft);
258 return $('#post-date-slider-right').unbind().bind('click', this.slideRight);
259 };
260
261
262 /*
263 * Event handler for sliding the date slider to the left
264 */
265
266 Slider.prototype.slideLeft = function(e) {
267 var $el, left, slider;
268 slider = this.slider;
269 if (slider.currentBar === 1) {
270 $(e.currentTarget).addClass('post-slider-disabled');
271 } else if (slider.currentBar < 1) {
272 return false;
273 } else {
274 $(e.currentTarget).removeClass('post-slider-disabled');
275 }
276 $('#post-date-slider-right').removeClass('post-slider-disabled');
277 slider.currentBar--;
278 $el = $('#post-tabs');
279 left = slider.currentBar * 100 * -1;
280 return $el.attr('style', "left:" + left + "%; width:" + (window.post.deliveryDays * 105) + "px");
281 };
282
283
284 /*
285 * Event handler for sliding the date slider to the right
286 */
287
288 Slider.prototype.slideRight = function(e) {
289 var $el, left, slider;
290 slider = this.slider;
291 if (parseInt(slider.currentBar) === parseInt(slider.bars - 1)) {
292 $(e.currentTarget).addClass('post-slider-disabled');
293 } else if (slider.currentBar >= slider.bars - 1) {
294 return false;
295 } else {
296 $(e.currentTarget).removeClass('post-slider-disabled');
297 }
298 $('#post-date-slider-left').removeClass('post-slider-disabled');
299 slider.currentBar++;
300 $el = $('#post-tabs');
301 left = slider.currentBar * 100 * -1;
302 return $el.attr('style', "left:" + left + "%; width:" + (window.post.deliveryDays * 105) + "px");
303 };
304
305
306 /*
307 * Order function for the delivery array
308 */
309
310 Slider.prototype.orderDays = function(dayA, dayB) {
311 var dateA, dateB, max;
312 dateA = moment(dayA.date);
313 dateB = moment(dayB.date);
314 max = moment.max(dateA, dateB);
315 if (max === dateA) {
316 return 1;
317 }
318 return -1;
319 };
320
321 return Slider;
322
323 })();
324
325 if (typeof postjQuery !== "undefined" && postjQuery !== null) {
326 jquery = postjQuery;
327 }
328
329 if (jquery == null) {
330 jquery = $;
331 }
332
333 if (jquery == null) {
334 jquery = jQuery;
335 }
336
337 $ = function(selector) {
338 return jquery(document.getElementById('postnl').shadowRoot).find(selector);
339 };
340
341 displayOtherTab = function() {
342 return $('.post-tab-container').toggleClass('post-slider-pos-1').toggleClass('post-slider-pos-0');
343 };
344
345
346 /*
347 * Starts the render of the delivery options with the preset config
348 */
349
350 renderPage = function(response) {
351 if (response.data.message === 'No results') {
352 $('#post-no-options').html('Geen bezorgopties gevonden voor het opgegeven adres.');
353 $('.post-overlay').removeClass('post-hidden');
354 return;
355 }
356 $('.post-overlay').addClass('post-hidden');
357 $('#post-delivery-option-check').bind('click', function() {
358 return renderDeliveryOptions($('input[name=date]:checked').val());
359 });
360 new Slider(response.data.delivery);
361 preparePickup(response.data.pickup);
362 $('#post-delivery-options-title').on('click', function() {
363 var date;
364 date = $('input[name=date]:checked').val();
365 renderDeliveryOptions(date);
366
367 $('#post-date-slider-right, #post-date-slider-left, #post-tabs-container').css("display","block");
368
369 return updateInputField();
370 });
371 $('#post-pickup-options-title').on('click', function() {
372 $('#post-pickup').prop('checked', true);
373
374 $('#post-date-slider-right, #post-date-slider-left, #post-tabs-container').css("display","none");
375
376 return updateInputField();
377 });
378 return updateInputField();
379 };
380
381 preparePickup = function(pickupOptions) {
382 var filter, i, j, len, len1, name1, pickupExpressPrice, pickupLocation, pickupPrice, ref, time;
383 if (pickupOptions.length < 1) {
384 $('#post-pickup-row').addClass('post-hidden');
385 return;
386 }
387 $('#post-pickup-row').removeClass('post-hidden');
388 pickupPrice = window.post.settings.price[PICKUP];
389 pickupExpressPrice = window.post.settings.price[PICKUP_EXPRESS];
390 $('.post-pickup-price').html(pickupPrice);
391 $('.post-pickup-price').toggleClass('post-hidden', pickupPrice == null);
392 $('.post-pickup-express-price').html(pickupExpressPrice);
393 $('.post-pickup-express-price').toggleClass('post-hidden', pickupExpressPrice == null);
394 window.post.pickupFiltered = filter = {};
395 pickupOptions = sortLocationsOnDistance(pickupOptions);
396 for (i = 0, len = pickupOptions.length; i < len; i++) {
397 pickupLocation = pickupOptions[i];
398 ref = pickupLocation.time;
399 for (j = 0, len1 = ref.length; j < len1; j++) {
400 time = ref[j];
401 if (filter[name1 = PICKUP_TIMES[time.start]] == null) {
402 filter[name1] = [];
403 }
404 filter[PICKUP_TIMES[time.start]].push(pickupLocation);
405 }
406 }
407 if (filter[PICKUP_TIMES[MORNING_PICKUP]] == null) {
408 $('#post-pickup-express').parent().css({
409 display: 'none'
410 });
411 }
412 showDefaultPickupLocation('#post-pickup-address', filter[PICKUP_TIMES[NORMAL_PICKUP]][0]);
413 if(MORNING_PICKUP && PICKUP_TIMES[MORNING_PICKUP] && filter[PICKUP_TIMES[MORNING_PICKUP]]){
414 showDefaultPickupLocation('#post-pickup-express-address', filter[PICKUP_TIMES[MORNING_PICKUP]][0]);
415 }
416 $('#post-pickup-address').off().bind('click', renderPickup);
417 $('#post-pickup-express-address').off().bind('click', renderExpressPickup);
418 return $('.post-pickup-selector').on('click', updateInputField);
419 };
420
421
422 /*
423 * Sorts the pickup options on nearest location
424 */
425
426 sortLocationsOnDistance = function(pickupOptions) {
427 return pickupOptions.sort(function(a, b) {
428 return parseInt(a.distance) - parseInt(b.distance);
429 });
430 };
431
432
433 /*
434 * Displays the default location behind the pickup location
435 */
436
437 showDefaultPickupLocation = function(selector, item) {
438 var html;
439 html = " - " + item.location + ", " + item.street + " " + item.number;
440 $(selector).html(html);
441 $(selector).parent().find('input').val(JSON.stringify(item));
442 return updateInputField();
443 };
444
445
446 /*
447 * Set the pickup time HTML and start rendering the locations page
448 */
449
450 renderPickup = function() {
451 renderPickupLocation(window.post.pickupFiltered[PICKUP_TIMES[NORMAL_PICKUP]]);
452 $('.post-location-time').html('- Vanaf 16.00 uur');
453 $('#post-pickup').prop('checked', true);
454 return false;
455 };
456
457
458 /*
459 * Set the pickup time HTML and start rendering the locations page
460 */
461
462 renderExpressPickup = function() {
463 renderPickupLocation(window.post.pickupFiltered[PICKUP_TIMES[MORNING_PICKUP]]);
464 $('.post-location-time').html('- Vanaf 08.30 uur');
465 $('#post-pickup-express').prop('checked', true);
466 return false;
467 };
468
469
470 /*
471 * Renders the locations in the array order given in data
472 */
473
474 renderPickupLocation = function(data) {
475 var day_index, html, i, index, j, k, len, location, openingHoursHtml, orderedHours, ref, ref1, time;
476 displayOtherTab();
477 $('.post-onoffswitch-checkbox:checked').prop('checked', false);
478 checkCombination();
479 $('#post-location-container').html('');
480 for (index = i = 0, ref = data.length - 1; 0 <= ref ? i <= ref : i >= ref; index = 0 <= ref ? ++i : --i) {
481 location = data[index];
482 orderedHours = orderOpeningHours(location.opening_hours);
483 openingHoursHtml = '';
484 for (day_index = j = 0; j <= 6; day_index = ++j) {
485 openingHoursHtml += "<div>\n <div class='post-day-of-the-week'>\n " + DAYS_OF_THE_WEEK_TRANSLATED[day_index] + ":\n </div>\n <div class='post-opening-hours-list'>";
486 ref1 = orderedHours[day_index];
487 for (k = 0, len = ref1.length; k < len; k++) {
488 time = ref1[k];
489 openingHoursHtml += "<div>" + time + "</div>";
490 }
491 if (orderedHours[day_index].length < 1) {
492 openingHoursHtml += "<div><i>Gesloten</i></div>";
493 }
494 openingHoursHtml += '</div></div>';
495 }
496 html = "<div for='post-pickup-location-" + index + "' class=\"post-row-lg afhalen-row\">\n <div class=\"afhalen-right\">\n <i class='post-info'>\n </i>\n </div>\n <div class='post-opening-hours'>\n " + openingHoursHtml + "\n </div>\n <label for='post-pickup-location-" + index + "' class=\"afhalen-left\">\n <div class=\"afhalen-check\">\n <input id=\"post-pickup-location-" + index + "\" type=\"radio\" name=\"post-pickup-option\" value='" + (JSON.stringify(location)) + "'>\n <label for='post-pickup-location-" + index + "' class='post-row-title'>\n <div class=\"post-checkmark post-main\">\n <div class=\"post-circle\"></div>\n <div class=\"post-checkmark-stem\"></div>\n <div class=\"post-checkmark-kick\"></div>\n </div>\n </label>\n </div>\n <div class='afhalen-tekst'>\n <span class=\"post-highlight post-inline-block\">" + location.location + ", <b class='post-inline-block'>" + location.street + " " + location.number + "</b>,\n <i class='post-inline-block'>" + (String(Math.round(location.distance / 100) / 10).replace('.', ',')) + " Km</i></span>\n </div>\n </label>\n</div>";
497 $('#post-location-container').append(html);
498 }
499 return $('input[name=post-pickup-option]').bind('click', function(e) {
500 var obj, selector;
501 displayOtherTab();
502 obj = JSON.parse($(e.currentTarget).val());
503 selector = '#' + $('input[name=post-delivery-time]:checked').parent().find('span.post-address').attr('id');
504 return showDefaultPickupLocation(selector, obj);
505 });
506 };
507
508 orderOpeningHours = function(opening_hours) {
509 var array, day, i, len;
510 array = [];
511 for (i = 0, len = DAYS_OF_THE_WEEK.length; i < len; i++) {
512 day = DAYS_OF_THE_WEEK[i];
513 array.push(opening_hours[day]);
514 }
515 return array;
516 };
517
518 updateDelivery = function(e) {
519 var date;
520 if ($('#post-delivery-option-check').prop('checked') !== true) {
521 return;
522 }
523 date = $("#" + ($(e.currentTarget).prop('for')))[0].value;
524 renderDeliveryOptions(date);
525 return updateInputField();
526 };
527
528 renderDeliveryOptions = function(date) {
529 var checked, combinatedPrice, combine, deliveryTimes, html, hvoPrice, hvoText, i, index, json, len, onlyRecipientPrice, onlyRecipientText, price, ref, ref1, time;
530 $('#post-delivery-options').html('');
531 html = '';
532 deliveryTimes = window.post.sortedDeliverytimes[date];
533 index = 0;
534 for (i = 0, len = deliveryTimes.length; i < len; i++) {
535 time = deliveryTimes[i];
536 if (time.price_comment === 'avond') {
537 time.price_comment = EVENING_DELIVERY;
538 }
539 price = window.post.settings.price[POST_NL_TRANSLATION[time.price_comment]];
540 json = {
541 date: date,
542 time: [time]
543 };
544 checked = '';
545 if (time.price_comment === 'standard') {
546 checked = "checked";
547 }
548 html += "<label for=\"post-time-" + index + "\" class='post-row-subitem'>\n <input id='post-time-" + index + "' type=\"radio\" name=\"post-delivery-time\" value='" + (JSON.stringify(json)) + "' " + checked + ">\n <label for=\"post-time-" + index + "\" class=\"post-checkmark\">\n <div class=\"post-circle post-circle-checked\"></div>\n <div class=\"post-checkmark-stem\"></div>\n <div class=\"post-checkmark-kick\"></div>\n </label>\n <span class=\"post-highlight\">" + (moment(time.start, 'HH:mm:SS').format('H.mm')) + " - " + (moment(time.end, 'HH:mm:SS').format('H.mm')) + " uur</span>";
549 if (price != null) {
550 html += "<span class='post-price'>" + price + "</span>";
551 }
552 html += "</label>";
553 index++;
554 }
555 hvoPrice = window.post.settings.price.signed;
556 hvoText = (ref = window.post.settings.text) != null ? ref.signed : void 0;
557 if (hvoText == null) {
558 hvoText = HVO_DEFAULT_TEXT;
559 }
560 onlyRecipientPrice = window.post.settings.price.only_recipient;
561 onlyRecipientText = (ref1 = window.post.settings.text) != null ? ref1.only_recipient : void 0;
562 if (onlyRecipientText == null) {
563 onlyRecipientText = AO_DEFAULT_TEXT;
564 }
565 combinatedPrice = window.post.settings.price.combi_options;
566 combine = onlyRecipientPrice !== 'disabled' && hvoPrice !== 'disabled' && (combinatedPrice != null);
567 if (combine) {
568 html += "<div class='post-combination-price'><span class='post-price post-hidden'>" + combinatedPrice + "</span>";
569 }
570 if (onlyRecipientPrice !== DISABLED) {
571 html += "<label for=\"post-only-recipient\" class='post-row-subitem'>\n <input type=\"checkbox\" name=\"post-only-recipient\" class=\"post-onoffswitch-checkbox\" id=\"post-only-recipient\">\n <div class=\"post-switch-container\">\n <div class=\"post-onoffswitch\">\n <label class=\"post-onoffswitch-label\" for=\"post-only-recipient\">\n <span class=\"post-onoffswitch-inner\"></span>\n <span class=\"post-onoffswitch-switch\"></span>\n </label>\n </div>\n </div>\n <span>" + onlyRecipientText;
572 if (onlyRecipientPrice != null) {
573 html += "<span class='post-price'>" + onlyRecipientPrice + "</span>";
574 }
575 html += "</span></label>";
576 }
577 if (hvoPrice !== DISABLED) {
578 html += "<label for=\"post-signed\" class='post-row-subitem'>\n <input type=\"checkbox\" name=\"post-signed\" class=\"post-onoffswitch-checkbox\" id=\"post-signed\">\n <div class=\"post-switch-container\">\n <div class=\"post-onoffswitch\">\n <label class=\"post-onoffswitch-label\" for=\"post-signed\">\n <span class=\"post-onoffswitch-inner\"></span>\n <span class=\"post-onoffswitch-switch\"></span>\n </label>\n </div>\n </div>\n <span>" + hvoText;
579 if (hvoPrice) {
580 html += "<span class='post-price'>" + hvoPrice + "</span>";
581 }
582 html += "</span></label>";
583 }
584 if (combine) {
585 html += "</div>";
586 }
587 $('#post-delivery-options').html(html);
588 $('.post-combination-price label').on('click', checkCombination);
589 $('#post-delivery-options label.post-row-subitem input[name=post-delivery-time]').on('change', function(e) {
590 var deliveryType;
591 deliveryType = JSON.parse($(e.currentTarget).val())['time'][0]['price_comment'];
592 if (deliveryType === MORNING_DELIVERY || deliveryType === EVENING_DELIVERY) {
593 $('input#post-only-recipient').prop('checked', true).prop('disabled', true);
594 $('label[for=post-only-recipient] span.post-price').html('incl.');
595 } else {
596 onlyRecipientPrice = window.post.settings.price.only_recipient;
597 $('input#post-only-recipient').prop('disabled', false);
598 $('label[for=post-only-recipient] span.post-price').html(onlyRecipientPrice);
599 }
600 return checkCombination();
601 });
602 if ($('input[name=post-delivery-time]:checked').length < 1) {
603 $($('input[name=post-delivery-time]')[0]).prop('checked', true);
604 }
605 return $('div#post-delivery-row label').bind('click', updateInputField);
606 };
607
608
609 /*
610 * Checks if the combination of options applies and displays this if needed.
611 */
612
613 checkCombination = function() {
614 var combination, deliveryType, inclusiveOption, json;
615 json = $('#post-delivery-options .post-row-subitem input[name=post-delivery-time]:checked').val();
616 if (json != null) {
617 deliveryType = JSON.parse(json)['time'][0]['price_comment'];
618 }
619 inclusiveOption = deliveryType === MORNING_DELIVERY || deliveryType === EVENING_DELIVERY;
620 combination = $('input[name=post-only-recipient]').prop('checked') && $('input[name=post-signed]').prop('checked') && !inclusiveOption;
621 $('.post-combination-price').toggleClass('post-combination-price-active', combination);
622 $('.post-combination-price > .post-price').toggleClass('post-price-active', combination);
623 $('.post-combination-price > .post-price').toggleClass('post-hidden', !combination);
624 return $('.post-combination-price label .post-price').toggleClass('post-hidden', combination);
625 };
626
627
628 /*
629 * Sets the json to the selected input field to be with the form
630 */
631
632 updateInputField = function() {
633 var json;
634 json = $('input[name=post-delivery-time]:checked').val();
635 if (jquery('#post-input', parent.document).val() !== json) {
636 jquery('#post-input', parent.document).val(json);
637 jquery('#post-input', parent.document).trigger('change');
638 parent.postjQuery('#post-input').trigger('change');
639 }
640 if (jquery('#post-signed', parent.document).val() !== $('#post-signed', parent.document).prop('checked')) {
641 jquery('#post-signed', parent.document).prop('checked', $('#post-signed', parent.document).prop('checked'));
642 jquery('#post-signed', parent.document).trigger('change');
643 parent.postjQuery('#post-input').trigger('change');
644 }
645 if (jquery('#post-recipient-only', parent.document).val() !== $('#post-recipient-only', parent.document).prop('checked')) {
646 jquery('#post-recipient-only', parent.document).prop('checked', $('#post-only-recipient').prop('checked'));
647 parent.postjQuery('#post-input').trigger('change');
648 return jquery('#post-recipient-only', parent.document).trigger('change');
649 }
650 };
651 /*
652 * Hide PostNL options
653 */
654 hidePostNLOptions = function() {
655 parent.postjQuery('#postnl-iframe').hide();
656 };
657 }).call(this);
658
659 //# sourceMappingURL=postnl.js.map
660