PageSourceSearch

https://drmahboobi.com/wp-content/plugins/bookly-responsive-appoin…-frontend-birthday-jalali.js?ver=1785181015

js drmahboobi.com collected 2026-10-03 02:32:54 UTC 4,259 bytes, 164 lines download raw bytes

1/**
2 * Jalali birthday selects on the public booking form (Details step).
3 */
4(function ($) {
5  'use strict';
6
7  function isPersianContext() {
8    return window.RadstJalali
9      && typeof RadstJalali.radst_isPersianCalendarContext === 'function'
10      && RadstJalali.radst_isPersianCalendarContext();
11  }
12
13  function toPersianDigits(value) {
14    return String(value).replace(/[0-9]/g, function (digit) {
15      return 'Û°Û±Û²Û³Û´ÛµÛ¶Û·Û¸Û¹'[digit];
16    });
17  }
18
19    function getDefaultJalaliYear() {
20    if (window.BooklyFrontendBirthdayJalali && BooklyFrontendBirthdayJalali.defaultJalaliYear) {
21      return parseInt(BooklyFrontendBirthdayJalali.defaultJalaliYear, 10);
22    }
23
24    if (window.RadstJalali && typeof RadstJalali.radst_gregorianToJalali === 'function') {
25      var now = new Date();
26      return RadstJalali.radst_gregorianToJalali(
27        now.getFullYear(),
28        now.getMonth() + 1,
29        now.getDate()
30      ).year;
31    }
32
33    return null;
34  }
35
36  function getBirthdayFields($container) {
37    return {
38      $day: $('.bookly-js-select-birthday-day', $container),
39      $month: $('.bookly-js-select-birthday-month', $container),
40      $year: $('.bookly-js-select-birthday-year', $container)
41    };
42  }
43
44  function syncBirthdayDays($container) {
45    var fields = getBirthdayFields($container);
46    var $day = fields.$day;
47    var $month = fields.$month;
48    var $year = fields.$year;
49
50    if (!$day.length || !$month.length || !$year.length) {
51      return;
52    }
53
54    var month = parseInt($month.val(), 10);
55    if (!month) {
56      return;
57    }
58
59    var year = parseInt($year.val(), 10);
60    if (!year) {
61      year = getDefaultJalaliYear();
62    }
63    if (!year) {
64      return;
65    }
66
67    var maxDay = RadstJalali.radst_jalaliMonthDays(year, month);
68    var selectedDay = parseInt($day.val(), 10);
69    var $placeholder = $day.find('option[value=""]').first().clone();
70
71    $day.empty();
72    if ($placeholder.length) {
73      $day.append($placeholder);
74    }
75
76    for (var day = 1; day <= maxDay; day++) {
77      $day.append($('<option>', {
78        value: String(day),
79        text: toPersianDigits(day)
80      }));
81    }
82
83    if (selectedDay > 0 && selectedDay <= maxDay) {
84      $day.val(String(selectedDay));
85    }
86  }
87
88  function convertGregorianBirthdayFields($container) {
89    var fields = getBirthdayFields($container);
90    var $day = fields.$day;
91    var $month = fields.$month;
92    var $year = fields.$year;
93
94    if (!$day.length || !$month.length || !$year.length) {
95      return;
96    }
97
98    var gregYear = parseInt($year.val(), 10);
99    var gregMonth = parseInt($month.val(), 10);
100    var gregDay = parseInt($day.val(), 10);
101
102    if (!gregYear || gregYear < 1900 || !gregMonth || !gregDay) {
103      return;
104    }
105
106    var jalali = RadstJalali.radst_gregorianToJalali(gregYear, gregMonth, gregDay);
107
108    $year.val(String(jalali.year));
109    $month.val(String(jalali.month));
110    $day.val(String(jalali.day));
111  }
112
113  function initBirthdayJalali($container) {
114    if (!isPersianContext() || !$container || !$container.length) {
115      return;
116    }
117
118    var fields = getBirthdayFields($container);
119    if (!fields.$month.length) {
120      return;
121    }
122
123    fields.$month.add(fields.$year)
124      .off('change.radstBirthday')
125      .on('change.radstBirthday', function () {
126        syncBirthdayDays($container);
127      });
128
129    convertGregorianBirthdayFields($container);
130    syncBirthdayDays($container);
131  }
132
133  function isLoginRequest(settings) {
134    var data = settings && settings.data;
135
136    if (!data) {
137      return false;
138    }
139
140    if (typeof data === 'string') {
141      return data.indexOf('action=bookly_login') !== -1 || data.indexOf('action=bookly_login&') !== -1;
142    }
143
144    return data.action === 'bookly_login';
145  }
146
147  $(document.body).on('bookly.render.step_detail', function (event, $container) {
148    initBirthdayJalali($container);
149  });
150
151  $(document).ajaxSuccess(function (event, xhr, settings) {
152    if (!isPersianContext() || !isLoginRequest(settings)) {
153      return;
154    }
155
156    window.setTimeout(function () {
157      $('.bookly-form').each(function () {
158        var $container = $(this);
159        convertGregorianBirthdayFields($container);
160        syncBirthdayDays($container);
161      });
162    }, 0);
163  });
164})(jQuery);

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.