| @@ -1,15 +1,152 @@ | ||
| 1 | 1 | (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ |
| 2 | 2 | "use strict"; |
| 3 | 3 | |
| 4 | +Object.defineProperty(exports, "__esModule", { | |
| 5 | + value: true | |
| 6 | +}); | |
| 7 | +exports["default"] = void 0; | |
| 8 | + | |
| 9 | +var _i18n = require("@wordpress/i18n"); | |
| 10 | + | |
| 11 | +var FileUploader = elementor.modules.controls.BaseMultiple.extend({ | |
| 12 | + ui: function ui() { | |
| 13 | + var ui = elementor.modules.controls.BaseMultiple.prototype.ui.apply(this, arguments); | |
| 14 | + return _.extend(ui, { | |
| 15 | + fileUploader: 'sellkit-control-file-uploader', | |
| 16 | + fileUploaderInput: '.sellkit-control-file-uploader-input', | |
| 17 | + fileUploaderBtn: '.sellkit-control-file-uploader-button', | |
| 18 | + fileUploaderValue: '.sellkit-control-file-uploader-value', | |
| 19 | + fileUploaderRemoveBtn: '.sellkit-control-file-uploader-value .fa', | |
| 20 | + fileUploaderProgress: '.sellkit-control-file-uploader-progress', | |
| 21 | + fileUploaderWarning: '.sellkit-control-file-uploader-warning', | |
| 22 | + fileUploaderSizeWarning: '.sellkit-control-file-uploader-warning-size' | |
| 23 | + }); | |
| 24 | + }, | |
| 25 | + events: function events() { | |
| 26 | + var events = elementor.modules.controls.BaseMultiple.prototype.events.apply(this, arguments); | |
| 27 | + return _.extend(events, { | |
| 28 | + 'change @ui.fileUploaderInput': 'onFileInputChange', | |
| 29 | + 'click @ui.fileUploaderRemoveBtn': 'onFileRemove' | |
| 30 | + }); | |
| 31 | + }, | |
| 32 | + onFileInputChange: function onFileInputChange(event) { | |
| 33 | + var self = this; | |
| 34 | + this.hideWarnings(); | |
| 35 | + | |
| 36 | + if (event.target.files.length === 0) { | |
| 37 | + return; | |
| 38 | + } | |
| 39 | + | |
| 40 | + if (!this.checkFileSize(event.target.files[0])) { | |
| 41 | + return; | |
| 42 | + } | |
| 43 | + | |
| 44 | + var formData = new FormData(); | |
| 45 | + formData.append('action', 'sellkit_control_file_upload'); | |
| 46 | + formData.append('file', event.target.files[0]); | |
| 47 | + formData.append('nonce', window.sellkitNonceEditorFileUploader[0]); | |
| 48 | + this.showUploadProgress(); | |
| 49 | + jQuery.ajax(this.ui.fileUploaderInput.data('ajax-url'), { | |
| 50 | + method: 'POST', | |
| 51 | + processData: false, | |
| 52 | + contentType: false, | |
| 53 | + global: false, | |
| 54 | + data: formData, | |
| 55 | + success: function success(res) { | |
| 56 | + if (res.success) { | |
| 57 | + self.setValue('files', [res.data]); | |
| 58 | + self.showFile(res.data.name); | |
| 59 | + } else { | |
| 60 | + self.ui.fileUploaderInput.val(''); | |
| 61 | + self.ui.fileUploaderWarning.find('ul').append("<li class=\"error\">".concat(res.data, "</li>")); | |
| 62 | + self.ui.fileUploaderWarning.show(); | |
| 63 | + self.showUploadBtn(); | |
| 64 | + } | |
| 65 | + }, | |
| 66 | + error: function error() { | |
| 67 | + self.ui.fileUploaderInput.val(''); | |
| 68 | + self.ui.fileUploaderWarning.find('ul').append("<li class=\"error\">".concat((0, _i18n.__)('Something went wrong please try again.', 'sellkit'), "</li>")); | |
| 69 | + self.ui.fileUploaderWarning.show(); | |
| 70 | + self.showUploadBtn(); | |
| 71 | + } | |
| 72 | + }); | |
| 73 | + }, | |
| 74 | + onFileRemove: function onFileRemove(event) { | |
| 75 | + event.stopPropagation(); | |
| 76 | + this.setValue('files', []); | |
| 77 | + this.ui.fileUploaderValue.hide(); | |
| 78 | + this.ui.fileUploaderBtn.show(); | |
| 79 | + this.ui.fileUploaderInput.val(''); | |
| 80 | + }, | |
| 81 | + hideWarnings: function hideWarnings() { | |
| 82 | + this.ui.fileUploaderWarning.hide(); | |
| 83 | + this.ui.fileUploaderWarning.find('li').hide(); | |
| 84 | + this.ui.fileUploaderWarning.find('li.error').remove(); | |
| 85 | + }, | |
| 86 | + checkFileSize: function checkFileSize(file) { | |
| 87 | + var uploadLimit = parseFloat(this.ui.fileUploaderInput.data('max-upload-limit')); | |
| 88 | + | |
| 89 | + if (file.size > uploadLimit) { | |
| 90 | + this.ui.fileUploaderWarning.show(); | |
| 91 | + this.ui.fileUploaderSizeWarning.show(); | |
| 92 | + return false; | |
| 93 | + } | |
| 94 | + | |
| 95 | + return true; | |
| 96 | + }, | |
| 97 | + stripHash: function stripHash(filename) { | |
| 98 | + var ext = filename.split('.').pop(); | |
| 99 | + var name = filename.replace('.' + ext, ''); | |
| 100 | + name = name.split('__').shift(); | |
| 101 | + return name + '.' + ext; | |
| 102 | + }, | |
| 103 | + shortenFilename: function shortenFilename(filename) { | |
| 104 | + return filename.length > 15 ? filename.substr(0, 15) + '...' : filename; | |
| 105 | + }, | |
| 106 | + showFile: function showFile(filename) { | |
| 107 | + this.ui.fileUploaderProgress.hide(); | |
| 108 | + this.ui.fileUploaderBtn.hide(); | |
| 109 | + filename = this.stripHash(filename); | |
| 110 | + this.ui.fileUploaderValue.find('> span:first-child').attr('title', filename).text(this.shortenFilename(filename)); | |
| 111 | + this.ui.fileUploaderValue.css('display', 'flex'); | |
| 112 | + }, | |
| 113 | + showUploadBtn: function showUploadBtn() { | |
| 114 | + this.ui.fileUploaderValue.hide(); | |
| 115 | + this.ui.fileUploaderProgress.hide(); | |
| 116 | + this.ui.fileUploaderBtn.show(); | |
| 117 | + }, | |
| 118 | + showUploadProgress: function showUploadProgress() { | |
| 119 | + this.ui.fileUploaderValue.hide(); | |
| 120 | + this.ui.fileUploaderBtn.hide(); | |
| 121 | + this.ui.fileUploaderProgress.show(); | |
| 122 | + }, | |
| 123 | + onRender: function onRender() { | |
| 124 | + _.extend(elementor.modules.controls.BaseMultiple.prototype.onRender.apply(this, arguments)); | |
| 125 | + | |
| 126 | + var files = this.getControlValue('files'); | |
| 127 | + | |
| 128 | + if (!files || files.length === 0) { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + | |
| 132 | + this.showFile(files[0].name); | |
| 133 | + } | |
| 134 | +}); | |
| 135 | +var _default = FileUploader; | |
| 136 | +exports["default"] = _default; | |
| 137 | + | |
| 138 | +},{"@wordpress/i18n":23}],2:[function(require,module,exports){ | |
| 139 | +"use strict"; | |
| 140 | + | |
| 4 | 141 | (function ($, window) { |
| 5 | 142 | var sellkitEditor = function sellkitEditor() { |
| 6 | - // Manage dark & light icons. | |
| 7 | 143 | var onElementorReady = function onElementorReady() { |
| 8 | 144 | if (typeof elementor.settings.editorPreferences === 'undefined') { |
| 9 | 145 | return; |
| 10 | - } | |
| 146 | + } // Manage dark & light icons. | |
| 11 | 147 | |
| 148 | + | |
| 12 | 149 | if ('dark' === elementor.settings.editorPreferences.model.attributes.ui_theme) { |
| 13 | 150 | $('#elementor-editor-wrapper').addClass('sellkit-editor-ui-dark'); |
| 14 | 151 | } else { |
| 15 | 152 | $('#elementor-editor-wrapper').removeClass('sellkit-editor-ui-dark'); |
| @@ -17,25 +154,67 @@ | ||
| 17 | 154 | }; |
| 18 | 155 | |
| 19 | 156 | var onSettingsChange = function onSettingsChange() { |
| 20 | 157 | elementor.settings.editorPreferences.model.on('change', onElementorReady); |
| 158 | + }; // Initialize controls JS. | |
| 159 | + | |
| 160 | + | |
| 161 | + var initControls = function initControls() { | |
| 162 | + var controls = { | |
| 163 | + file_uploader: require('./controls/file-uploader')["default"] | |
| 164 | + }; | |
| 165 | + | |
| 166 | + for (var control in controls) { | |
| 167 | + elementor.addControlView("sellkit_".concat(control), controls[control]); | |
| 168 | + } | |
| 21 | 169 | }; // Initialize widget JS. |
| 22 | 170 | |
| 23 | 171 | |
| 24 | - function initWidgets() { | |
| 172 | + var initWidgets = function initWidgets() { | |
| 25 | 173 | var widgets = { |
| 26 | - 'sellkit-checkout': require('./widgets/checkout')["default"] | |
| 174 | + 'sellkit-checkout': require('./widgets/checkout')["default"], | |
| 175 | + 'sellkit-optin': require('./widgets/optin/optin')["default"] | |
| 27 | 176 | }; |
| 28 | 177 | |
| 29 | 178 | for (var widget in widgets) { |
| 30 | 179 | elementor.hooks.addAction("panel/open_editor/widget/".concat(widget), widgets[widget]); |
| 31 | 180 | } |
| 181 | + }; // Some widgets require a rerender after preview loaded, | |
| 182 | + // to fully sync with their ajaxed settings AND\OR displaying shortcode contents. | |
| 183 | + | |
| 184 | + | |
| 185 | + function rerenderWidgets() { | |
| 186 | + if (!elementor.previewView || !elementor.previewView._getNestedViews) { | |
| 187 | + return; | |
| 188 | + } | |
| 189 | + | |
| 190 | + var widgets = ['sellkit-checkout']; | |
| 191 | + | |
| 192 | + var _loop = function _loop(widget) { | |
| 193 | + var views = elementor.previewView._getNestedViews().filter(function (view) { | |
| 194 | + return 'widget' === view.model.get('elType') && widgets[widget] === view.model.get('widgetType'); | |
| 195 | + }); | |
| 196 | + | |
| 197 | + _.each(views, function (view) { | |
| 198 | + return view.renderHTML(); | |
| 199 | + }); | |
| 200 | + }; | |
| 201 | + | |
| 202 | + for (var widget in widgets) { | |
| 203 | + _loop(widget); | |
| 204 | + } | |
| 32 | 205 | } |
| 33 | 206 | |
| 207 | + function onDocumentLoaded() { | |
| 208 | + setTimeout(rerenderWidgets, 0); | |
| 209 | + } | |
| 210 | + | |
| 34 | 211 | var onElementorInit = function onElementorInit() { |
| 35 | 212 | onElementorReady(); |
| 36 | 213 | onSettingsChange(); |
| 214 | + initControls(); | |
| 37 | 215 | elementor.on('frontend:init', initWidgets); |
| 216 | + elementor.on('document:loaded', onDocumentLoaded); | |
| 38 | 217 | }; |
| 39 | 218 | |
| 40 | 219 | $(window).on('elementor:init', onElementorInit); |
| 41 | 220 | }; |
| @@ -42,9 +221,9 @@ | ||
| 42 | 221 | |
| 43 | 222 | window.sellkitEditor = new sellkitEditor(); |
| 44 | 223 | })(jQuery, window); |
| 45 | 224 | |
| 46 | -},{"./widgets/checkout":2}],2:[function(require,module,exports){ | |
| 225 | +},{"./controls/file-uploader":1,"./widgets/checkout":3,"./widgets/optin/optin":13}],3:[function(require,module,exports){ | |
| 47 | 226 | "use strict"; |
| 48 | 227 | |
| 49 | 228 | Object.defineProperty(exports, "__esModule", { |
| 50 | 229 | value: true |
| @@ -51,10 +230,12 @@ | ||
| 51 | 230 | }); |
| 52 | 231 | exports["default"] = _default; |
| 53 | 232 | |
| 54 | 233 | function _default() { |
| 55 | - var $ = jQuery; | |
| 234 | + var $ = jQuery; // eslint-disable-next-line no-undef | |
| 56 | 235 | |
| 236 | + var activeTheme = sellkitPromotion.activeTheme; | |
| 237 | + | |
| 57 | 238 | var initializeChange = function initializeChange() { |
| 58 | 239 | var $element = $('input[data-setting="place_order_btn_txt"'); |
| 59 | 240 | var value = $element.val(); |
| 60 | 241 | $element.val(''); |
| @@ -64,9 +245,9 @@ | ||
| 64 | 245 | var disableExpressOnFree = function disableExpressOnFree() { |
| 65 | 246 | var promotionParent = $('.elementor-control-checkout-express-promotion'); |
| 66 | 247 | promotionParent.find('input').attr('disabled', 'disabled'); |
| 67 | 248 | promotionParent.find('.elementor-control-title').on('click', function () { |
| 68 | - window.open('https://getsellkit.com/pricing/', '_blank'); | |
| 249 | + window.open('https://getsellkit.com/pricing/?utm_source=wp-dashboard&utm_campaign=gopro&utm_medium=' + activeTheme, '_blank'); | |
| 69 | 250 | }); |
| 70 | 251 | }; |
| 71 | 252 | |
| 72 | 253 | var init = function init() { |
| @@ -76,5 +257,3706 @@ | ||
| 76 | 257 | |
| 77 | 258 | init(); |
| 78 | 259 | } |
| 79 | 260 | |
| 80 | -},{}]},{},[1]); | |
| 261 | +},{}],4:[function(require,module,exports){ | |
| 262 | +"use strict"; | |
| 263 | + | |
| 264 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 265 | + | |
| 266 | +Object.defineProperty(exports, "__esModule", { | |
| 267 | + value: true | |
| 268 | +}); | |
| 269 | +exports["default"] = _default; | |
| 270 | + | |
| 271 | +var _crmBase = _interopRequireDefault(require("./crm-base")); | |
| 272 | + | |
| 273 | +function _default(panel, model, view) { | |
| 274 | + var ActiveCampaign = _crmBase["default"].extend({ | |
| 275 | + panel: panel, | |
| 276 | + model: model, | |
| 277 | + action: 'activecampaign', | |
| 278 | + add_additional_api_data: function add_additional_api_data(params) { | |
| 279 | + params["".concat(this.action, "_custom_api_url")] = this.getControlValue("".concat(this.action, "_custom_api_url")); | |
| 280 | + }, | |
| 281 | + updateAdditionalControls: function updateAdditionalControls() { | |
| 282 | + if (!this.additionalData.hasOwnProperty('tags')) { | |
| 283 | + return; | |
| 284 | + } | |
| 285 | + | |
| 286 | + var tagsControl = this.getControlView("".concat(this.action, "_tags")); | |
| 287 | + tagsControl.model.set('options', this.additionalData.tags); | |
| 288 | + tagsControl.render(); | |
| 289 | + }, | |
| 290 | + // Override to reflect changes of "custom_api_url" control. | |
| 291 | + onElementChange: function onElementChange(controlView) { | |
| 292 | + var setting = controlView.model.get('name'); | |
| 293 | + | |
| 294 | + switch (setting) { | |
| 295 | + case "".concat(this.action, "_api_key_source"): | |
| 296 | + case "".concat(this.action, "_custom_api_key"): | |
| 297 | + case "".concat(this.action, "_custom_api_url"): | |
| 298 | + this.ajaxUpdateList(); | |
| 299 | + break; | |
| 300 | + | |
| 301 | + case "".concat(this.action, "_list"): | |
| 302 | + var listId = this.getListId(); | |
| 303 | + | |
| 304 | + if (listId && !this.listOptions.hasOwnProperty(listId)) { | |
| 305 | + this.ajaxUpdateAdditionalData(); | |
| 306 | + } | |
| 307 | + | |
| 308 | + break; | |
| 309 | + } | |
| 310 | + } | |
| 311 | + }); | |
| 312 | + | |
| 313 | + new ActiveCampaign({ | |
| 314 | + $element: view.$el | |
| 315 | + }); | |
| 316 | +} | |
| 317 | + | |
| 318 | +},{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],5:[function(require,module,exports){ | |
| 319 | +"use strict"; | |
| 320 | + | |
| 321 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 322 | + | |
| 323 | +Object.defineProperty(exports, "__esModule", { | |
| 324 | + value: true | |
| 325 | +}); | |
| 326 | +exports["default"] = _default; | |
| 327 | + | |
| 328 | +var _crmBase = _interopRequireDefault(require("./crm-base")); | |
| 329 | + | |
| 330 | +function _default(panel, model, view) { | |
| 331 | + var ConvertKit = _crmBase["default"].extend({ | |
| 332 | + panel: panel, | |
| 333 | + model: model, | |
| 334 | + action: 'convertkit', | |
| 335 | + updateAdditionalControls: function updateAdditionalControls() { | |
| 336 | + if (!this.additionalData.hasOwnProperty('tags')) { | |
| 337 | + return; | |
| 338 | + } | |
| 339 | + | |
| 340 | + var tagsControl = this.getControlView("".concat(this.action, "_tags")); | |
| 341 | + tagsControl.model.set('options', this.additionalData.tags); | |
| 342 | + tagsControl.render(); | |
| 343 | + } | |
| 344 | + }); | |
| 345 | + | |
| 346 | + new ConvertKit({ | |
| 347 | + $element: view.$el | |
| 348 | + }); | |
| 349 | +} | |
| 350 | + | |
| 351 | +},{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],6:[function(require,module,exports){ | |
| 352 | +"use strict"; | |
| 353 | + | |
| 354 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 355 | + | |
| 356 | +Object.defineProperty(exports, "__esModule", { | |
| 357 | + value: true | |
| 358 | +}); | |
| 359 | +exports["default"] = void 0; | |
| 360 | + | |
| 361 | +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | |
| 362 | + | |
| 363 | +var _util = _interopRequireDefault(require("../../util")); | |
| 364 | + | |
| 365 | +var _i18n = require("@wordpress/i18n"); | |
| 366 | + | |
| 367 | +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | |
| 368 | + | |
| 369 | +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | |
| 370 | + | |
| 371 | +var _default = _util["default"].extend({ | |
| 372 | + panel: null, | |
| 373 | + model: null, | |
| 374 | + action: null, | |
| 375 | + listView: null, | |
| 376 | + listOptions: { | |
| 377 | + none: { | |
| 378 | + none: (0, _i18n.__)('Select...', 'sellkit') | |
| 379 | + }, | |
| 380 | + fetching: { | |
| 381 | + fetching: (0, _i18n.__)('Fetching...', 'sellkit') | |
| 382 | + }, | |
| 383 | + noList: { | |
| 384 | + noList: (0, _i18n.__)('Nothing found!', 'sellkit') | |
| 385 | + } | |
| 386 | + }, | |
| 387 | + fieldNoneOption: { | |
| 388 | + '': (0, _i18n.__)('-NONE-', 'sellkit') | |
| 389 | + }, | |
| 390 | + mappingRepeater: null, | |
| 391 | + localFields: {}, | |
| 392 | + additionalData: [], | |
| 393 | + onInit: function onInit() { | |
| 394 | + elementor.channels.editor.on('section:activated', this.onSectionActivated); | |
| 395 | + elementor.channels.editor.on('change', this.onElementChange); | |
| 396 | + }, | |
| 397 | + onDestroy: function onDestroy() { | |
| 398 | + elementor.channels.editor.off('change', this.onElementChange); | |
| 399 | + }, | |
| 400 | + onSectionActivated: function onSectionActivated(activeSection, section) { | |
| 401 | + if (activeSection !== "section_".concat(this.action) || section.model.id !== this.model.get('id')) { | |
| 402 | + return; | |
| 403 | + } | |
| 404 | + | |
| 405 | + this.init(); | |
| 406 | + }, | |
| 407 | + init: function init() { | |
| 408 | + this.localFields = _objectSpread(_objectSpread({}, this.fieldNoneOption), this.getFormFields()); | |
| 409 | + this.listView = this.getControlView("".concat(this.action, "_list")); | |
| 410 | + this.mappingRepeater = this.getControlView("".concat(this.action, "_fields_mapping")); | |
| 411 | + this.ajaxUpdateList(); | |
| 412 | + this.updateControls(); | |
| 413 | + this.mappingRepeater.on('add:child', this.updateControls); | |
| 414 | + this.mappingRepeater.on('childview:click:remove', this.updateControls); | |
| 415 | + }, | |
| 416 | + ajaxUpdateList: function ajaxUpdateList() { | |
| 417 | + var _this = this; | |
| 418 | + | |
| 419 | + var currentValue = this.getControlValue("".concat(this.action, "_list")); | |
| 420 | + this.setListOptions(this.listOptions.fetching); | |
| 421 | + this.setListSelection('fetching'); | |
| 422 | + this.addControlSpinner("".concat(this.action, "_list")); | |
| 423 | + var params = {}; | |
| 424 | + params["".concat(this.action, "_api_key_source")] = this.getControlValue("".concat(this.action, "_api_key_source")) || 'default'; | |
| 425 | + params["".concat(this.action, "_custom_api_key")] = this.getControlValue("".concat(this.action, "_custom_api_key")); | |
| 426 | + this.add_additional_api_data(params); | |
| 427 | + wp.ajax.send('sellkit_optin_editor', { | |
| 428 | + cache: false, | |
| 429 | + data: { | |
| 430 | + params: params, | |
| 431 | + nonce: window.sellkitNonceEditorOptin[0], | |
| 432 | + service: this.action, | |
| 433 | + request: 'get_list' | |
| 434 | + }, | |
| 435 | + success: function success(response) { | |
| 436 | + _this.removeControlSpinner("".concat(_this.action, "_list")); | |
| 437 | + | |
| 438 | + var lists = {}; | |
| 439 | + | |
| 440 | + if (response.success[0].lists.length === 0) { | |
| 441 | + _this.setListOptions(_this.listOptions.noList); | |
| 442 | + | |
| 443 | + _this.setListSelection('noList'); | |
| 444 | + | |
| 445 | + return; | |
| 446 | + } | |
| 447 | + | |
| 448 | + _.each(response.success[0].lists, function (list, id) { | |
| 449 | + lists[id] = list; | |
| 450 | + }); | |
| 451 | + | |
| 452 | + var options = _objectSpread(_objectSpread({}, _this.listOptions.none), lists); | |
| 453 | + | |
| 454 | + _this.setListOptions(options); | |
| 455 | + | |
| 456 | + if (options[currentValue]) { | |
| 457 | + _this.setListSelection(currentValue); | |
| 458 | + | |
| 459 | + return; | |
| 460 | + } | |
| 461 | + | |
| 462 | + if (_.isEmpty(_this.listView.$el.val())) { | |
| 463 | + _this.setListSelection('none'); | |
| 464 | + } | |
| 465 | + }, | |
| 466 | + error: function error() { | |
| 467 | + _this.removeControlSpinner("".concat(_this.action, "_list")); | |
| 468 | + | |
| 469 | + _this.listView.$el.find('option').text((0, _i18n.__)('Error! nonce mismatch', 'sellkit')); | |
| 470 | + | |
| 471 | + _this.listView.$el.find('select').attr('disabled', 'disabled'); | |
| 472 | + } | |
| 473 | + }); | |
| 474 | + }, | |
| 475 | + ajaxUpdateAdditionalData: function ajaxUpdateAdditionalData() { | |
| 476 | + var _this2 = this; | |
| 477 | + | |
| 478 | + var params = {}; | |
| 479 | + params["".concat(this.action, "_api_key_source")] = this.getControlValue("".concat(this.action, "_api_key_source")) || 'default'; | |
| 480 | + params["".concat(this.action, "_custom_api_key")] = this.getControlValue("".concat(this.action, "_custom_api_key")); | |
| 481 | + params.list_id = this.getListId(); | |
| 482 | + this.add_additional_api_data(params); | |
| 483 | + this.toggleSpinner(true); | |
| 484 | + wp.ajax.send('sellkit_optin_editor', { | |
| 485 | + data: { | |
| 486 | + params: params, | |
| 487 | + nonce: window.sellkitNonceEditorOptin[0], | |
| 488 | + service: this.action, | |
| 489 | + request: 'get_additional_data' | |
| 490 | + }, | |
| 491 | + success: function success(response) { | |
| 492 | + _this2.additionalData = response.success[0]; | |
| 493 | + | |
| 494 | + _this2.updateControls(); | |
| 495 | + }, | |
| 496 | + complete: function complete() { | |
| 497 | + return _this2.toggleSpinner(false); | |
| 498 | + } | |
| 499 | + }); | |
| 500 | + }, | |
| 501 | + updateControls: function updateControls() { | |
| 502 | + var _this3 = this; | |
| 503 | + | |
| 504 | + this.mappingRepeater.children.each(function (row) { | |
| 505 | + row.children.each(function (control) { | |
| 506 | + var fieldModel = control.model; | |
| 507 | + var fieldName = fieldModel.get('name'); | |
| 508 | + | |
| 509 | + switch (fieldName) { | |
| 510 | + case 'remote_field': | |
| 511 | + if (!_this3.additionalData.hasOwnProperty('custom_fields')) { | |
| 512 | + break; | |
| 513 | + } | |
| 514 | + | |
| 515 | + var currentOptions = fieldModel.get('options'); | |
| 516 | + | |
| 517 | + var newOptions = _objectSpread(_objectSpread(_objectSpread({}, _this3.fieldNoneOption), currentOptions), _this3.additionalData.custom_fields); | |
| 518 | + | |
| 519 | + fieldModel.set('options', newOptions); | |
| 520 | + break; | |
| 521 | + | |
| 522 | + case 'local_field': | |
| 523 | + fieldModel.set('options', _this3.localFields); | |
| 524 | + break; | |
| 525 | + | |
| 526 | + default: | |
| 527 | + break; | |
| 528 | + } | |
| 529 | + | |
| 530 | + control.render(); | |
| 531 | + }); | |
| 532 | + | |
| 533 | + _this3.fixTitleField(row); | |
| 534 | + }); | |
| 535 | + this.sortSelectOptions(); | |
| 536 | + this.lockRequiredRemoteFields(); | |
| 537 | + this.updateAdditionalControls(); | |
| 538 | + }, | |
| 539 | + onElementChange: function onElementChange(controlView) { | |
| 540 | + var setting = controlView.model.get('name'); | |
| 541 | + | |
| 542 | + switch (setting) { | |
| 543 | + case "".concat(this.action, "_api_key_source"): | |
| 544 | + case "".concat(this.action, "_custom_api_key"): | |
| 545 | + this.ajaxUpdateList(); | |
| 546 | + break; | |
| 547 | + | |
| 548 | + case "".concat(this.action, "_list"): | |
| 549 | + var listId = this.getListId(); | |
| 550 | + | |
| 551 | + if (listId && !this.listOptions.hasOwnProperty(listId)) { | |
| 552 | + this.ajaxUpdateAdditionalData(); | |
| 553 | + } | |
| 554 | + | |
| 555 | + break; | |
| 556 | + } | |
| 557 | + }, | |
| 558 | + getListId: function getListId() { | |
| 559 | + return this.getControlValue("".concat(this.action, "_list")); | |
| 560 | + }, | |
| 561 | + // Set Options of the "List" select control. | |
| 562 | + setListOptions: function setListOptions(options) { | |
| 563 | + this.listView.model.set('options', options); | |
| 564 | + this.listView.render(); // Sort options so that the "Select..." option comes first. | |
| 565 | + | |
| 566 | + var select = this.listView.$el.find('select'); | |
| 567 | + var firstOption = select.find('option[value="none"]'); | |
| 568 | + | |
| 569 | + if (!firstOption.length) { | |
| 570 | + return; | |
| 571 | + } | |
| 572 | + | |
| 573 | + var helper = firstOption[0]; | |
| 574 | + firstOption.remove(); | |
| 575 | + select.prepend(helper); | |
| 576 | + }, | |
| 577 | + setListSelection: function setListSelection(option) { | |
| 578 | + this.listView.$el.find('select').val(option).change(); | |
| 579 | + }, | |
| 580 | + // Sort mapping fields options so that the "-NONE-" option comes first. | |
| 581 | + sortSelectOptions: function sortSelectOptions() { | |
| 582 | + var selects = this.mappingRepeater.$el.find('select'); | |
| 583 | + | |
| 584 | + _.each(selects, function (select) { | |
| 585 | + var firstOption = jQuery(select).find('option[value=""]'); | |
| 586 | + | |
| 587 | + if (!firstOption.length) { | |
| 588 | + return; | |
| 589 | + } | |
| 590 | + | |
| 591 | + var helper = firstOption[0]; | |
| 592 | + firstOption.remove(); | |
| 593 | + select.prepend(helper); | |
| 594 | + }); | |
| 595 | + }, | |
| 596 | + getFormFields: function getFormFields() { | |
| 597 | + var items = {}; | |
| 598 | + var formFieldsRepeater = this.getElementSettings(this.model, 'fields'); | |
| 599 | + | |
| 600 | + _.each(formFieldsRepeater, function (item) { | |
| 601 | + items[item._id] = item.label; | |
| 602 | + }); | |
| 603 | + | |
| 604 | + return items; | |
| 605 | + }, | |
| 606 | + // Find required remote fields, lock them, remove their repeater row styles, and add a star next to them. | |
| 607 | + lockRequiredRemoteFields: function lockRequiredRemoteFields() { | |
| 608 | + this.mappingRepeater.children.each(function (row) { | |
| 609 | + if (row.model.get('is_required')) { | |
| 610 | + var toolbar = row.$el.find('div.elementor-repeater-row-tools'); | |
| 611 | + var controlWrapper = row.$el.find('div.elementor-repeater-row-controls'); | |
| 612 | + var remoteField = row.$el.find('div.elementor-control-remote_field'); | |
| 613 | + var localField = row.$el.find('div.elementor-control-local_field'); | |
| 614 | + var localLabel = localField.find('label'); | |
| 615 | + var newLabel = remoteField.find('select option:selected').text(); | |
| 616 | + var starMark = '<span style="color:red">*</span>'; | |
| 617 | + toolbar.hide(); | |
| 618 | + controlWrapper.show(); | |
| 619 | + controlWrapper.css('border', 'none'); | |
| 620 | + remoteField.hide(); | |
| 621 | + localLabel.html(newLabel + starMark); | |
| 622 | + localField.css('padding', '0'); | |
| 623 | + } | |
| 624 | + }); | |
| 625 | + }, | |
| 626 | + // Set titles of repeater rows so that they show "label" of remote fields instead of their "key". | |
| 627 | + fixTitleField: function fixTitleField(rowView) { | |
| 628 | + if (rowView.data) { | |
| 629 | + rowView = rowView.data.rowView; | |
| 630 | + } | |
| 631 | + | |
| 632 | + var remoteFieldSelect = rowView.$el.find('select[data-setting="remote_field"]'); | |
| 633 | + var label = remoteFieldSelect.find("option[value=\"".concat(remoteFieldSelect.val(), "\"]")).first().text(); | |
| 634 | + rowView.$el.find('div.elementor-repeater-row-item-title').text(label); | |
| 635 | + remoteFieldSelect.off('change', this.fixTitleField).change({ | |
| 636 | + rowView: rowView | |
| 637 | + }, this.fixTitleField); | |
| 638 | + }, | |
| 639 | + // While additional data about the selected list is being recieved, | |
| 640 | + // toggle a spinner and opaque its corresopnding fields. | |
| 641 | + toggleSpinner: function toggleSpinner(state) { | |
| 642 | + var containers = jQuery(".elementor-control.elementor-control-".concat(this.action, "_list")).nextAll(); | |
| 643 | + containers.css('opacity', state ? 0.5 : 1); | |
| 644 | + | |
| 645 | + if (state) { | |
| 646 | + var spinner = "\n\t\t\t\t<span style=\"position: absolute; top: 15px; right: 15px;\" class=\"elementor-control-spinner\">\n\t\t\t\t\t<span style=\"font-size: 20px\" class=\"fa fa-spinner fa-spin\"></span>\n\t\t\t\t\t \n\t\t\t\t</span>\n\t\t\t"; | |
| 647 | + containers.first().prepend(spinner); | |
| 648 | + return; | |
| 649 | + } | |
| 650 | + | |
| 651 | + containers.first().find('span.elementor-control-spinner').remove(); | |
| 652 | + }, | |
| 653 | + // Placed to be overridden if needed. | |
| 654 | + | |
| 655 | + /* eslint-disable no-unused-vars */ | |
| 656 | + add_additional_api_data: function add_additional_api_data(params) {}, | |
| 657 | + | |
| 658 | + /* eslint-enable no-unused-vars */ | |
| 659 | + // Placed to be overridden if needed. | |
| 660 | + updateAdditionalControls: function updateAdditionalControls() {} | |
| 661 | +}); | |
| 662 | + | |
| 663 | +exports["default"] = _default; | |
| 664 | + | |
| 665 | +},{"../../util":14,"@babel/runtime/helpers/defineProperty":15,"@babel/runtime/helpers/interopRequireDefault":16,"@wordpress/i18n":23}],7:[function(require,module,exports){ | |
| 666 | +"use strict"; | |
| 667 | + | |
| 668 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 669 | + | |
| 670 | +Object.defineProperty(exports, "__esModule", { | |
| 671 | + value: true | |
| 672 | +}); | |
| 673 | +exports["default"] = _default; | |
| 674 | + | |
| 675 | +var _crmBase = _interopRequireDefault(require("./crm-base")); | |
| 676 | + | |
| 677 | +function _default(panel, model, view) { | |
| 678 | + var Drip = _crmBase["default"].extend({ | |
| 679 | + panel: panel, | |
| 680 | + model: model, | |
| 681 | + action: 'drip', | |
| 682 | + updateAdditionalControls: function updateAdditionalControls() { | |
| 683 | + if (!this.additionalData.hasOwnProperty('tags')) { | |
| 684 | + return; | |
| 685 | + } | |
| 686 | + | |
| 687 | + var tagsControl = this.getControlView("".concat(this.action, "_tags")); | |
| 688 | + tagsControl.model.set('options', this.additionalData.tags); | |
| 689 | + tagsControl.render(); | |
| 690 | + } | |
| 691 | + }); | |
| 692 | + | |
| 693 | + new Drip({ | |
| 694 | + $element: view.$el | |
| 695 | + }); | |
| 696 | +} | |
| 697 | + | |
| 698 | +},{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],8:[function(require,module,exports){ | |
| 699 | +"use strict"; | |
| 700 | + | |
| 701 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 702 | + | |
| 703 | +Object.defineProperty(exports, "__esModule", { | |
| 704 | + value: true | |
| 705 | +}); | |
| 706 | +exports["default"] = _default; | |
| 707 | + | |
| 708 | +var _crmBase = _interopRequireDefault(require("./crm-base")); | |
| 709 | + | |
| 710 | +function _default(panel, model, view) { | |
| 711 | + var GetResponse = _crmBase["default"].extend({ | |
| 712 | + panel: panel, | |
| 713 | + model: model, | |
| 714 | + action: 'getresponse', | |
| 715 | + updateAdditionalControls: function updateAdditionalControls() { | |
| 716 | + if (!this.additionalData.hasOwnProperty('tags')) { | |
| 717 | + return; | |
| 718 | + } | |
| 719 | + | |
| 720 | + var tagsControl = this.getControlView("".concat(this.action, "_tags")); | |
| 721 | + tagsControl.model.set('options', this.additionalData.tags); | |
| 722 | + tagsControl.render(); | |
| 723 | + } | |
| 724 | + }); | |
| 725 | + | |
| 726 | + new GetResponse({ | |
| 727 | + $element: view.$el | |
| 728 | + }); | |
| 729 | +} | |
| 730 | + | |
| 731 | +},{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],9:[function(require,module,exports){ | |
| 732 | +"use strict"; | |
| 733 | + | |
| 734 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 735 | + | |
| 736 | +Object.defineProperty(exports, "__esModule", { | |
| 737 | + value: true | |
| 738 | +}); | |
| 739 | +exports["default"] = _default; | |
| 740 | + | |
| 741 | +var _crmBase = _interopRequireDefault(require("./crm-base")); | |
| 742 | + | |
| 743 | +function _default(panel, model, view) { | |
| 744 | + var Growmatic = _crmBase["default"].extend({ | |
| 745 | + panel: panel, | |
| 746 | + model: model, | |
| 747 | + action: 'growmatik', | |
| 748 | + updateAdditionalControls: function updateAdditionalControls() { | |
| 749 | + if (!this.additionalData.hasOwnProperty('tags')) { | |
| 750 | + return; | |
| 751 | + } | |
| 752 | + | |
| 753 | + var tagsControl = this.getControlView("".concat(this.action, "_tags")); | |
| 754 | + tagsControl.model.set('options', this.additionalData.tags); | |
| 755 | + tagsControl.render(); | |
| 756 | + } | |
| 757 | + }); | |
| 758 | + | |
| 759 | + new Growmatic({ | |
| 760 | + $element: view.$el | |
| 761 | + }); | |
| 762 | +} | |
| 763 | + | |
| 764 | +},{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],10:[function(require,module,exports){ | |
| 765 | +"use strict"; | |
| 766 | + | |
| 767 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 768 | + | |
| 769 | +Object.defineProperty(exports, "__esModule", { | |
| 770 | + value: true | |
| 771 | +}); | |
| 772 | +exports["default"] = _default; | |
| 773 | + | |
| 774 | +var _crmBase = _interopRequireDefault(require("./crm-base")); | |
| 775 | + | |
| 776 | +function _default(panel, model, view) { | |
| 777 | + var ConvertKit = _crmBase["default"].extend({ | |
| 778 | + panel: panel, | |
| 779 | + model: model, | |
| 780 | + action: 'mailchimp', | |
| 781 | + // Override just to add spinner, since the request time is little heavier than other actions. | |
| 782 | + ajaxUpdateAdditionalData: function ajaxUpdateAdditionalData() { | |
| 783 | + this.addControlSpinner("".concat(this.action, "_tags")); | |
| 784 | + this.addControlSpinner("".concat(this.action, "_groups")); | |
| 785 | + | |
| 786 | + _crmBase["default"].prototype.ajaxUpdateAdditionalData.apply(this, arguments); | |
| 787 | + }, | |
| 788 | + updateAdditionalControls: function updateAdditionalControls() { | |
| 789 | + var _this = this; | |
| 790 | + | |
| 791 | + this.removeControlSpinner("".concat(this.action, "_tags")); | |
| 792 | + this.removeControlSpinner("".concat(this.action, "_groups")); | |
| 793 | + | |
| 794 | + _.each(['tags', 'groups'], function (control) { | |
| 795 | + if (!_this.additionalData.hasOwnProperty("".concat(control))) { | |
| 796 | + return; | |
| 797 | + } | |
| 798 | + | |
| 799 | + var controlView = _this.getControlView("".concat(_this.action, "_").concat(control)); | |
| 800 | + | |
| 801 | + controlView.model.set('options', _this.additionalData["".concat(control)]); | |
| 802 | + controlView.render(); | |
| 803 | + }); | |
| 804 | + } | |
| 805 | + }); | |
| 806 | + | |
| 807 | + new ConvertKit({ | |
| 808 | + $element: view.$el | |
| 809 | + }); | |
| 810 | +} | |
| 811 | + | |
| 812 | +},{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],11:[function(require,module,exports){ | |
| 813 | +"use strict"; | |
| 814 | + | |
| 815 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 816 | + | |
| 817 | +Object.defineProperty(exports, "__esModule", { | |
| 818 | + value: true | |
| 819 | +}); | |
| 820 | +exports["default"] = _default; | |
| 821 | + | |
| 822 | +var _crmBase = _interopRequireDefault(require("./crm-base")); | |
| 823 | + | |
| 824 | +function _default(panel, model, view) { | |
| 825 | + var MailerLite = _crmBase["default"].extend({ | |
| 826 | + panel: panel, | |
| 827 | + model: model, | |
| 828 | + action: 'mailerlite' | |
| 829 | + }); | |
| 830 | + | |
| 831 | + new MailerLite({ | |
| 832 | + $element: view.$el | |
| 833 | + }); | |
| 834 | +} | |
| 835 | + | |
| 836 | +},{"./crm-base":6,"@babel/runtime/helpers/interopRequireDefault":16}],12:[function(require,module,exports){ | |
| 837 | +"use strict"; | |
| 838 | + | |
| 839 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 840 | + | |
| 841 | +Object.defineProperty(exports, "__esModule", { | |
| 842 | + value: true | |
| 843 | +}); | |
| 844 | +exports["default"] = _default; | |
| 845 | + | |
| 846 | +var _util = _interopRequireDefault(require("../../util")); | |
| 847 | + | |
| 848 | +function _default(panel, model, view) { | |
| 849 | + var itiTel = _util["default"].extend({ | |
| 850 | + panel: panel, | |
| 851 | + model: model, | |
| 852 | + view: view, | |
| 853 | + sectionName: 'section_form_fields', | |
| 854 | + countries: {}, | |
| 855 | + onInit: function onInit() { | |
| 856 | + this.getCountries(); | |
| 857 | + this.refresh(); | |
| 858 | + elementor.channels.editor.on('section:activated', this.onSectionActivated); | |
| 859 | + }, | |
| 860 | + onSectionActivated: function onSectionActivated(activeSection, section) { | |
| 861 | + if (activeSection !== this.sectionName || section.model.id !== model.get('id')) { | |
| 862 | + return; | |
| 863 | + } | |
| 864 | + | |
| 865 | + this.refresh(); | |
| 866 | + }, | |
| 867 | + refresh: function refresh() { | |
| 868 | + var _this = this; | |
| 869 | + | |
| 870 | + var fieldsRepeater = this.getControlView('fields'); | |
| 871 | + this.select2s = []; | |
| 872 | + fieldsRepeater.children.each(function (row) { | |
| 873 | + var typeControl = row.children.find(function (option) { | |
| 874 | + return 'type' === option.model.get('name'); | |
| 875 | + }).$el.find('select'); | |
| 876 | + typeControl.off('change', _this.refresh).change(_this.refresh); | |
| 877 | + | |
| 878 | + if ('tel' !== typeControl.val()) { | |
| 879 | + return; | |
| 880 | + } | |
| 881 | + | |
| 882 | + var allowDropdownControl = row.children.find(function (option) { | |
| 883 | + return 'iti_tel_allow_dropdown' === option.model.get('name'); | |
| 884 | + }).$el.find('input'); | |
| 885 | + allowDropdownControl.off('change', _this.refresh).change(_this.refresh); | |
| 886 | + var allowDropdown = allowDropdownControl[0].checked; | |
| 887 | + var countrySelect2 = row.children.find(function (option) { | |
| 888 | + return 'iti_tel_country_include' === option.model.get('name'); | |
| 889 | + }); | |
| 890 | + countrySelect2.model.set('multiple', allowDropdown); | |
| 891 | + countrySelect2.model.set('options', _this.countries); | |
| 892 | + countrySelect2.render(); | |
| 893 | + }); | |
| 894 | + fieldsRepeater.off('add:child', this.refresh).on('add:child', this.refresh); | |
| 895 | + }, | |
| 896 | + getCountries: function getCountries() { | |
| 897 | + var _this2 = this; | |
| 898 | + | |
| 899 | + require('intl-tel-input'); | |
| 900 | + | |
| 901 | + _.each(window.intlTelInputGlobals.getCountryData(), function (country) { | |
| 902 | + _this2.countries[country.iso2] = country.name; | |
| 903 | + }); | |
| 904 | + } | |
| 905 | + }); | |
| 906 | + | |
| 907 | + new itiTel({ | |
| 908 | + $element: view.$el | |
| 909 | + }); | |
| 910 | +} | |
| 911 | + | |
| 912 | +},{"../../util":14,"@babel/runtime/helpers/interopRequireDefault":16,"intl-tel-input":27}],13:[function(require,module,exports){ | |
| 913 | +"use strict"; | |
| 914 | + | |
| 915 | +Object.defineProperty(exports, "__esModule", { | |
| 916 | + value: true | |
| 917 | +}); | |
| 918 | +exports["default"] = _default; | |
| 919 | + | |
| 920 | +function _default(panel, model, view) { | |
| 921 | + var optinModules = { | |
| 922 | + activecampaign: require('./actions/activecampaign')["default"], | |
| 923 | + drip: require('./actions/drip')["default"], | |
| 924 | + convertkit: require('./actions/convertkit')["default"], | |
| 925 | + getresponse: require('./actions/getresponse')["default"], | |
| 926 | + growmatik: require('./actions/growmatik')["default"], | |
| 927 | + mailchimp: require('./actions/mailchimp')["default"], | |
| 928 | + mailerlite: require('./actions/mailerlite')["default"], | |
| 929 | + iti: require('./misc/intelligent-tel')["default"] | |
| 930 | + }; | |
| 931 | + | |
| 932 | + for (var module in optinModules) { | |
| 933 | + optinModules[module](panel, model, view); | |
| 934 | + } | |
| 935 | +} | |
| 936 | + | |
| 937 | +},{"./actions/activecampaign":4,"./actions/convertkit":5,"./actions/drip":7,"./actions/getresponse":8,"./actions/growmatik":9,"./actions/mailchimp":10,"./actions/mailerlite":11,"./misc/intelligent-tel":12}],14:[function(require,module,exports){ | |
| 938 | +"use strict"; | |
| 939 | + | |
| 940 | +Object.defineProperty(exports, "__esModule", { | |
| 941 | + value: true | |
| 942 | +}); | |
| 943 | +exports["default"] = void 0; | |
| 944 | +var Module = elementorModules.editor.utils.Module.extend({ | |
| 945 | + panel: null, | |
| 946 | + getControl: function getControl(propertyName) { | |
| 947 | + if (!this.panel) { | |
| 948 | + return; | |
| 949 | + } | |
| 950 | + | |
| 951 | + var control = this.panel.getCurrentPageView().collection.findWhere({ | |
| 952 | + name: propertyName | |
| 953 | + }); | |
| 954 | + return control; | |
| 955 | + }, | |
| 956 | + getControlView: function getControlView(propertyName) { | |
| 957 | + if (!this.panel) { | |
| 958 | + return; | |
| 959 | + } | |
| 960 | + | |
| 961 | + var control = this.getControl(propertyName); | |
| 962 | + var view = this.panel.getCurrentPageView().children.findByModelCid(control.cid); | |
| 963 | + return view; | |
| 964 | + }, | |
| 965 | + getControlValue: function getControlValue(id) { | |
| 966 | + return this.getControlView(id).getControlValue(); | |
| 967 | + }, | |
| 968 | + addControlSpinner: function addControlSpinner(name) { | |
| 969 | + var $el = this.getControlView(name).$el, | |
| 970 | + $input = $el.find(':input'); | |
| 971 | + | |
| 972 | + if ($input.attr('disabled') || $el.find('.elementor-control-spinner').length > 0) { | |
| 973 | + return; | |
| 974 | + } | |
| 975 | + | |
| 976 | + $input.attr('disabled', true); | |
| 977 | + $el.find('.elementor-control-title').after('<span style="display:inline-flex" class="elementor-control-spinner"><span class="fa fa-spinner fa-spin"></span> </span>'); | |
| 978 | + }, | |
| 979 | + removeControlSpinner: function removeControlSpinner(name) { | |
| 980 | + var $el = this.getControlView(name).$el; | |
| 981 | + $el.find(':input').attr('disabled', false); | |
| 982 | + $el.find('.elementor-control-spinner').remove(); | |
| 983 | + }, | |
| 984 | + getElementSettings: function getElementSettings(model, name) { | |
| 985 | + if (!model) { | |
| 986 | + return null; | |
| 987 | + } | |
| 988 | + | |
| 989 | + var value = model.get('settings').get(name); | |
| 990 | + return value instanceof window.Backbone.Collection ? value.toJSON() : value; | |
| 991 | + } | |
| 992 | +}); | |
| 993 | +var _default = Module; | |
| 994 | +exports["default"] = _default; | |
| 995 | + | |
| 996 | +},{}],15:[function(require,module,exports){ | |
| 997 | +function _defineProperty(obj, key, value) { | |
| 998 | + if (key in obj) { | |
| 999 | + Object.defineProperty(obj, key, { | |
| 1000 | + value: value, | |
| 1001 | + enumerable: true, | |
| 1002 | + configurable: true, | |
| 1003 | + writable: true | |
| 1004 | + }); | |
| 1005 | + } else { | |
| 1006 | + obj[key] = value; | |
| 1007 | + } | |
| 1008 | + | |
| 1009 | + return obj; | |
| 1010 | +} | |
| 1011 | + | |
| 1012 | +module.exports = _defineProperty; | |
| 1013 | +},{}],16:[function(require,module,exports){ | |
| 1014 | +function _interopRequireDefault(obj) { | |
| 1015 | + return obj && obj.__esModule ? obj : { | |
| 1016 | + "default": obj | |
| 1017 | + }; | |
| 1018 | +} | |
| 1019 | + | |
| 1020 | +module.exports = _interopRequireDefault; | |
| 1021 | +},{}],17:[function(require,module,exports){ | |
| 1022 | +'use strict'; | |
| 1023 | + | |
| 1024 | +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | |
| 1025 | + | |
| 1026 | +var postfix = _interopDefault(require('@tannin/postfix')); | |
| 1027 | +var evaluate = _interopDefault(require('@tannin/evaluate')); | |
| 1028 | + | |
| 1029 | +/** | |
| 1030 | + * Given a C expression, returns a function which can be called to evaluate its | |
| 1031 | + * result. | |
| 1032 | + * | |
| 1033 | + * @example | |
| 1034 | + * | |
| 1035 | + * ```js | |
| 1036 | + * import compile from '@tannin/compile'; | |
| 1037 | + * | |
| 1038 | + * const evaluate = compile( 'n > 1' ); | |
| 1039 | + * | |
| 1040 | + * evaluate( { n: 2 } ); | |
| 1041 | + * // ⇒ true | |
| 1042 | + * ``` | |
| 1043 | + * | |
| 1044 | + * @param {string} expression C expression. | |
| 1045 | + * | |
| 1046 | + * @return {(variables?:{[variable:string]:*})=>*} Compiled evaluator. | |
| 1047 | + */ | |
| 1048 | +function compile( expression ) { | |
| 1049 | + var terms = postfix( expression ); | |
| 1050 | + | |
| 1051 | + return function( variables ) { | |
| 1052 | + return evaluate( terms, variables ); | |
| 1053 | + }; | |
| 1054 | +} | |
| 1055 | + | |
| 1056 | +module.exports = compile; | |
| 1057 | + | |
| 1058 | +},{"@tannin/evaluate":18,"@tannin/postfix":20}],18:[function(require,module,exports){ | |
| 1059 | +'use strict'; | |
| 1060 | + | |
| 1061 | +/** | |
| 1062 | + * Operator callback functions. | |
| 1063 | + * | |
| 1064 | + * @type {Object} | |
| 1065 | + */ | |
| 1066 | +var OPERATORS = { | |
| 1067 | + '!': function( a ) { | |
| 1068 | + return ! a; | |
| 1069 | + }, | |
| 1070 | + '*': function( a, b ) { | |
| 1071 | + return a * b; | |
| 1072 | + }, | |
| 1073 | + '/': function( a, b ) { | |
| 1074 | + return a / b; | |
| 1075 | + }, | |
| 1076 | + '%': function( a, b ) { | |
| 1077 | + return a % b; | |
| 1078 | + }, | |
| 1079 | + '+': function( a, b ) { | |
| 1080 | + return a + b; | |
| 1081 | + }, | |
| 1082 | + '-': function( a, b ) { | |
| 1083 | + return a - b; | |
| 1084 | + }, | |
| 1085 | + '<': function( a, b ) { | |
| 1086 | + return a < b; | |
| 1087 | + }, | |
| 1088 | + '<=': function( a, b ) { | |
| 1089 | + return a <= b; | |
| 1090 | + }, | |
| 1091 | + '>': function( a, b ) { | |
| 1092 | + return a > b; | |
| 1093 | + }, | |
| 1094 | + '>=': function( a, b ) { | |
| 1095 | + return a >= b; | |
| 1096 | + }, | |
| 1097 | + '==': function( a, b ) { | |
| 1098 | + return a === b; | |
| 1099 | + }, | |
| 1100 | + '!=': function( a, b ) { | |
| 1101 | + return a !== b; | |
| 1102 | + }, | |
| 1103 | + '&&': function( a, b ) { | |
| 1104 | + return a && b; | |
| 1105 | + }, | |
| 1106 | + '||': function( a, b ) { | |
| 1107 | + return a || b; | |
| 1108 | + }, | |
| 1109 | + '?:': function( a, b, c ) { | |
| 1110 | + if ( a ) { | |
| 1111 | + throw b; | |
| 1112 | + } | |
| 1113 | + | |
| 1114 | + return c; | |
| 1115 | + }, | |
| 1116 | +}; | |
| 1117 | + | |
| 1118 | +/** | |
| 1119 | + * Given an array of postfix terms and operand variables, returns the result of | |
| 1120 | + * the postfix evaluation. | |
| 1121 | + * | |
| 1122 | + * @example | |
| 1123 | + * | |
| 1124 | + * ```js | |
| 1125 | + * import evaluate from '@tannin/evaluate'; | |
| 1126 | + * | |
| 1127 | + * // 3 + 4 * 5 / 6 ⇒ '3 4 5 * 6 / +' | |
| 1128 | + * const terms = [ '3', '4', '5', '*', '6', '/', '+' ]; | |
| 1129 | + * | |
| 1130 | + * evaluate( terms, {} ); | |
| 1131 | + * // ⇒ 6.333333333333334 | |
| 1132 | + * ``` | |
| 1133 | + * | |
| 1134 | + * @param {string[]} postfix Postfix terms. | |
| 1135 | + * @param {Object} variables Operand variables. | |
| 1136 | + * | |
| 1137 | + * @return {*} Result of evaluation. | |
| 1138 | + */ | |
| 1139 | +function evaluate( postfix, variables ) { | |
| 1140 | + var stack = [], | |
| 1141 | + i, j, args, getOperatorResult, term, value; | |
| 1142 | + | |
| 1143 | + for ( i = 0; i < postfix.length; i++ ) { | |
| 1144 | + term = postfix[ i ]; | |
| 1145 | + | |
| 1146 | + getOperatorResult = OPERATORS[ term ]; | |
| 1147 | + if ( getOperatorResult ) { | |
| 1148 | + // Pop from stack by number of function arguments. | |
| 1149 | + j = getOperatorResult.length; | |
| 1150 | + args = Array( j ); | |
| 1151 | + while ( j-- ) { | |
| 1152 | + args[ j ] = stack.pop(); | |
| 1153 | + } | |
| 1154 | + | |
| 1155 | + try { | |
| 1156 | + value = getOperatorResult.apply( null, args ); | |
| 1157 | + } catch ( earlyReturn ) { | |
| 1158 | + return earlyReturn; | |
| 1159 | + } | |
| 1160 | + } else if ( variables.hasOwnProperty( term ) ) { | |
| 1161 | + value = variables[ term ]; | |
| 1162 | + } else { | |
| 1163 | + value = +term; | |
| 1164 | + } | |
| 1165 | + | |
| 1166 | + stack.push( value ); | |
| 1167 | + } | |
| 1168 | + | |
| 1169 | + return stack[ 0 ]; | |
| 1170 | +} | |
| 1171 | + | |
| 1172 | +module.exports = evaluate; | |
| 1173 | + | |
| 1174 | +},{}],19:[function(require,module,exports){ | |
| 1175 | +'use strict'; | |
| 1176 | + | |
| 1177 | +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | |
| 1178 | + | |
| 1179 | +var compile = _interopDefault(require('@tannin/compile')); | |
| 1180 | + | |
| 1181 | +/** | |
| 1182 | + * Given a C expression, returns a function which, when called with a value, | |
| 1183 | + * evaluates the result with the value assumed to be the "n" variable of the | |
| 1184 | + * expression. The result will be coerced to its numeric equivalent. | |
| 1185 | + * | |
| 1186 | + * @param {string} expression C expression. | |
| 1187 | + * | |
| 1188 | + * @return {Function} Evaluator function. | |
| 1189 | + */ | |
| 1190 | +function pluralForms( expression ) { | |
| 1191 | + var evaluate = compile( expression ); | |
| 1192 | + | |
| 1193 | + return function( n ) { | |
| 1194 | + return +evaluate( { n: n } ); | |
| 1195 | + }; | |
| 1196 | +} | |
| 1197 | + | |
| 1198 | +module.exports = pluralForms; | |
| 1199 | + | |
| 1200 | +},{"@tannin/compile":17}],20:[function(require,module,exports){ | |
| 1201 | +'use strict'; | |
| 1202 | + | |
| 1203 | +var PRECEDENCE, OPENERS, TERMINATORS, PATTERN; | |
| 1204 | + | |
| 1205 | +/** | |
| 1206 | + * Operator precedence mapping. | |
| 1207 | + * | |
| 1208 | + * @type {Object} | |
| 1209 | + */ | |
| 1210 | +PRECEDENCE = { | |
| 1211 | + '(': 9, | |
| 1212 | + '!': 8, | |
| 1213 | + '*': 7, | |
| 1214 | + '/': 7, | |
| 1215 | + '%': 7, | |
| 1216 | + '+': 6, | |
| 1217 | + '-': 6, | |
| 1218 | + '<': 5, | |
| 1219 | + '<=': 5, | |
| 1220 | + '>': 5, | |
| 1221 | + '>=': 5, | |
| 1222 | + '==': 4, | |
| 1223 | + '!=': 4, | |
| 1224 | + '&&': 3, | |
| 1225 | + '||': 2, | |
| 1226 | + '?': 1, | |
| 1227 | + '?:': 1, | |
| 1228 | +}; | |
| 1229 | + | |
| 1230 | +/** | |
| 1231 | + * Characters which signal pair opening, to be terminated by terminators. | |
| 1232 | + * | |
| 1233 | + * @type {string[]} | |
| 1234 | + */ | |
| 1235 | +OPENERS = [ '(', '?' ]; | |
| 1236 | + | |
| 1237 | +/** | |
| 1238 | + * Characters which signal pair termination, the value an array with the | |
| 1239 | + * opener as its first member. The second member is an optional operator | |
| 1240 | + * replacement to push to the stack. | |
| 1241 | + * | |
| 1242 | + * @type {string[]} | |
| 1243 | + */ | |
| 1244 | +TERMINATORS = { | |
| 1245 | + ')': [ '(' ], | |
| 1246 | + ':': [ '?', '?:' ], | |
| 1247 | +}; | |
| 1248 | + | |
| 1249 | +/** | |
| 1250 | + * Pattern matching operators and openers. | |
| 1251 | + * | |
| 1252 | + * @type {RegExp} | |
| 1253 | + */ | |
| 1254 | +PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/; | |
| 1255 | + | |
| 1256 | +/** | |
| 1257 | + * Given a C expression, returns the equivalent postfix (Reverse Polish) | |
| 1258 | + * notation terms as an array. | |
| 1259 | + * | |
| 1260 | + * If a postfix string is desired, simply `.join( ' ' )` the result. | |
| 1261 | + * | |
| 1262 | + * @example | |
| 1263 | + * | |
| 1264 | + * ```js | |
| 1265 | + * import postfix from '@tannin/postfix'; | |
| 1266 | + * | |
| 1267 | + * postfix( 'n > 1' ); | |
| 1268 | + * // ⇒ [ 'n', '1', '>' ] | |
| 1269 | + * ``` | |
| 1270 | + * | |
| 1271 | + * @param {string} expression C expression. | |
| 1272 | + * | |
| 1273 | + * @return {string[]} Postfix terms. | |
| 1274 | + */ | |
| 1275 | +function postfix( expression ) { | |
| 1276 | + var terms = [], | |
| 1277 | + stack = [], | |
| 1278 | + match, operator, term, element; | |
| 1279 | + | |
| 1280 | + while ( ( match = expression.match( PATTERN ) ) ) { | |
| 1281 | + operator = match[ 0 ]; | |
| 1282 | + | |
| 1283 | + // Term is the string preceding the operator match. It may contain | |
| 1284 | + // whitespace, and may be empty (if operator is at beginning). | |
| 1285 | + term = expression.substr( 0, match.index ).trim(); | |
| 1286 | + if ( term ) { | |
| 1287 | + terms.push( term ); | |
| 1288 | + } | |
| 1289 | + | |
| 1290 | + while ( ( element = stack.pop() ) ) { | |
| 1291 | + if ( TERMINATORS[ operator ] ) { | |
| 1292 | + if ( TERMINATORS[ operator ][ 0 ] === element ) { | |
| 1293 | + // Substitution works here under assumption that because | |
| 1294 | + // the assigned operator will no longer be a terminator, it | |
| 1295 | + // will be pushed to the stack during the condition below. | |
| 1296 | + operator = TERMINATORS[ operator ][ 1 ] || operator; | |
| 1297 | + break; | |
| 1298 | + } | |
| 1299 | + } else if ( OPENERS.indexOf( element ) >= 0 || PRECEDENCE[ element ] < PRECEDENCE[ operator ] ) { | |
| 1300 | + // Push to stack if either an opener or when pop reveals an | |
| 1301 | + // element of lower precedence. | |
| 1302 | + stack.push( element ); | |
| 1303 | + break; | |
| 1304 | + } | |
| 1305 | + | |
| 1306 | + // For each popped from stack, push to terms. | |
| 1307 | + terms.push( element ); | |
| 1308 | + } | |
| 1309 | + | |
| 1310 | + if ( ! TERMINATORS[ operator ] ) { | |
| 1311 | + stack.push( operator ); | |
| 1312 | + } | |
| 1313 | + | |
| 1314 | + // Slice matched fragment from expression to continue match. | |
| 1315 | + expression = expression.substr( match.index + operator.length ); | |
| 1316 | + } | |
| 1317 | + | |
| 1318 | + // Push remainder of operand, if exists, to terms. | |
| 1319 | + expression = expression.trim(); | |
| 1320 | + if ( expression ) { | |
| 1321 | + terms.push( expression ); | |
| 1322 | + } | |
| 1323 | + | |
| 1324 | + // Pop remaining items from stack into terms. | |
| 1325 | + return terms.concat( stack.reverse() ); | |
| 1326 | +} | |
| 1327 | + | |
| 1328 | +module.exports = postfix; | |
| 1329 | + | |
| 1330 | +},{}],21:[function(require,module,exports){ | |
| 1331 | +"use strict"; | |
| 1332 | + | |
| 1333 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 1334 | + | |
| 1335 | +Object.defineProperty(exports, "__esModule", { | |
| 1336 | + value: true | |
| 1337 | +}); | |
| 1338 | +exports.createI18n = void 0; | |
| 1339 | + | |
| 1340 | +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | |
| 1341 | + | |
| 1342 | +var _tannin = _interopRequireDefault(require("tannin")); | |
| 1343 | + | |
| 1344 | +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | |
| 1345 | + | |
| 1346 | +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | |
| 1347 | + | |
| 1348 | +/** | |
| 1349 | + * @typedef {Record<string,any>} LocaleData | |
| 1350 | + */ | |
| 1351 | + | |
| 1352 | +/** | |
| 1353 | + * Default locale data to use for Tannin domain when not otherwise provided. | |
| 1354 | + * Assumes an English plural forms expression. | |
| 1355 | + * | |
| 1356 | + * @type {LocaleData} | |
| 1357 | + */ | |
| 1358 | +var DEFAULT_LOCALE_DATA = { | |
| 1359 | + '': { | |
| 1360 | + /** @param {number} n */ | |
| 1361 | + plural_forms: function plural_forms(n) { | |
| 1362 | + return n === 1 ? 0 : 1; | |
| 1363 | + } | |
| 1364 | + } | |
| 1365 | +}; | |
| 1366 | +/** | |
| 1367 | + * An i18n instance | |
| 1368 | + * | |
| 1369 | + * @typedef {Object} I18n | |
| 1370 | + * @property {Function} setLocaleData Merges locale data into the Tannin instance by domain. Accepts data in a | |
| 1371 | + * Jed-formatted JSON object shape. | |
| 1372 | + * @property {Function} __ Retrieve the translation of text. | |
| 1373 | + * @property {Function} _x Retrieve translated string with gettext context. | |
| 1374 | + * @property {Function} _n Translates and retrieves the singular or plural form based on the supplied | |
| 1375 | + * number. | |
| 1376 | + * @property {Function} _nx Translates and retrieves the singular or plural form based on the supplied | |
| 1377 | + * number, with gettext context. | |
| 1378 | + * @property {Function} isRTL Check if current locale is RTL. | |
| 1379 | + */ | |
| 1380 | + | |
| 1381 | +/** | |
| 1382 | + * Create an i18n instance | |
| 1383 | + * | |
| 1384 | + * @param {LocaleData} [initialData] Locale data configuration. | |
| 1385 | + * @param {string} [initialDomain] Domain for which configuration applies. | |
| 1386 | + * @return {I18n} I18n instance | |
| 1387 | + */ | |
| 1388 | + | |
| 1389 | +var createI18n = function createI18n(initialData, initialDomain) { | |
| 1390 | + /** | |
| 1391 | + * The underlying instance of Tannin to which exported functions interface. | |
| 1392 | + * | |
| 1393 | + * @type {Tannin} | |
| 1394 | + */ | |
| 1395 | + var tannin = new _tannin.default({}); | |
| 1396 | + /** | |
| 1397 | + * Merges locale data into the Tannin instance by domain. Accepts data in a | |
| 1398 | + * Jed-formatted JSON object shape. | |
| 1399 | + * | |
| 1400 | + * @see http://messageformat.github.io/Jed/ | |
| 1401 | + * | |
| 1402 | + * @param {LocaleData} [data] Locale data configuration. | |
| 1403 | + * @param {string} [domain] Domain for which configuration applies. | |
| 1404 | + */ | |
| 1405 | + | |
| 1406 | + var setLocaleData = function setLocaleData(data) { | |
| 1407 | + var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default'; | |
| 1408 | + tannin.data[domain] = _objectSpread({}, DEFAULT_LOCALE_DATA, {}, tannin.data[domain], {}, data); // Populate default domain configuration (supported locale date which omits | |
| 1409 | + // a plural forms expression). | |
| 1410 | + | |
| 1411 | + tannin.data[domain][''] = _objectSpread({}, DEFAULT_LOCALE_DATA[''], {}, tannin.data[domain]['']); | |
| 1412 | + }; | |
| 1413 | + /** | |
| 1414 | + * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not | |
| 1415 | + * otherwise previously assigned. | |
| 1416 | + * | |
| 1417 | + * @param {string|undefined} domain Domain to retrieve the translated text. | |
| 1418 | + * @param {string|undefined} context Context information for the translators. | |
| 1419 | + * @param {string} single Text to translate if non-plural. Used as | |
| 1420 | + * fallback return value on a caught error. | |
| 1421 | + * @param {string} [plural] The text to be used if the number is | |
| 1422 | + * plural. | |
| 1423 | + * @param {number} [number] The number to compare against to use | |
| 1424 | + * either the singular or plural form. | |
| 1425 | + * | |
| 1426 | + * @return {string} The translated string. | |
| 1427 | + */ | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + var dcnpgettext = function dcnpgettext() { | |
| 1431 | + var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default'; | |
| 1432 | + var context = arguments.length > 1 ? arguments[1] : undefined; | |
| 1433 | + var single = arguments.length > 2 ? arguments[2] : undefined; | |
| 1434 | + var plural = arguments.length > 3 ? arguments[3] : undefined; | |
| 1435 | + var number = arguments.length > 4 ? arguments[4] : undefined; | |
| 1436 | + | |
| 1437 | + if (!tannin.data[domain]) { | |
| 1438 | + setLocaleData(undefined, domain); | |
| 1439 | + } | |
| 1440 | + | |
| 1441 | + return tannin.dcnpgettext(domain, context, single, plural, number); | |
| 1442 | + }; | |
| 1443 | + /** | |
| 1444 | + * Retrieve the translation of text. | |
| 1445 | + * | |
| 1446 | + * @see https://developer.wordpress.org/reference/functions/__/ | |
| 1447 | + * | |
| 1448 | + * @param {string} text Text to translate. | |
| 1449 | + * @param {string} [domain] Domain to retrieve the translated text. | |
| 1450 | + * | |
| 1451 | + * @return {string} Translated text. | |
| 1452 | + */ | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + var __ = function __(text, domain) { | |
| 1456 | + return dcnpgettext(domain, undefined, text); | |
| 1457 | + }; | |
| 1458 | + /** | |
| 1459 | + * Retrieve translated string with gettext context. | |
| 1460 | + * | |
| 1461 | + * @see https://developer.wordpress.org/reference/functions/_x/ | |
| 1462 | + * | |
| 1463 | + * @param {string} text Text to translate. | |
| 1464 | + * @param {string} context Context information for the translators. | |
| 1465 | + * @param {string} [domain] Domain to retrieve the translated text. | |
| 1466 | + * | |
| 1467 | + * @return {string} Translated context string without pipe. | |
| 1468 | + */ | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + var _x = function _x(text, context, domain) { | |
| 1472 | + return dcnpgettext(domain, context, text); | |
| 1473 | + }; | |
| 1474 | + /** | |
| 1475 | + * Translates and retrieves the singular or plural form based on the supplied | |
| 1476 | + * number. | |
| 1477 | + * | |
| 1478 | + * @see https://developer.wordpress.org/reference/functions/_n/ | |
| 1479 | + * | |
| 1480 | + * @param {string} single The text to be used if the number is singular. | |
| 1481 | + * @param {string} plural The text to be used if the number is plural. | |
| 1482 | + * @param {number} number The number to compare against to use either the | |
| 1483 | + * singular or plural form. | |
| 1484 | + * @param {string} [domain] Domain to retrieve the translated text. | |
| 1485 | + * | |
| 1486 | + * @return {string} The translated singular or plural form. | |
| 1487 | + */ | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + var _n = function _n(single, plural, number, domain) { | |
| 1491 | + return dcnpgettext(domain, undefined, single, plural, number); | |
| 1492 | + }; | |
| 1493 | + /** | |
| 1494 | + * Translates and retrieves the singular or plural form based on the supplied | |
| 1495 | + * number, with gettext context. | |
| 1496 | + * | |
| 1497 | + * @see https://developer.wordpress.org/reference/functions/_nx/ | |
| 1498 | + * | |
| 1499 | + * @param {string} single The text to be used if the number is singular. | |
| 1500 | + * @param {string} plural The text to be used if the number is plural. | |
| 1501 | + * @param {number} number The number to compare against to use either the | |
| 1502 | + * singular or plural form. | |
| 1503 | + * @param {string} context Context information for the translators. | |
| 1504 | + * @param {string} [domain] Domain to retrieve the translated text. | |
| 1505 | + * | |
| 1506 | + * @return {string} The translated singular or plural form. | |
| 1507 | + */ | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + var _nx = function _nx(single, plural, number, context, domain) { | |
| 1511 | + return dcnpgettext(domain, context, single, plural, number); | |
| 1512 | + }; | |
| 1513 | + /** | |
| 1514 | + * Check if current locale is RTL. | |
| 1515 | + * | |
| 1516 | + * **RTL (Right To Left)** is a locale property indicating that text is written from right to left. | |
| 1517 | + * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common | |
| 1518 | + * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages, | |
| 1519 | + * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`). | |
| 1520 | + * | |
| 1521 | + * @return {boolean} Whether locale is RTL. | |
| 1522 | + */ | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + var isRTL = function isRTL() { | |
| 1526 | + return 'rtl' === _x('ltr', 'text direction'); | |
| 1527 | + }; | |
| 1528 | + | |
| 1529 | + if (initialData) { | |
| 1530 | + setLocaleData(initialData, initialDomain); | |
| 1531 | + } | |
| 1532 | + | |
| 1533 | + return { | |
| 1534 | + setLocaleData: setLocaleData, | |
| 1535 | + __: __, | |
| 1536 | + _x: _x, | |
| 1537 | + _n: _n, | |
| 1538 | + _nx: _nx, | |
| 1539 | + isRTL: isRTL | |
| 1540 | + }; | |
| 1541 | +}; | |
| 1542 | + | |
| 1543 | +exports.createI18n = createI18n; | |
| 1544 | + | |
| 1545 | +},{"@babel/runtime/helpers/defineProperty":15,"@babel/runtime/helpers/interopRequireDefault":16,"tannin":30}],22:[function(require,module,exports){ | |
| 1546 | +"use strict"; | |
| 1547 | + | |
| 1548 | +Object.defineProperty(exports, "__esModule", { | |
| 1549 | + value: true | |
| 1550 | +}); | |
| 1551 | +exports.isRTL = exports._nx = exports._n = exports._x = exports.__ = exports.setLocaleData = void 0; | |
| 1552 | + | |
| 1553 | +var _createI18n = require("./create-i18n"); | |
| 1554 | + | |
| 1555 | +/** | |
| 1556 | + * Internal dependencies | |
| 1557 | + */ | |
| 1558 | +var i18n = (0, _createI18n.createI18n)(); | |
| 1559 | +/* | |
| 1560 | + * Comments in this file are duplicated from ./i18n due to | |
| 1561 | + * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722 | |
| 1562 | + */ | |
| 1563 | + | |
| 1564 | +/** | |
| 1565 | + * @typedef {import('./create-i18n').LocaleData} LocaleData | |
| 1566 | + */ | |
| 1567 | + | |
| 1568 | +/** | |
| 1569 | + * Merges locale data into the Tannin instance by domain. Accepts data in a | |
| 1570 | + * Jed-formatted JSON object shape. | |
| 1571 | + * | |
| 1572 | + * @see http://messageformat.github.io/Jed/ | |
| 1573 | + * | |
| 1574 | + * @param {LocaleData} [data] Locale data configuration. | |
| 1575 | + * @param {string} [domain] Domain for which configuration applies. | |
| 1576 | + */ | |
| 1577 | + | |
| 1578 | +var setLocaleData = i18n.setLocaleData.bind(i18n); | |
| 1579 | +/** | |
| 1580 | + * Retrieve the translation of text. | |
| 1581 | + * | |
| 1582 | + * @see https://developer.wordpress.org/reference/functions/__/ | |
| 1583 | + * | |
| 1584 | + * @param {string} text Text to translate. | |
| 1585 | + * @param {string} [domain] Domain to retrieve the translated text. | |
| 1586 | + * | |
| 1587 | + * @return {string} Translated text. | |
| 1588 | + */ | |
| 1589 | + | |
| 1590 | +exports.setLocaleData = setLocaleData; | |
| 1591 | + | |
| 1592 | +var __ = i18n.__.bind(i18n); | |
| 1593 | +/** | |
| 1594 | + * Retrieve translated string with gettext context. | |
| 1595 | + * | |
| 1596 | + * @see https://developer.wordpress.org/reference/functions/_x/ | |
| 1597 | + * | |
| 1598 | + * @param {string} text Text to translate. | |
| 1599 | + * @param {string} context Context information for the translators. | |
| 1600 | + * @param {string} [domain] Domain to retrieve the translated text. | |
| 1601 | + * | |
| 1602 | + * @return {string} Translated context string without pipe. | |
| 1603 | + */ | |
| 1604 | + | |
| 1605 | + | |
| 1606 | +exports.__ = __; | |
| 1607 | + | |
| 1608 | +var _x = i18n._x.bind(i18n); | |
| 1609 | +/** | |
| 1610 | + * Translates and retrieves the singular or plural form based on the supplied | |
| 1611 | + * number. | |
| 1612 | + * | |
| 1613 | + * @see https://developer.wordpress.org/reference/functions/_n/ | |
| 1614 | + * | |
| 1615 | + * @param {string} single The text to be used if the number is singular. | |
| 1616 | + * @param {string} plural The text to be used if the number is plural. | |
| 1617 | + * @param {number} number The number to compare against to use either the | |
| 1618 | + * singular or plural form. | |
| 1619 | + * @param {string} [domain] Domain to retrieve the translated text. | |
| 1620 | + * | |
| 1621 | + * @return {string} The translated singular or plural form. | |
| 1622 | + */ | |
| 1623 | + | |
| 1624 | + | |
| 1625 | +exports._x = _x; | |
| 1626 | + | |
| 1627 | +var _n = i18n._n.bind(i18n); | |
| 1628 | +/** | |
| 1629 | + * Translates and retrieves the singular or plural form based on the supplied | |
| 1630 | + * number, with gettext context. | |
| 1631 | + * | |
| 1632 | + * @see https://developer.wordpress.org/reference/functions/_nx/ | |
| 1633 | + * | |
| 1634 | + * @param {string} single The text to be used if the number is singular. | |
| 1635 | + * @param {string} plural The text to be used if the number is plural. | |
| 1636 | + * @param {number} number The number to compare against to use either the | |
| 1637 | + * singular or plural form. | |
| 1638 | + * @param {string} context Context information for the translators. | |
| 1639 | + * @param {string} [domain] Domain to retrieve the translated text. | |
| 1640 | + * | |
| 1641 | + * @return {string} The translated singular or plural form. | |
| 1642 | + */ | |
| 1643 | + | |
| 1644 | + | |
| 1645 | +exports._n = _n; | |
| 1646 | + | |
| 1647 | +var _nx = i18n._nx.bind(i18n); | |
| 1648 | +/** | |
| 1649 | + * Check if current locale is RTL. | |
| 1650 | + * | |
| 1651 | + * **RTL (Right To Left)** is a locale property indicating that text is written from right to left. | |
| 1652 | + * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common | |
| 1653 | + * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages, | |
| 1654 | + * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`). | |
| 1655 | + * | |
| 1656 | + * @return {boolean} Whether locale is RTL. | |
| 1657 | + */ | |
| 1658 | + | |
| 1659 | + | |
| 1660 | +exports._nx = _nx; | |
| 1661 | +var isRTL = i18n.isRTL.bind(i18n); | |
| 1662 | +exports.isRTL = isRTL; | |
| 1663 | + | |
| 1664 | +},{"./create-i18n":21}],23:[function(require,module,exports){ | |
| 1665 | +"use strict"; | |
| 1666 | + | |
| 1667 | +Object.defineProperty(exports, "__esModule", { | |
| 1668 | + value: true | |
| 1669 | +}); | |
| 1670 | +var _exportNames = { | |
| 1671 | + sprintf: true, | |
| 1672 | + setLocaleData: true, | |
| 1673 | + __: true, | |
| 1674 | + _x: true, | |
| 1675 | + _n: true, | |
| 1676 | + _nx: true, | |
| 1677 | + isRTL: true | |
| 1678 | +}; | |
| 1679 | +Object.defineProperty(exports, "sprintf", { | |
| 1680 | + enumerable: true, | |
| 1681 | + get: function get() { | |
| 1682 | + return _sprintf.sprintf; | |
| 1683 | + } | |
| 1684 | +}); | |
| 1685 | +Object.defineProperty(exports, "setLocaleData", { | |
| 1686 | + enumerable: true, | |
| 1687 | + get: function get() { | |
| 1688 | + return _defaultI18n.setLocaleData; | |
| 1689 | + } | |
| 1690 | +}); | |
| 1691 | +Object.defineProperty(exports, "__", { | |
| 1692 | + enumerable: true, | |
| 1693 | + get: function get() { | |
| 1694 | + return _defaultI18n.__; | |
| 1695 | + } | |
| 1696 | +}); | |
| 1697 | +Object.defineProperty(exports, "_x", { | |
| 1698 | + enumerable: true, | |
| 1699 | + get: function get() { | |
| 1700 | + return _defaultI18n._x; | |
| 1701 | + } | |
| 1702 | +}); | |
| 1703 | +Object.defineProperty(exports, "_n", { | |
| 1704 | + enumerable: true, | |
| 1705 | + get: function get() { | |
| 1706 | + return _defaultI18n._n; | |
| 1707 | + } | |
| 1708 | +}); | |
| 1709 | +Object.defineProperty(exports, "_nx", { | |
| 1710 | + enumerable: true, | |
| 1711 | + get: function get() { | |
| 1712 | + return _defaultI18n._nx; | |
| 1713 | + } | |
| 1714 | +}); | |
| 1715 | +Object.defineProperty(exports, "isRTL", { | |
| 1716 | + enumerable: true, | |
| 1717 | + get: function get() { | |
| 1718 | + return _defaultI18n.isRTL; | |
| 1719 | + } | |
| 1720 | +}); | |
| 1721 | + | |
| 1722 | +var _sprintf = require("./sprintf"); | |
| 1723 | + | |
| 1724 | +var _createI18n = require("./create-i18n"); | |
| 1725 | + | |
| 1726 | +Object.keys(_createI18n).forEach(function (key) { | |
| 1727 | + if (key === "default" || key === "__esModule") return; | |
| 1728 | + if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | |
| 1729 | + Object.defineProperty(exports, key, { | |
| 1730 | + enumerable: true, | |
| 1731 | + get: function get() { | |
| 1732 | + return _createI18n[key]; | |
| 1733 | + } | |
| 1734 | + }); | |
| 1735 | +}); | |
| 1736 | + | |
| 1737 | +var _defaultI18n = require("./default-i18n"); | |
| 1738 | + | |
| 1739 | +},{"./create-i18n":21,"./default-i18n":22,"./sprintf":24}],24:[function(require,module,exports){ | |
| 1740 | +"use strict"; | |
| 1741 | + | |
| 1742 | +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | |
| 1743 | + | |
| 1744 | +Object.defineProperty(exports, "__esModule", { | |
| 1745 | + value: true | |
| 1746 | +}); | |
| 1747 | +exports.sprintf = sprintf; | |
| 1748 | + | |
| 1749 | +var _memize = _interopRequireDefault(require("memize")); | |
| 1750 | + | |
| 1751 | +var _sprintfJs = _interopRequireDefault(require("sprintf-js")); | |
| 1752 | + | |
| 1753 | +/** | |
| 1754 | + * External dependencies | |
| 1755 | + */ | |
| 1756 | + | |
| 1757 | +/** | |
| 1758 | + * Log to console, once per message; or more precisely, per referentially equal | |
| 1759 | + * argument set. Because Jed throws errors, we log these to the console instead | |
| 1760 | + * to avoid crashing the application. | |
| 1761 | + * | |
| 1762 | + * @param {...*} args Arguments to pass to `console.error` | |
| 1763 | + */ | |
| 1764 | +var logErrorOnce = (0, _memize.default)(console.error); // eslint-disable-line no-console | |
| 1765 | + | |
| 1766 | +/** | |
| 1767 | + * Returns a formatted string. If an error occurs in applying the format, the | |
| 1768 | + * original format string is returned. | |
| 1769 | + * | |
| 1770 | + * @param {string} format The format of the string to generate. | |
| 1771 | + * @param {...*} args Arguments to apply to the format. | |
| 1772 | + * | |
| 1773 | + * @see http://www.diveintojavascript.com/projects/javascript-sprintf | |
| 1774 | + * | |
| 1775 | + * @return {string} The formatted string. | |
| 1776 | + */ | |
| 1777 | + | |
| 1778 | +function sprintf(format) { | |
| 1779 | + try { | |
| 1780 | + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | |
| 1781 | + args[_key - 1] = arguments[_key]; | |
| 1782 | + } | |
| 1783 | + | |
| 1784 | + return _sprintfJs.default.sprintf.apply(_sprintfJs.default, [format].concat(args)); | |
| 1785 | + } catch (error) { | |
| 1786 | + logErrorOnce('sprintf error: \n\n' + error.toString()); | |
| 1787 | + return format; | |
| 1788 | + } | |
| 1789 | +} | |
| 1790 | + | |
| 1791 | +},{"@babel/runtime/helpers/interopRequireDefault":16,"memize":28,"sprintf-js":25}],25:[function(require,module,exports){ | |
| 1792 | +/* global window, exports, define */ | |
| 1793 | + | |
| 1794 | +!function() { | |
| 1795 | + 'use strict' | |
| 1796 | + | |
| 1797 | + var re = { | |
| 1798 | + not_string: /[^s]/, | |
| 1799 | + not_bool: /[^t]/, | |
| 1800 | + not_type: /[^T]/, | |
| 1801 | + not_primitive: /[^v]/, | |
| 1802 | + number: /[diefg]/, | |
| 1803 | + numeric_arg: /[bcdiefguxX]/, | |
| 1804 | + json: /[j]/, | |
| 1805 | + not_json: /[^j]/, | |
| 1806 | + text: /^[^\x25]+/, | |
| 1807 | + modulo: /^\x25{2}/, | |
| 1808 | + placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/, | |
| 1809 | + key: /^([a-z_][a-z_\d]*)/i, | |
| 1810 | + key_access: /^\.([a-z_][a-z_\d]*)/i, | |
| 1811 | + index_access: /^\[(\d+)\]/, | |
| 1812 | + sign: /^[+-]/ | |
| 1813 | + } | |
| 1814 | + | |
| 1815 | + function sprintf(key) { | |
| 1816 | + // `arguments` is not an array, but should be fine for this call | |
| 1817 | + return sprintf_format(sprintf_parse(key), arguments) | |
| 1818 | + } | |
| 1819 | + | |
| 1820 | + function vsprintf(fmt, argv) { | |
| 1821 | + return sprintf.apply(null, [fmt].concat(argv || [])) | |
| 1822 | + } | |
| 1823 | + | |
| 1824 | + function sprintf_format(parse_tree, argv) { | |
| 1825 | + var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign | |
| 1826 | + for (i = 0; i < tree_length; i++) { | |
| 1827 | + if (typeof parse_tree[i] === 'string') { | |
| 1828 | + output += parse_tree[i] | |
| 1829 | + } | |
| 1830 | + else if (typeof parse_tree[i] === 'object') { | |
| 1831 | + ph = parse_tree[i] // convenience purposes only | |
| 1832 | + if (ph.keys) { // keyword argument | |
| 1833 | + arg = argv[cursor] | |
| 1834 | + for (k = 0; k < ph.keys.length; k++) { | |
| 1835 | + if (arg == undefined) { | |
| 1836 | + throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1])) | |
| 1837 | + } | |
| 1838 | + arg = arg[ph.keys[k]] | |
| 1839 | + } | |
| 1840 | + } | |
| 1841 | + else if (ph.param_no) { // positional argument (explicit) | |
| 1842 | + arg = argv[ph.param_no] | |
| 1843 | + } | |
| 1844 | + else { // positional argument (implicit) | |
| 1845 | + arg = argv[cursor++] | |
| 1846 | + } | |
| 1847 | + | |
| 1848 | + if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) { | |
| 1849 | + arg = arg() | |
| 1850 | + } | |
| 1851 | + | |
| 1852 | + if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) { | |
| 1853 | + throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg)) | |
| 1854 | + } | |
| 1855 | + | |
| 1856 | + if (re.number.test(ph.type)) { | |
| 1857 | + is_positive = arg >= 0 | |
| 1858 | + } | |
| 1859 | + | |
| 1860 | + switch (ph.type) { | |
| 1861 | + case 'b': | |
| 1862 | + arg = parseInt(arg, 10).toString(2) | |
| 1863 | + break | |
| 1864 | + case 'c': | |
| 1865 | + arg = String.fromCharCode(parseInt(arg, 10)) | |
| 1866 | + break | |
| 1867 | + case 'd': | |
| 1868 | + case 'i': | |
| 1869 | + arg = parseInt(arg, 10) | |
| 1870 | + break | |
| 1871 | + case 'j': | |
| 1872 | + arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0) | |
| 1873 | + break | |
| 1874 | + case 'e': | |
| 1875 | + arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential() | |
| 1876 | + break | |
| 1877 | + case 'f': | |
| 1878 | + arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg) | |
| 1879 | + break | |
| 1880 | + case 'g': | |
| 1881 | + arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg) | |
| 1882 | + break | |
| 1883 | + case 'o': | |
| 1884 | + arg = (parseInt(arg, 10) >>> 0).toString(8) | |
| 1885 | + break | |
| 1886 | + case 's': | |
| 1887 | + arg = String(arg) | |
| 1888 | + arg = (ph.precision ? arg.substring(0, ph.precision) : arg) | |
| 1889 | + break | |
| 1890 | + case 't': | |
| 1891 | + arg = String(!!arg) | |
| 1892 | + arg = (ph.precision ? arg.substring(0, ph.precision) : arg) | |
| 1893 | + break | |
| 1894 | + case 'T': | |
| 1895 | + arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase() | |
| 1896 | + arg = (ph.precision ? arg.substring(0, ph.precision) : arg) | |
| 1897 | + break | |
| 1898 | + case 'u': | |
| 1899 | + arg = parseInt(arg, 10) >>> 0 | |
| 1900 | + break | |
| 1901 | + case 'v': | |
| 1902 | + arg = arg.valueOf() | |
| 1903 | + arg = (ph.precision ? arg.substring(0, ph.precision) : arg) | |
| 1904 | + break | |
| 1905 | + case 'x': | |
| 1906 | + arg = (parseInt(arg, 10) >>> 0).toString(16) | |
| 1907 | + break | |
| 1908 | + case 'X': | |
| 1909 | + arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase() | |
| 1910 | + break | |
| 1911 | + } | |
| 1912 | + if (re.json.test(ph.type)) { | |
| 1913 | + output += arg | |
| 1914 | + } | |
| 1915 | + else { | |
| 1916 | + if (re.number.test(ph.type) && (!is_positive || ph.sign)) { | |
| 1917 | + sign = is_positive ? '+' : '-' | |
| 1918 | + arg = arg.toString().replace(re.sign, '') | |
| 1919 | + } | |
| 1920 | + else { | |
| 1921 | + sign = '' | |
| 1922 | + } | |
| 1923 | + pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' ' | |
| 1924 | + pad_length = ph.width - (sign + arg).length | |
| 1925 | + pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : '' | |
| 1926 | + output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg) | |
| 1927 | + } | |
| 1928 | + } | |
| 1929 | + } | |
| 1930 | + return output | |
| 1931 | + } | |
| 1932 | + | |
| 1933 | + var sprintf_cache = Object.create(null) | |
| 1934 | + | |
| 1935 | + function sprintf_parse(fmt) { | |
| 1936 | + if (sprintf_cache[fmt]) { | |
| 1937 | + return sprintf_cache[fmt] | |
| 1938 | + } | |
| 1939 | + | |
| 1940 | + var _fmt = fmt, match, parse_tree = [], arg_names = 0 | |
| 1941 | + while (_fmt) { | |
| 1942 | + if ((match = re.text.exec(_fmt)) !== null) { | |
| 1943 | + parse_tree.push(match[0]) | |
| 1944 | + } | |
| 1945 | + else if ((match = re.modulo.exec(_fmt)) !== null) { | |
| 1946 | + parse_tree.push('%') | |
| 1947 | + } | |
| 1948 | + else if ((match = re.placeholder.exec(_fmt)) !== null) { | |
| 1949 | + if (match[2]) { | |
| 1950 | + arg_names |= 1 | |
| 1951 | + var field_list = [], replacement_field = match[2], field_match = [] | |
| 1952 | + if ((field_match = re.key.exec(replacement_field)) !== null) { | |
| 1953 | + field_list.push(field_match[1]) | |
| 1954 | + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { | |
| 1955 | + if ((field_match = re.key_access.exec(replacement_field)) !== null) { | |
| 1956 | + field_list.push(field_match[1]) | |
| 1957 | + } | |
| 1958 | + else if ((field_match = re.index_access.exec(replacement_field)) !== null) { | |
| 1959 | + field_list.push(field_match[1]) | |
| 1960 | + } | |
| 1961 | + else { | |
| 1962 | + throw new SyntaxError('[sprintf] failed to parse named argument key') | |
| 1963 | + } | |
| 1964 | + } | |
| 1965 | + } | |
| 1966 | + else { | |
| 1967 | + throw new SyntaxError('[sprintf] failed to parse named argument key') | |
| 1968 | + } | |
| 1969 | + match[2] = field_list | |
| 1970 | + } | |
| 1971 | + else { | |
| 1972 | + arg_names |= 2 | |
| 1973 | + } | |
| 1974 | + if (arg_names === 3) { | |
| 1975 | + throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported') | |
| 1976 | + } | |
| 1977 | + | |
| 1978 | + parse_tree.push( | |
| 1979 | + { | |
| 1980 | + placeholder: match[0], | |
| 1981 | + param_no: match[1], | |
| 1982 | + keys: match[2], | |
| 1983 | + sign: match[3], | |
| 1984 | + pad_char: match[4], | |
| 1985 | + align: match[5], | |
| 1986 | + width: match[6], | |
| 1987 | + precision: match[7], | |
| 1988 | + type: match[8] | |
| 1989 | + } | |
| 1990 | + ) | |
| 1991 | + } | |
| 1992 | + else { | |
| 1993 | + throw new SyntaxError('[sprintf] unexpected placeholder') | |
| 1994 | + } | |
| 1995 | + _fmt = _fmt.substring(match[0].length) | |
| 1996 | + } | |
| 1997 | + return sprintf_cache[fmt] = parse_tree | |
| 1998 | + } | |
| 1999 | + | |
| 2000 | + /** | |
| 2001 | + * export to either browser or node.js | |
| 2002 | + */ | |
| 2003 | + /* eslint-disable quote-props */ | |
| 2004 | + if (typeof exports !== 'undefined') { | |
| 2005 | + exports['sprintf'] = sprintf | |
| 2006 | + exports['vsprintf'] = vsprintf | |
| 2007 | + } | |
| 2008 | + if (typeof window !== 'undefined') { | |
| 2009 | + window['sprintf'] = sprintf | |
| 2010 | + window['vsprintf'] = vsprintf | |
| 2011 | + | |
| 2012 | + if (typeof define === 'function' && define['amd']) { | |
| 2013 | + define(function() { | |
| 2014 | + return { | |
| 2015 | + 'sprintf': sprintf, | |
| 2016 | + 'vsprintf': vsprintf | |
| 2017 | + } | |
| 2018 | + }) | |
| 2019 | + } | |
| 2020 | + } | |
| 2021 | + /* eslint-enable quote-props */ | |
| 2022 | +}(); // eslint-disable-line | |
| 2023 | + | |
| 2024 | +},{}],26:[function(require,module,exports){ | |
| 2025 | +/* | |
| 2026 | + * International Telephone Input v17.0.16 | |
| 2027 | + * https://github.com/jackocnr/intl-tel-input.git | |
| 2028 | + * Licensed under the MIT license | |
| 2029 | + */ | |
| 2030 | + | |
| 2031 | +// wrap in UMD | |
| 2032 | +(function(factory) { | |
| 2033 | + if (typeof module === "object" && module.exports) module.exports = factory(); else window.intlTelInput = factory(); | |
| 2034 | +})(function(undefined) { | |
| 2035 | + "use strict"; | |
| 2036 | + return function() { | |
| 2037 | + // Array of country objects for the flag dropdown. | |
| 2038 | + // Here is the criteria for the plugin to support a given country/territory | |
| 2039 | + // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 | |
| 2040 | + // - It has it's own country calling code (it is not a sub-region of another country): https://en.wikipedia.org/wiki/List_of_country_calling_codes | |
| 2041 | + // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png | |
| 2042 | + // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml | |
| 2043 | + // Each country array has the following information: | |
| 2044 | + // [ | |
| 2045 | + // Country name, | |
| 2046 | + // iso2 code, | |
| 2047 | + // International dial code, | |
| 2048 | + // Order (if >1 country with same dial code), | |
| 2049 | + // Area codes | |
| 2050 | + // ] | |
| 2051 | + var allCountries = [ [ "Afghanistan (افغانستان)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (الجزائر)", "dz", "213" ], [ "American Samoa", "as", "1", 5, [ "684" ] ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1", 6, [ "264" ] ], [ "Antigua and Barbuda", "ag", "1", 7, [ "268" ] ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Ascension Island", "ac", "247" ], [ "Australia", "au", "61", 0 ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1", 8, [ "242" ] ], [ "Bahrain (البحرين)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1", 9, [ "246" ] ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1", 10, [ "441" ] ], [ "Bhutan (འབྲུག)", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia and Herzegovina (Босна и Херцеговина)", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil (Brasil)", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "British Virgin Islands", "vg", "1", 11, [ "284" ] ], [ "Brunei", "bn", "673" ], [ "Bulgaria (България)", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi (Uburundi)", "bi", "257" ], [ "Cambodia (កម្ពុជា)", "kh", "855" ], [ "Cameroon (Cameroun)", "cm", "237" ], [ "Canada", "ca", "1", 1, [ "204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905" ] ], [ "Cape Verde (Kabu Verdi)", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1, [ "3", "4", "7" ] ], [ "Cayman Islands", "ky", "1", 12, [ "345" ] ], [ "Central African Republic (République centrafricaine)", "cf", "236" ], [ "Chad (Tchad)", "td", "235" ], [ "Chile", "cl", "56" ], [ "China (中国)", "cn", "86" ], [ "Christmas Island", "cx", "61", 2, [ "89164" ] ], [ "Cocos (Keeling) Islands", "cc", "61", 1, [ "89162" ] ], [ "Colombia", "co", "57" ], [ "Comoros (جزر القمر)", "km", "269" ], [ "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cd", "243" ], [ "Congo (Republic) (Congo-Brazzaville)", "cg", "242" ], [ "Cook Islands", "ck", "682" ], [ "Costa Rica", "cr", "506" ], [ "Côte d’Ivoire", "ci", "225" ], [ "Croatia (Hrvatska)", "hr", "385" ], [ "Cuba", "cu", "53" ], [ "Curaçao", "cw", "599", 0 ], [ "Cyprus (Κύπρος)", "cy", "357" ], [ "Czech Republic (Česká republika)", "cz", "420" ], [ "Denmark (Danmark)", "dk", "45" ], [ "Djibouti", "dj", "253" ], [ "Dominica", "dm", "1", 13, [ "767" ] ], [ "Dominican Republic (República Dominicana)", "do", "1", 2, [ "809", "829", "849" ] ], [ "Ecuador", "ec", "593" ], [ "Egypt (مصر)", "eg", "20" ], [ "El Salvador", "sv", "503" ], [ "Equatorial Guinea (Guinea Ecuatorial)", "gq", "240" ], [ "Eritrea", "er", "291" ], [ "Estonia (Eesti)", "ee", "372" ], [ "Eswatini", "sz", "268" ], [ "Ethiopia", "et", "251" ], [ "Falkland Islands (Islas Malvinas)", "fk", "500" ], [ "Faroe Islands (Føroyar)", "fo", "298" ], [ "Fiji", "fj", "679" ], [ "Finland (Suomi)", "fi", "358", 0 ], [ "France", "fr", "33" ], [ "French Guiana (Guyane française)", "gf", "594" ], [ "French Polynesia (Polynésie française)", "pf", "689" ], [ "Gabon", "ga", "241" ], [ "Gambia", "gm", "220" ], [ "Georgia (საქართველო)", "ge", "995" ], [ "Germany (Deutschland)", "de", "49" ], [ "Ghana (Gaana)", "gh", "233" ], [ "Gibraltar", "gi", "350" ], [ "Greece (Ελλάδα)", "gr", "30" ], [ "Greenland (Kalaallit Nunaat)", "gl", "299" ], [ "Grenada", "gd", "1", 14, [ "473" ] ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1", 15, [ "671" ] ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1, [ "1481", "7781", "7839", "7911" ] ], [ "Guinea (Guinée)", "gn", "224" ], [ "Guinea-Bissau (Guiné Bissau)", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong (香港)", "hk", "852" ], [ "Hungary (Magyarország)", "hu", "36" ], [ "Iceland (Ísland)", "is", "354" ], [ "India (भारत)", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran (ایران)", "ir", "98" ], [ "Iraq (العراق)", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Isle of Man", "im", "44", 2, [ "1624", "74576", "7524", "7924", "7624" ] ], [ "Israel (ישראל)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1", 4, [ "876", "658" ] ], [ "Japan (日本)", "jp", "81" ], [ "Jersey", "je", "44", 3, [ "1534", "7509", "7700", "7797", "7829", "7937" ] ], [ "Jordan (الأردن)", "jo", "962" ], [ "Kazakhstan (Казахстан)", "kz", "7", 1, [ "33", "7" ] ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kosovo", "xk", "383" ], [ "Kuwait (الكويت)", "kw", "965" ], [ "Kyrgyzstan (Кыргызстан)", "kg", "996" ], [ "Laos (ລາວ)", "la", "856" ], [ "Latvia (Latvija)", "lv", "371" ], [ "Lebanon (لبنان)", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya (ليبيا)", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania (Lietuva)", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau (澳門)", "mo", "853" ], [ "North Macedonia (Македонија)", "mk", "389" ], [ "Madagascar (Madagasikara)", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania (موريتانيا)", "mr", "222" ], [ "Mauritius (Moris)", "mu", "230" ], [ "Mayotte", "yt", "262", 1, [ "269", "639" ] ], [ "Mexico (México)", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova (Republica Moldova)", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia (Монгол)", "mn", "976" ], [ "Montenegro (Crna Gora)", "me", "382" ], [ "Montserrat", "ms", "1", 16, [ "664" ] ], [ "Morocco (المغرب)", "ma", "212", 0 ], [ "Mozambique (Moçambique)", "mz", "258" ], [ "Myanmar (Burma) (မြန်မာ)", "mm", "95" ], [ "Namibia (Namibië)", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal (नेपाल)", "np", "977" ], [ "Netherlands (Nederland)", "nl", "31" ], [ "New Caledonia (Nouvelle-Calédonie)", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger (Nijar)", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea (조선 민주주의 인민 공화국)", "kp", "850" ], [ "Northern Mariana Islands", "mp", "1", 17, [ "670" ] ], [ "Norway (Norge)", "no", "47", 0 ], [ "Oman (عُمان)", "om", "968" ], [ "Pakistan (پاکستان)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (فلسطين)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (قطر)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262", 0 ], [ "Romania (România)", "ro", "40" ], [ "Russia (Россия)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1", 18, [ "869" ] ], [ "Saint Lucia", "lc", "1", 19, [ "758" ] ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1", 20, [ "784" ] ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and Príncipe (São Tomé e Príncipe)", "st", "239" ], [ "Saudi Arabia (المملكة العربية السعودية)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (Србија)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1", 21, [ "721" ] ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (대한민국)", "kr", "82" ], [ "South Sudan (جنوب السودان)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (ශ්රී ලංකාව)", "lk", "94" ], [ "Sudan (السودان)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Svalbard and Jan Mayen", "sj", "47", 1, [ "79" ] ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (سوريا)", "sy", "963" ], [ "Taiwan (台灣)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (ไทย)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1", 22, [ "868" ] ], [ "Tunisia (تونس)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1", 23, [ "649" ] ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1", 24, [ "340" ] ], [ "Uganda", "ug", "256" ], [ "Ukraine (Україна)", "ua", "380" ], [ "United Arab Emirates (الإمارات العربية المتحدة)", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (Oʻzbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1, [ "06698" ] ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna (Wallis-et-Futuna)", "wf", "681" ], [ "Western Sahara (الصحراء الغربية)", "eh", "212", 1, [ "5288", "5289" ] ], [ "Yemen (اليمن)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1, [ "18" ] ] ]; | |
| 2052 | + // loop over all of the countries above, restructuring the data to be objects with named keys | |
| 2053 | + for (var i = 0; i < allCountries.length; i++) { | |
| 2054 | + var c = allCountries[i]; | |
| 2055 | + allCountries[i] = { | |
| 2056 | + name: c[0], | |
| 2057 | + iso2: c[1], | |
| 2058 | + dialCode: c[2], | |
| 2059 | + priority: c[3] || 0, | |
| 2060 | + areaCodes: c[4] || null | |
| 2061 | + }; | |
| 2062 | + } | |
| 2063 | + "use strict"; | |
| 2064 | + function _classCallCheck(instance, Constructor) { | |
| 2065 | + if (!(instance instanceof Constructor)) { | |
| 2066 | + throw new TypeError("Cannot call a class as a function"); | |
| 2067 | + } | |
| 2068 | + } | |
| 2069 | + function _defineProperties(target, props) { | |
| 2070 | + for (var i = 0; i < props.length; i++) { | |
| 2071 | + var descriptor = props[i]; | |
| 2072 | + descriptor.enumerable = descriptor.enumerable || false; | |
| 2073 | + descriptor.configurable = true; | |
| 2074 | + if ("value" in descriptor) descriptor.writable = true; | |
| 2075 | + Object.defineProperty(target, descriptor.key, descriptor); | |
| 2076 | + } | |
| 2077 | + } | |
| 2078 | + function _createClass(Constructor, protoProps, staticProps) { | |
| 2079 | + if (protoProps) _defineProperties(Constructor.prototype, protoProps); | |
| 2080 | + if (staticProps) _defineProperties(Constructor, staticProps); | |
| 2081 | + return Constructor; | |
| 2082 | + } | |
| 2083 | + var intlTelInputGlobals = { | |
| 2084 | + getInstance: function getInstance(input) { | |
| 2085 | + var id = input.getAttribute("data-intl-tel-input-id"); | |
| 2086 | + return window.intlTelInputGlobals.instances[id]; | |
| 2087 | + }, | |
| 2088 | + instances: {}, | |
| 2089 | + // using a global like this allows us to mock it in the tests | |
| 2090 | + documentReady: function documentReady() { | |
| 2091 | + return document.readyState === "complete"; | |
| 2092 | + } | |
| 2093 | + }; | |
| 2094 | + if (typeof window === "object") window.intlTelInputGlobals = intlTelInputGlobals; | |
| 2095 | + // these vars persist through all instances of the plugin | |
| 2096 | + var id = 0; | |
| 2097 | + var defaults = { | |
| 2098 | + // whether or not to allow the dropdown | |
| 2099 | + allowDropdown: true, | |
| 2100 | + // if there is just a dial code in the input: remove it on blur | |
| 2101 | + autoHideDialCode: true, | |
| 2102 | + // add a placeholder in the input with an example number for the selected country | |
| 2103 | + autoPlaceholder: "polite", | |
| 2104 | + // modify the parentClass | |
| 2105 | + customContainer: "", | |
| 2106 | + // modify the auto placeholder | |
| 2107 | + customPlaceholder: null, | |
| 2108 | + // append menu to specified element | |
| 2109 | + dropdownContainer: null, | |
| 2110 | + // don't display these countries | |
| 2111 | + excludeCountries: [], | |
| 2112 | + // format the input value during initialisation and on setNumber | |
| 2113 | + formatOnDisplay: true, | |
| 2114 | + // geoIp lookup function | |
| 2115 | + geoIpLookup: null, | |
| 2116 | + // inject a hidden input with this name, and on submit, populate it with the result of getNumber | |
| 2117 | + hiddenInput: "", | |
| 2118 | + // initial country | |
| 2119 | + initialCountry: "", | |
| 2120 | + // localized country names e.g. { 'de': 'Deutschland' } | |
| 2121 | + localizedCountries: null, | |
| 2122 | + // don't insert international dial codes | |
| 2123 | + nationalMode: true, | |
| 2124 | + // display only these countries | |
| 2125 | + onlyCountries: [], | |
| 2126 | + // number type to use for placeholders | |
| 2127 | + placeholderNumberType: "MOBILE", | |
| 2128 | + // the countries at the top of the list. defaults to united states and united kingdom | |
| 2129 | + preferredCountries: [ "us", "gb" ], | |
| 2130 | + // display the country dial code next to the selected flag so it's not part of the typed number | |
| 2131 | + separateDialCode: false, | |
| 2132 | + // specify the path to the libphonenumber script to enable validation/formatting | |
| 2133 | + utilsScript: "" | |
| 2134 | + }; | |
| 2135 | + // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes | |
| 2136 | + var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ]; | |
| 2137 | + // utility function to iterate over an object. can't use Object.entries or native forEach because | |
| 2138 | + // of IE11 | |
| 2139 | + var forEachProp = function forEachProp(obj, callback) { | |
| 2140 | + var keys = Object.keys(obj); | |
| 2141 | + for (var i = 0; i < keys.length; i++) { | |
| 2142 | + callback(keys[i], obj[keys[i]]); | |
| 2143 | + } | |
| 2144 | + }; | |
| 2145 | + // run a method on each instance of the plugin | |
| 2146 | + var forEachInstance = function forEachInstance(method) { | |
| 2147 | + forEachProp(window.intlTelInputGlobals.instances, function(key) { | |
| 2148 | + window.intlTelInputGlobals.instances[key][method](); | |
| 2149 | + }); | |
| 2150 | + }; | |
| 2151 | + // this is our plugin class that we will create an instance of | |
| 2152 | + // eslint-disable-next-line no-unused-vars | |
| 2153 | + var Iti = /*#__PURE__*/ | |
| 2154 | + function() { | |
| 2155 | + function Iti(input, options) { | |
| 2156 | + var _this = this; | |
| 2157 | + _classCallCheck(this, Iti); | |
| 2158 | + this.id = id++; | |
| 2159 | + this.telInput = input; | |
| 2160 | + this.activeItem = null; | |
| 2161 | + this.highlightedItem = null; | |
| 2162 | + // process specified options / defaults | |
| 2163 | + // alternative to Object.assign, which isn't supported by IE11 | |
| 2164 | + var customOptions = options || {}; | |
| 2165 | + this.options = {}; | |
| 2166 | + forEachProp(defaults, function(key, value) { | |
| 2167 | + _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value; | |
| 2168 | + }); | |
| 2169 | + this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder")); | |
| 2170 | + } | |
| 2171 | + _createClass(Iti, [ { | |
| 2172 | + key: "_init", | |
| 2173 | + value: function _init() { | |
| 2174 | + var _this2 = this; | |
| 2175 | + // if in nationalMode, disable options relating to dial codes | |
| 2176 | + if (this.options.nationalMode) this.options.autoHideDialCode = false; | |
| 2177 | + // if separateDialCode then doesn't make sense to A) insert dial code into input | |
| 2178 | + // (autoHideDialCode), and B) display national numbers (because we're displaying the country | |
| 2179 | + // dial code next to them) | |
| 2180 | + if (this.options.separateDialCode) { | |
| 2181 | + this.options.autoHideDialCode = this.options.nationalMode = false; | |
| 2182 | + } | |
| 2183 | + // we cannot just test screen size as some smartphones/website meta tags will report desktop | |
| 2184 | + // resolutions | |
| 2185 | + // Note: for some reason jasmine breaks if you put this in the main Plugin function with the | |
| 2186 | + // rest of these declarations | |
| 2187 | + // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile' | |
| 2188 | + this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); | |
| 2189 | + if (this.isMobile) { | |
| 2190 | + // trigger the mobile dropdown css | |
| 2191 | + document.body.classList.add("iti-mobile"); | |
| 2192 | + // on mobile, we want a full screen dropdown, so we must append it to the body | |
| 2193 | + if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body; | |
| 2194 | + } | |
| 2195 | + // these promises get resolved when their individual requests complete | |
| 2196 | + // this way the dev can do something like iti.promise.then(...) to know when all requests are | |
| 2197 | + // complete | |
| 2198 | + if (typeof Promise !== "undefined") { | |
| 2199 | + var autoCountryPromise = new Promise(function(resolve, reject) { | |
| 2200 | + _this2.resolveAutoCountryPromise = resolve; | |
| 2201 | + _this2.rejectAutoCountryPromise = reject; | |
| 2202 | + }); | |
| 2203 | + var utilsScriptPromise = new Promise(function(resolve, reject) { | |
| 2204 | + _this2.resolveUtilsScriptPromise = resolve; | |
| 2205 | + _this2.rejectUtilsScriptPromise = reject; | |
| 2206 | + }); | |
| 2207 | + this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]); | |
| 2208 | + } else { | |
| 2209 | + // prevent errors when Promise doesn't exist | |
| 2210 | + this.resolveAutoCountryPromise = this.rejectAutoCountryPromise = function() {}; | |
| 2211 | + this.resolveUtilsScriptPromise = this.rejectUtilsScriptPromise = function() {}; | |
| 2212 | + } | |
| 2213 | + // in various situations there could be no country selected initially, but we need to be able | |
| 2214 | + // to assume this variable exists | |
| 2215 | + this.selectedCountryData = {}; | |
| 2216 | + // process all the data: onlyCountries, excludeCountries, preferredCountries etc | |
| 2217 | + this._processCountryData(); | |
| 2218 | + // generate the markup | |
| 2219 | + this._generateMarkup(); | |
| 2220 | + // set the initial state of the input value and the selected flag | |
| 2221 | + this._setInitialState(); | |
| 2222 | + // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click | |
| 2223 | + this._initListeners(); | |
| 2224 | + // utils script, and auto country | |
| 2225 | + this._initRequests(); | |
| 2226 | + } | |
| 2227 | + }, { | |
| 2228 | + key: "_processCountryData", | |
| 2229 | + value: function _processCountryData() { | |
| 2230 | + // process onlyCountries or excludeCountries array if present | |
| 2231 | + this._processAllCountries(); | |
| 2232 | + // process the countryCodes map | |
| 2233 | + this._processCountryCodes(); | |
| 2234 | + // process the preferredCountries | |
| 2235 | + this._processPreferredCountries(); | |
| 2236 | + // translate countries according to localizedCountries option | |
| 2237 | + if (this.options.localizedCountries) this._translateCountriesByLocale(); | |
| 2238 | + // sort countries by name | |
| 2239 | + if (this.options.onlyCountries.length || this.options.localizedCountries) { | |
| 2240 | + this.countries.sort(this._countryNameSort); | |
| 2241 | + } | |
| 2242 | + } | |
| 2243 | + }, { | |
| 2244 | + key: "_addCountryCode", | |
| 2245 | + value: function _addCountryCode(iso2, countryCode, priority) { | |
| 2246 | + if (countryCode.length > this.countryCodeMaxLen) { | |
| 2247 | + this.countryCodeMaxLen = countryCode.length; | |
| 2248 | + } | |
| 2249 | + if (!this.countryCodes.hasOwnProperty(countryCode)) { | |
| 2250 | + this.countryCodes[countryCode] = []; | |
| 2251 | + } | |
| 2252 | + // bail if we already have this country for this countryCode | |
| 2253 | + for (var i = 0; i < this.countryCodes[countryCode].length; i++) { | |
| 2254 | + if (this.countryCodes[countryCode][i] === iso2) return; | |
| 2255 | + } | |
| 2256 | + // check for undefined as 0 is falsy | |
| 2257 | + var index = priority !== undefined ? priority : this.countryCodes[countryCode].length; | |
| 2258 | + this.countryCodes[countryCode][index] = iso2; | |
| 2259 | + } | |
| 2260 | + }, { | |
| 2261 | + key: "_processAllCountries", | |
| 2262 | + value: function _processAllCountries() { | |
| 2263 | + if (this.options.onlyCountries.length) { | |
| 2264 | + var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) { | |
| 2265 | + return country.toLowerCase(); | |
| 2266 | + }); | |
| 2267 | + this.countries = allCountries.filter(function(country) { | |
| 2268 | + return lowerCaseOnlyCountries.indexOf(country.iso2) > -1; | |
| 2269 | + }); | |
| 2270 | + } else if (this.options.excludeCountries.length) { | |
| 2271 | + var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) { | |
| 2272 | + return country.toLowerCase(); | |
| 2273 | + }); | |
| 2274 | + this.countries = allCountries.filter(function(country) { | |
| 2275 | + return lowerCaseExcludeCountries.indexOf(country.iso2) === -1; | |
| 2276 | + }); | |
| 2277 | + } else { | |
| 2278 | + this.countries = allCountries; | |
| 2279 | + } | |
| 2280 | + } | |
| 2281 | + }, { | |
| 2282 | + key: "_translateCountriesByLocale", | |
| 2283 | + value: function _translateCountriesByLocale() { | |
| 2284 | + for (var i = 0; i < this.countries.length; i++) { | |
| 2285 | + var iso = this.countries[i].iso2.toLowerCase(); | |
| 2286 | + if (this.options.localizedCountries.hasOwnProperty(iso)) { | |
| 2287 | + this.countries[i].name = this.options.localizedCountries[iso]; | |
| 2288 | + } | |
| 2289 | + } | |
| 2290 | + } | |
| 2291 | + }, { | |
| 2292 | + key: "_countryNameSort", | |
| 2293 | + value: function _countryNameSort(a, b) { | |
| 2294 | + return a.name.localeCompare(b.name); | |
| 2295 | + } | |
| 2296 | + }, { | |
| 2297 | + key: "_processCountryCodes", | |
| 2298 | + value: function _processCountryCodes() { | |
| 2299 | + this.countryCodeMaxLen = 0; | |
| 2300 | + // here we store just dial codes | |
| 2301 | + this.dialCodes = {}; | |
| 2302 | + // here we store "country codes" (both dial codes and their area codes) | |
| 2303 | + this.countryCodes = {}; | |
| 2304 | + // first: add dial codes | |
| 2305 | + for (var i = 0; i < this.countries.length; i++) { | |
| 2306 | + var c = this.countries[i]; | |
| 2307 | + if (!this.dialCodes[c.dialCode]) this.dialCodes[c.dialCode] = true; | |
| 2308 | + this._addCountryCode(c.iso2, c.dialCode, c.priority); | |
| 2309 | + } | |
| 2310 | + // next: add area codes | |
| 2311 | + // this is a second loop over countries, to make sure we have all of the "root" countries | |
| 2312 | + // already in the map, so that we can access them, as each time we add an area code substring | |
| 2313 | + // to the map, we also need to include the "root" country's code, as that also matches | |
| 2314 | + for (var _i = 0; _i < this.countries.length; _i++) { | |
| 2315 | + var _c = this.countries[_i]; | |
| 2316 | + // area codes | |
| 2317 | + if (_c.areaCodes) { | |
| 2318 | + var rootCountryCode = this.countryCodes[_c.dialCode][0]; | |
| 2319 | + // for each area code | |
| 2320 | + for (var j = 0; j < _c.areaCodes.length; j++) { | |
| 2321 | + var areaCode = _c.areaCodes[j]; | |
| 2322 | + // for each digit in the area code to add all partial matches as well | |
| 2323 | + for (var k = 1; k < areaCode.length; k++) { | |
| 2324 | + var partialDialCode = _c.dialCode + areaCode.substr(0, k); | |
| 2325 | + // start with the root country, as that also matches this dial code | |
| 2326 | + this._addCountryCode(rootCountryCode, partialDialCode); | |
| 2327 | + this._addCountryCode(_c.iso2, partialDialCode); | |
| 2328 | + } | |
| 2329 | + // add the full area code | |
| 2330 | + this._addCountryCode(_c.iso2, _c.dialCode + areaCode); | |
| 2331 | + } | |
| 2332 | + } | |
| 2333 | + } | |
| 2334 | + } | |
| 2335 | + }, { | |
| 2336 | + key: "_processPreferredCountries", | |
| 2337 | + value: function _processPreferredCountries() { | |
| 2338 | + this.preferredCountries = []; | |
| 2339 | + for (var i = 0; i < this.options.preferredCountries.length; i++) { | |
| 2340 | + var countryCode = this.options.preferredCountries[i].toLowerCase(); | |
| 2341 | + var countryData = this._getCountryData(countryCode, false, true); | |
| 2342 | + if (countryData) this.preferredCountries.push(countryData); | |
| 2343 | + } | |
| 2344 | + } | |
| 2345 | + }, { | |
| 2346 | + key: "_createEl", | |
| 2347 | + value: function _createEl(name, attrs, container) { | |
| 2348 | + var el = document.createElement(name); | |
| 2349 | + if (attrs) forEachProp(attrs, function(key, value) { | |
| 2350 | + return el.setAttribute(key, value); | |
| 2351 | + }); | |
| 2352 | + if (container) container.appendChild(el); | |
| 2353 | + return el; | |
| 2354 | + } | |
| 2355 | + }, { | |
| 2356 | + key: "_generateMarkup", | |
| 2357 | + value: function _generateMarkup() { | |
| 2358 | + // if autocomplete does not exist on the element and its form, then | |
| 2359 | + // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can | |
| 2360 | + // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the | |
| 2361 | + // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode) | |
| 2362 | + if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) { | |
| 2363 | + this.telInput.setAttribute("autocomplete", "off"); | |
| 2364 | + } | |
| 2365 | + // containers (mostly for positioning) | |
| 2366 | + var parentClass = "iti"; | |
| 2367 | + if (this.options.allowDropdown) parentClass += " iti--allow-dropdown"; | |
| 2368 | + if (this.options.separateDialCode) parentClass += " iti--separate-dial-code"; | |
| 2369 | + if (this.options.customContainer) { | |
| 2370 | + parentClass += " "; | |
| 2371 | + parentClass += this.options.customContainer; | |
| 2372 | + } | |
| 2373 | + var wrapper = this._createEl("div", { | |
| 2374 | + "class": parentClass | |
| 2375 | + }); | |
| 2376 | + this.telInput.parentNode.insertBefore(wrapper, this.telInput); | |
| 2377 | + this.flagsContainer = this._createEl("div", { | |
| 2378 | + "class": "iti__flag-container" | |
| 2379 | + }, wrapper); | |
| 2380 | + wrapper.appendChild(this.telInput); | |
| 2381 | + // selected flag (displayed to left of input) | |
| 2382 | + this.selectedFlag = this._createEl("div", { | |
| 2383 | + "class": "iti__selected-flag", | |
| 2384 | + role: "combobox", | |
| 2385 | + "aria-controls": "iti-".concat(this.id, "__country-listbox"), | |
| 2386 | + "aria-owns": "iti-".concat(this.id, "__country-listbox"), | |
| 2387 | + "aria-expanded": "false" | |
| 2388 | + }, this.flagsContainer); | |
| 2389 | + this.selectedFlagInner = this._createEl("div", { | |
| 2390 | + "class": "iti__flag" | |
| 2391 | + }, this.selectedFlag); | |
| 2392 | + if (this.options.separateDialCode) { | |
| 2393 | + this.selectedDialCode = this._createEl("div", { | |
| 2394 | + "class": "iti__selected-dial-code" | |
| 2395 | + }, this.selectedFlag); | |
| 2396 | + } | |
| 2397 | + if (this.options.allowDropdown) { | |
| 2398 | + // make element focusable and tab navigable | |
| 2399 | + this.selectedFlag.setAttribute("tabindex", "0"); | |
| 2400 | + this.dropdownArrow = this._createEl("div", { | |
| 2401 | + "class": "iti__arrow" | |
| 2402 | + }, this.selectedFlag); | |
| 2403 | + // country dropdown: preferred countries, then divider, then all countries | |
| 2404 | + this.countryList = this._createEl("ul", { | |
| 2405 | + "class": "iti__country-list iti__hide", | |
| 2406 | + id: "iti-".concat(this.id, "__country-listbox"), | |
| 2407 | + role: "listbox", | |
| 2408 | + "aria-label": "List of countries" | |
| 2409 | + }); | |
| 2410 | + if (this.preferredCountries.length) { | |
| 2411 | + this._appendListItems(this.preferredCountries, "iti__preferred", true); | |
| 2412 | + this._createEl("li", { | |
| 2413 | + "class": "iti__divider", | |
| 2414 | + role: "separator", | |
| 2415 | + "aria-disabled": "true" | |
| 2416 | + }, this.countryList); | |
| 2417 | + } | |
| 2418 | + this._appendListItems(this.countries, "iti__standard"); | |
| 2419 | + // create dropdownContainer markup | |
| 2420 | + if (this.options.dropdownContainer) { | |
| 2421 | + this.dropdown = this._createEl("div", { | |
| 2422 | + "class": "iti iti--container" | |
| 2423 | + }); | |
| 2424 | + this.dropdown.appendChild(this.countryList); | |
| 2425 | + } else { | |
| 2426 | + this.flagsContainer.appendChild(this.countryList); | |
| 2427 | + } | |
| 2428 | + } | |
| 2429 | + if (this.options.hiddenInput) { | |
| 2430 | + var hiddenInputName = this.options.hiddenInput; | |
| 2431 | + var name = this.telInput.getAttribute("name"); | |
| 2432 | + if (name) { | |
| 2433 | + var i = name.lastIndexOf("["); | |
| 2434 | + // if input name contains square brackets, then give the hidden input the same name, | |
| 2435 | + // replacing the contents of the last set of brackets with the given hiddenInput name | |
| 2436 | + if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]"); | |
| 2437 | + } | |
| 2438 | + this.hiddenInput = this._createEl("input", { | |
| 2439 | + type: "hidden", | |
| 2440 | + name: hiddenInputName | |
| 2441 | + }); | |
| 2442 | + wrapper.appendChild(this.hiddenInput); | |
| 2443 | + } | |
| 2444 | + } | |
| 2445 | + }, { | |
| 2446 | + key: "_appendListItems", | |
| 2447 | + value: function _appendListItems(countries, className, preferred) { | |
| 2448 | + // we create so many DOM elements, it is faster to build a temp string | |
| 2449 | + // and then add everything to the DOM in one go at the end | |
| 2450 | + var tmp = ""; | |
| 2451 | + // for each country | |
| 2452 | + for (var i = 0; i < countries.length; i++) { | |
| 2453 | + var c = countries[i]; | |
| 2454 | + var idSuffix = preferred ? "-preferred" : ""; | |
| 2455 | + // open the list item | |
| 2456 | + tmp += "<li class='iti__country ".concat(className, "' tabIndex='-1' id='iti-").concat(this.id, "__item-").concat(c.iso2).concat(idSuffix, "' role='option' data-dial-code='").concat(c.dialCode, "' data-country-code='").concat(c.iso2, "' aria-selected='false'>"); | |
| 2457 | + // add the flag | |
| 2458 | + tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>"); | |
| 2459 | + // and the country name and dial code | |
| 2460 | + tmp += "<span class='iti__country-name'>".concat(c.name, "</span>"); | |
| 2461 | + tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>"); | |
| 2462 | + // close the list item | |
| 2463 | + tmp += "</li>"; | |
| 2464 | + } | |
| 2465 | + this.countryList.insertAdjacentHTML("beforeend", tmp); | |
| 2466 | + } | |
| 2467 | + }, { | |
| 2468 | + key: "_setInitialState", | |
| 2469 | + value: function _setInitialState() { | |
| 2470 | + // fix firefox bug: when first load page (with input with value set to number with intl dial | |
| 2471 | + // code) and initialising plugin removes the dial code from the input, then refresh page, | |
| 2472 | + // and we try to init plugin again but this time on number without dial code so get grey flag | |
| 2473 | + var attributeValue = this.telInput.getAttribute("value"); | |
| 2474 | + var inputValue = this.telInput.value; | |
| 2475 | + var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+"); | |
| 2476 | + var val = useAttribute ? attributeValue : inputValue; | |
| 2477 | + var dialCode = this._getDialCode(val); | |
| 2478 | + var isRegionlessNanp = this._isRegionlessNanp(val); | |
| 2479 | + var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode; | |
| 2480 | + // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the | |
| 2481 | + // flag, else fall back to the default country | |
| 2482 | + if (dialCode && !isRegionlessNanp) { | |
| 2483 | + this._updateFlagFromNumber(val); | |
| 2484 | + } else if (initialCountry !== "auto") { | |
| 2485 | + // see if we should select a flag | |
| 2486 | + if (initialCountry) { | |
| 2487 | + this._setFlag(initialCountry.toLowerCase()); | |
| 2488 | + } else { | |
| 2489 | + if (dialCode && isRegionlessNanp) { | |
| 2490 | + // has intl dial code, is regionless nanp, and no initialCountry, so default to US | |
| 2491 | + this._setFlag("us"); | |
| 2492 | + } else { | |
| 2493 | + // no dial code and no initialCountry, so default to first in list | |
| 2494 | + this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2; | |
| 2495 | + if (!val) { | |
| 2496 | + this._setFlag(this.defaultCountry); | |
| 2497 | + } | |
| 2498 | + } | |
| 2499 | + } | |
| 2500 | + // if empty and no nationalMode and no autoHideDialCode then insert the default dial code | |
| 2501 | + if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) { | |
| 2502 | + this.telInput.value = "+".concat(this.selectedCountryData.dialCode); | |
| 2503 | + } | |
| 2504 | + } | |
| 2505 | + // NOTE: if initialCountry is set to auto, that will be handled separately | |
| 2506 | + // format - note this wont be run after _updateDialCode as that's only called if no val | |
| 2507 | + if (val) this._updateValFromNumber(val); | |
| 2508 | + } | |
| 2509 | + }, { | |
| 2510 | + key: "_initListeners", | |
| 2511 | + value: function _initListeners() { | |
| 2512 | + this._initKeyListeners(); | |
| 2513 | + if (this.options.autoHideDialCode) this._initBlurListeners(); | |
| 2514 | + if (this.options.allowDropdown) this._initDropdownListeners(); | |
| 2515 | + if (this.hiddenInput) this._initHiddenInputListener(); | |
| 2516 | + } | |
| 2517 | + }, { | |
| 2518 | + key: "_initHiddenInputListener", | |
| 2519 | + value: function _initHiddenInputListener() { | |
| 2520 | + var _this3 = this; | |
| 2521 | + this._handleHiddenInputSubmit = function() { | |
| 2522 | + _this3.hiddenInput.value = _this3.getNumber(); | |
| 2523 | + }; | |
| 2524 | + if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit); | |
| 2525 | + } | |
| 2526 | + }, { | |
| 2527 | + key: "_getClosestLabel", | |
| 2528 | + value: function _getClosestLabel() { | |
| 2529 | + var el = this.telInput; | |
| 2530 | + while (el && el.tagName !== "LABEL") { | |
| 2531 | + el = el.parentNode; | |
| 2532 | + } | |
| 2533 | + return el; | |
| 2534 | + } | |
| 2535 | + }, { | |
| 2536 | + key: "_initDropdownListeners", | |
| 2537 | + value: function _initDropdownListeners() { | |
| 2538 | + var _this4 = this; | |
| 2539 | + // hack for input nested inside label (which is valid markup): clicking the selected-flag to | |
| 2540 | + // open the dropdown would then automatically trigger a 2nd click on the input which would | |
| 2541 | + // close it again | |
| 2542 | + this._handleLabelClick = function(e) { | |
| 2543 | + // if the dropdown is closed, then focus the input, else ignore the click | |
| 2544 | + if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); else e.preventDefault(); | |
| 2545 | + }; | |
| 2546 | + var label = this._getClosestLabel(); | |
| 2547 | + if (label) label.addEventListener("click", this._handleLabelClick); | |
| 2548 | + // toggle country dropdown on click | |
| 2549 | + this._handleClickSelectedFlag = function() { | |
| 2550 | + // only intercept this event if we're opening the dropdown | |
| 2551 | + // else let it bubble up to the top ("click-off-to-close" listener) | |
| 2552 | + // we cannot just stopPropagation as it may be needed to close another instance | |
| 2553 | + if (_this4.countryList.classList.contains("iti__hide") && !_this4.telInput.disabled && !_this4.telInput.readOnly) { | |
| 2554 | + _this4._showDropdown(); | |
| 2555 | + } | |
| 2556 | + }; | |
| 2557 | + this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag); | |
| 2558 | + // open dropdown list if currently focused | |
| 2559 | + this._handleFlagsContainerKeydown = function(e) { | |
| 2560 | + var isDropdownHidden = _this4.countryList.classList.contains("iti__hide"); | |
| 2561 | + if (isDropdownHidden && [ "ArrowUp", "Up", "ArrowDown", "Down", " ", "Enter" ].indexOf(e.key) !== -1) { | |
| 2562 | + // prevent form from being submitted if "ENTER" was pressed | |
| 2563 | + e.preventDefault(); | |
| 2564 | + // prevent event from being handled again by document | |
| 2565 | + e.stopPropagation(); | |
| 2566 | + _this4._showDropdown(); | |
| 2567 | + } | |
| 2568 | + // allow navigation from dropdown to input on TAB | |
| 2569 | + if (e.key === "Tab") _this4._closeDropdown(); | |
| 2570 | + }; | |
| 2571 | + this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown); | |
| 2572 | + } | |
| 2573 | + }, { | |
| 2574 | + key: "_initRequests", | |
| 2575 | + value: function _initRequests() { | |
| 2576 | + var _this5 = this; | |
| 2577 | + // if the user has specified the path to the utils script, fetch it on window.load, else resolve | |
| 2578 | + if (this.options.utilsScript && !window.intlTelInputUtils) { | |
| 2579 | + // if the plugin is being initialised after the window.load event has already been fired | |
| 2580 | + if (window.intlTelInputGlobals.documentReady()) { | |
| 2581 | + window.intlTelInputGlobals.loadUtils(this.options.utilsScript); | |
| 2582 | + } else { | |
| 2583 | + // wait until the load event so we don't block any other requests e.g. the flags image | |
| 2584 | + window.addEventListener("load", function() { | |
| 2585 | + window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript); | |
| 2586 | + }); | |
| 2587 | + } | |
| 2588 | + } else this.resolveUtilsScriptPromise(); | |
| 2589 | + if (this.options.initialCountry === "auto") this._loadAutoCountry(); else this.resolveAutoCountryPromise(); | |
| 2590 | + } | |
| 2591 | + }, { | |
| 2592 | + key: "_loadAutoCountry", | |
| 2593 | + value: function _loadAutoCountry() { | |
| 2594 | + // 3 options: | |
| 2595 | + // 1) already loaded (we're done) | |
| 2596 | + // 2) not already started loading (start) | |
| 2597 | + // 3) already started loading (do nothing - just wait for loading callback to fire) | |
| 2598 | + if (window.intlTelInputGlobals.autoCountry) { | |
| 2599 | + this.handleAutoCountry(); | |
| 2600 | + } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) { | |
| 2601 | + // don't do this twice! | |
| 2602 | + window.intlTelInputGlobals.startedLoadingAutoCountry = true; | |
| 2603 | + if (typeof this.options.geoIpLookup === "function") { | |
| 2604 | + this.options.geoIpLookup(function(countryCode) { | |
| 2605 | + window.intlTelInputGlobals.autoCountry = countryCode.toLowerCase(); | |
| 2606 | + // tell all instances the auto country is ready | |
| 2607 | + // TODO: this should just be the current instances | |
| 2608 | + // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight | |
| 2609 | + // away (e.g. if they have already done the geo ip lookup somewhere else). Using | |
| 2610 | + // setTimeout means that the current thread of execution will finish before executing | |
| 2611 | + // this, which allows the plugin to finish initialising. | |
| 2612 | + setTimeout(function() { | |
| 2613 | + return forEachInstance("handleAutoCountry"); | |
| 2614 | + }); | |
| 2615 | + }, function() { | |
| 2616 | + return forEachInstance("rejectAutoCountryPromise"); | |
| 2617 | + }); | |
| 2618 | + } | |
| 2619 | + } | |
| 2620 | + } | |
| 2621 | + }, { | |
| 2622 | + key: "_initKeyListeners", | |
| 2623 | + value: function _initKeyListeners() { | |
| 2624 | + var _this6 = this; | |
| 2625 | + // update flag on keyup | |
| 2626 | + this._handleKeyupEvent = function() { | |
| 2627 | + if (_this6._updateFlagFromNumber(_this6.telInput.value)) { | |
| 2628 | + _this6._triggerCountryChange(); | |
| 2629 | + } | |
| 2630 | + }; | |
| 2631 | + this.telInput.addEventListener("keyup", this._handleKeyupEvent); | |
| 2632 | + // update flag on cut/paste events (now supported in all major browsers) | |
| 2633 | + this._handleClipboardEvent = function() { | |
| 2634 | + // hack because "paste" event is fired before input is updated | |
| 2635 | + setTimeout(_this6._handleKeyupEvent); | |
| 2636 | + }; | |
| 2637 | + this.telInput.addEventListener("cut", this._handleClipboardEvent); | |
| 2638 | + this.telInput.addEventListener("paste", this._handleClipboardEvent); | |
| 2639 | + } | |
| 2640 | + }, { | |
| 2641 | + key: "_cap", | |
| 2642 | + value: function _cap(number) { | |
| 2643 | + var max = this.telInput.getAttribute("maxlength"); | |
| 2644 | + return max && number.length > max ? number.substr(0, max) : number; | |
| 2645 | + } | |
| 2646 | + }, { | |
| 2647 | + key: "_initBlurListeners", | |
| 2648 | + value: function _initBlurListeners() { | |
| 2649 | + var _this7 = this; | |
| 2650 | + // on blur or form submit: if just a dial code then remove it | |
| 2651 | + this._handleSubmitOrBlurEvent = function() { | |
| 2652 | + _this7._removeEmptyDialCode(); | |
| 2653 | + }; | |
| 2654 | + if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent); | |
| 2655 | + this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent); | |
| 2656 | + } | |
| 2657 | + }, { | |
| 2658 | + key: "_removeEmptyDialCode", | |
| 2659 | + value: function _removeEmptyDialCode() { | |
| 2660 | + if (this.telInput.value.charAt(0) === "+") { | |
| 2661 | + var numeric = this._getNumeric(this.telInput.value); | |
| 2662 | + // if just a plus, or if just a dial code | |
| 2663 | + if (!numeric || this.selectedCountryData.dialCode === numeric) { | |
| 2664 | + this.telInput.value = ""; | |
| 2665 | + } | |
| 2666 | + } | |
| 2667 | + } | |
| 2668 | + }, { | |
| 2669 | + key: "_getNumeric", | |
| 2670 | + value: function _getNumeric(s) { | |
| 2671 | + return s.replace(/\D/g, ""); | |
| 2672 | + } | |
| 2673 | + }, { | |
| 2674 | + key: "_trigger", | |
| 2675 | + value: function _trigger(name) { | |
| 2676 | + // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax | |
| 2677 | + var e = document.createEvent("Event"); | |
| 2678 | + e.initEvent(name, true, true); | |
| 2679 | + // can bubble, and is cancellable | |
| 2680 | + this.telInput.dispatchEvent(e); | |
| 2681 | + } | |
| 2682 | + }, { | |
| 2683 | + key: "_showDropdown", | |
| 2684 | + value: function _showDropdown() { | |
| 2685 | + this.countryList.classList.remove("iti__hide"); | |
| 2686 | + this.selectedFlag.setAttribute("aria-expanded", "true"); | |
| 2687 | + this._setDropdownPosition(); | |
| 2688 | + // update highlighting and scroll to active list item | |
| 2689 | + if (this.activeItem) { | |
| 2690 | + this._highlightListItem(this.activeItem, false); | |
| 2691 | + this._scrollTo(this.activeItem, true); | |
| 2692 | + } | |
| 2693 | + // bind all the dropdown-related listeners: mouseover, click, click-off, keydown | |
| 2694 | + this._bindDropdownListeners(); | |
| 2695 | + // update the arrow | |
| 2696 | + this.dropdownArrow.classList.add("iti__arrow--up"); | |
| 2697 | + this._trigger("open:countrydropdown"); | |
| 2698 | + } | |
| 2699 | + }, { | |
| 2700 | + key: "_toggleClass", | |
| 2701 | + value: function _toggleClass(el, className, shouldHaveClass) { | |
| 2702 | + if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className); | |
| 2703 | + } | |
| 2704 | + }, { | |
| 2705 | + key: "_setDropdownPosition", | |
| 2706 | + value: function _setDropdownPosition() { | |
| 2707 | + var _this8 = this; | |
| 2708 | + if (this.options.dropdownContainer) { | |
| 2709 | + this.options.dropdownContainer.appendChild(this.dropdown); | |
| 2710 | + } | |
| 2711 | + if (!this.isMobile) { | |
| 2712 | + var pos = this.telInput.getBoundingClientRect(); | |
| 2713 | + // windowTop from https://stackoverflow.com/a/14384091/217866 | |
| 2714 | + var windowTop = window.pageYOffset || document.documentElement.scrollTop; | |
| 2715 | + var inputTop = pos.top + windowTop; | |
| 2716 | + var dropdownHeight = this.countryList.offsetHeight; | |
| 2717 | + // dropdownFitsBelow = (dropdownBottom < windowBottom) | |
| 2718 | + var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight; | |
| 2719 | + var dropdownFitsAbove = inputTop - dropdownHeight > windowTop; | |
| 2720 | + // by default, the dropdown will be below the input. If we want to position it above the | |
| 2721 | + // input, we add the dropup class. | |
| 2722 | + this._toggleClass(this.countryList, "iti__country-list--dropup", !dropdownFitsBelow && dropdownFitsAbove); | |
| 2723 | + // if dropdownContainer is enabled, calculate postion | |
| 2724 | + if (this.options.dropdownContainer) { | |
| 2725 | + // by default the dropdown will be directly over the input because it's not in the flow. | |
| 2726 | + // If we want to position it below, we need to add some extra top value. | |
| 2727 | + var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.offsetHeight; | |
| 2728 | + // calculate placement | |
| 2729 | + this.dropdown.style.top = "".concat(inputTop + extraTop, "px"); | |
| 2730 | + this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px"); | |
| 2731 | + // close menu on window scroll | |
| 2732 | + this._handleWindowScroll = function() { | |
| 2733 | + return _this8._closeDropdown(); | |
| 2734 | + }; | |
| 2735 | + window.addEventListener("scroll", this._handleWindowScroll); | |
| 2736 | + } | |
| 2737 | + } | |
| 2738 | + } | |
| 2739 | + }, { | |
| 2740 | + key: "_getClosestListItem", | |
| 2741 | + value: function _getClosestListItem(target) { | |
| 2742 | + var el = target; | |
| 2743 | + while (el && el !== this.countryList && !el.classList.contains("iti__country")) { | |
| 2744 | + el = el.parentNode; | |
| 2745 | + } | |
| 2746 | + // if we reached the countryList element, then return null | |
| 2747 | + return el === this.countryList ? null : el; | |
| 2748 | + } | |
| 2749 | + }, { | |
| 2750 | + key: "_bindDropdownListeners", | |
| 2751 | + value: function _bindDropdownListeners() { | |
| 2752 | + var _this9 = this; | |
| 2753 | + // when mouse over a list item, just highlight that one | |
| 2754 | + // we add the class "highlight", so if they hit "enter" we know which one to select | |
| 2755 | + this._handleMouseoverCountryList = function(e) { | |
| 2756 | + // handle event delegation, as we're listening for this event on the countryList | |
| 2757 | + var listItem = _this9._getClosestListItem(e.target); | |
| 2758 | + if (listItem) _this9._highlightListItem(listItem, false); | |
| 2759 | + }; | |
| 2760 | + this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList); | |
| 2761 | + // listen for country selection | |
| 2762 | + this._handleClickCountryList = function(e) { | |
| 2763 | + var listItem = _this9._getClosestListItem(e.target); | |
| 2764 | + if (listItem) _this9._selectListItem(listItem); | |
| 2765 | + }; | |
| 2766 | + this.countryList.addEventListener("click", this._handleClickCountryList); | |
| 2767 | + // click off to close | |
| 2768 | + // (except when this initial opening click is bubbling up) | |
| 2769 | + // we cannot just stopPropagation as it may be needed to close another instance | |
| 2770 | + var isOpening = true; | |
| 2771 | + this._handleClickOffToClose = function() { | |
| 2772 | + if (!isOpening) _this9._closeDropdown(); | |
| 2773 | + isOpening = false; | |
| 2774 | + }; | |
| 2775 | + document.documentElement.addEventListener("click", this._handleClickOffToClose); | |
| 2776 | + // listen for up/down scrolling, enter to select, or letters to jump to country name. | |
| 2777 | + // use keydown as keypress doesn't fire for non-char keys and we want to catch if they | |
| 2778 | + // just hit down and hold it to scroll down (no keyup event). | |
| 2779 | + // listen on the document because that's where key events are triggered if no input has focus | |
| 2780 | + var query = ""; | |
| 2781 | + var queryTimer = null; | |
| 2782 | + this._handleKeydownOnDropdown = function(e) { | |
| 2783 | + // prevent down key from scrolling the whole page, | |
| 2784 | + // and enter key from submitting a form etc | |
| 2785 | + e.preventDefault(); | |
| 2786 | + // up and down to navigate | |
| 2787 | + if (e.key === "ArrowUp" || e.key === "Up" || e.key === "ArrowDown" || e.key === "Down") _this9._handleUpDownKey(e.key); else if (e.key === "Enter") _this9._handleEnterKey(); else if (e.key === "Escape") _this9._closeDropdown(); else if (/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) { | |
| 2788 | + // jump to countries that start with the query string | |
| 2789 | + if (queryTimer) clearTimeout(queryTimer); | |
| 2790 | + query += e.key.toLowerCase(); | |
| 2791 | + _this9._searchForCountry(query); | |
| 2792 | + // if the timer hits 1 second, reset the query | |
| 2793 | + queryTimer = setTimeout(function() { | |
| 2794 | + query = ""; | |
| 2795 | + }, 1e3); | |
| 2796 | + } | |
| 2797 | + }; | |
| 2798 | + document.addEventListener("keydown", this._handleKeydownOnDropdown); | |
| 2799 | + } | |
| 2800 | + }, { | |
| 2801 | + key: "_handleUpDownKey", | |
| 2802 | + value: function _handleUpDownKey(key) { | |
| 2803 | + var next = key === "ArrowUp" || key === "Up" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling; | |
| 2804 | + if (next) { | |
| 2805 | + // skip the divider | |
| 2806 | + if (next.classList.contains("iti__divider")) { | |
| 2807 | + next = key === "ArrowUp" || key === "Up" ? next.previousElementSibling : next.nextElementSibling; | |
| 2808 | + } | |
| 2809 | + this._highlightListItem(next, true); | |
| 2810 | + } | |
| 2811 | + } | |
| 2812 | + }, { | |
| 2813 | + key: "_handleEnterKey", | |
| 2814 | + value: function _handleEnterKey() { | |
| 2815 | + if (this.highlightedItem) this._selectListItem(this.highlightedItem); | |
| 2816 | + } | |
| 2817 | + }, { | |
| 2818 | + key: "_searchForCountry", | |
| 2819 | + value: function _searchForCountry(query) { | |
| 2820 | + for (var i = 0; i < this.countries.length; i++) { | |
| 2821 | + if (this._startsWith(this.countries[i].name, query)) { | |
| 2822 | + var listItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(this.countries[i].iso2)); | |
| 2823 | + // update highlighting and scroll | |
| 2824 | + this._highlightListItem(listItem, false); | |
| 2825 | + this._scrollTo(listItem, true); | |
| 2826 | + break; | |
| 2827 | + } | |
| 2828 | + } | |
| 2829 | + } | |
| 2830 | + }, { | |
| 2831 | + key: "_startsWith", | |
| 2832 | + value: function _startsWith(a, b) { | |
| 2833 | + return a.substr(0, b.length).toLowerCase() === b; | |
| 2834 | + } | |
| 2835 | + }, { | |
| 2836 | + key: "_updateValFromNumber", | |
| 2837 | + value: function _updateValFromNumber(originalNumber) { | |
| 2838 | + var number = originalNumber; | |
| 2839 | + if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) { | |
| 2840 | + var useNational = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) !== "+"); | |
| 2841 | + var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL; | |
| 2842 | + var format = useNational ? NATIONAL : INTERNATIONAL; | |
| 2843 | + number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format); | |
| 2844 | + } | |
| 2845 | + number = this._beforeSetNumber(number); | |
| 2846 | + this.telInput.value = number; | |
| 2847 | + } | |
| 2848 | + }, { | |
| 2849 | + key: "_updateFlagFromNumber", | |
| 2850 | + value: function _updateFlagFromNumber(originalNumber) { | |
| 2851 | + // if we're in nationalMode and we already have US/Canada selected, make sure the number starts | |
| 2852 | + // with a +1 so _getDialCode will be able to extract the area code | |
| 2853 | + // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag | |
| 2854 | + // from the number), that means we're initialising the plugin with a number that already has a | |
| 2855 | + // dial code, so fine to ignore this bit | |
| 2856 | + var number = originalNumber; | |
| 2857 | + var selectedDialCode = this.selectedCountryData.dialCode; | |
| 2858 | + var isNanp = selectedDialCode === "1"; | |
| 2859 | + if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") { | |
| 2860 | + if (number.charAt(0) !== "1") number = "1".concat(number); | |
| 2861 | + number = "+".concat(number); | |
| 2862 | + } | |
| 2863 | + // update flag if user types area code for another country | |
| 2864 | + if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") { | |
| 2865 | + number = "+".concat(selectedDialCode).concat(number); | |
| 2866 | + } | |
| 2867 | + // try and extract valid dial code from input | |
| 2868 | + var dialCode = this._getDialCode(number, true); | |
| 2869 | + var numeric = this._getNumeric(number); | |
| 2870 | + var countryCode = null; | |
| 2871 | + if (dialCode) { | |
| 2872 | + var countryCodes = this.countryCodes[this._getNumeric(dialCode)]; | |
| 2873 | + // check if the right country is already selected. this should be false if the number is | |
| 2874 | + // longer than the matched dial code because in this case we need to make sure that if | |
| 2875 | + // there are multiple country matches, that the first one is selected (note: we could | |
| 2876 | + // just check that here, but it requires the same loop that we already have later) | |
| 2877 | + var alreadySelected = countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1; | |
| 2878 | + var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric); | |
| 2879 | + // only update the flag if: | |
| 2880 | + // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp) | |
| 2881 | + // AND | |
| 2882 | + // B) the right country is not already selected | |
| 2883 | + if (!isRegionlessNanpNumber && !alreadySelected) { | |
| 2884 | + // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first | |
| 2885 | + // non-empty index | |
| 2886 | + for (var j = 0; j < countryCodes.length; j++) { | |
| 2887 | + if (countryCodes[j]) { | |
| 2888 | + countryCode = countryCodes[j]; | |
| 2889 | + break; | |
| 2890 | + } | |
| 2891 | + } | |
| 2892 | + } | |
| 2893 | + } else if (number.charAt(0) === "+" && numeric.length) { | |
| 2894 | + // invalid dial code, so empty | |
| 2895 | + // Note: use getNumeric here because the number has not been formatted yet, so could contain | |
| 2896 | + // bad chars | |
| 2897 | + countryCode = ""; | |
| 2898 | + } else if (!number || number === "+") { | |
| 2899 | + // empty, or just a plus, so default | |
| 2900 | + countryCode = this.defaultCountry; | |
| 2901 | + } | |
| 2902 | + if (countryCode !== null) { | |
| 2903 | + return this._setFlag(countryCode); | |
| 2904 | + } | |
| 2905 | + return false; | |
| 2906 | + } | |
| 2907 | + }, { | |
| 2908 | + key: "_isRegionlessNanp", | |
| 2909 | + value: function _isRegionlessNanp(number) { | |
| 2910 | + var numeric = this._getNumeric(number); | |
| 2911 | + if (numeric.charAt(0) === "1") { | |
| 2912 | + var areaCode = numeric.substr(1, 3); | |
| 2913 | + return regionlessNanpNumbers.indexOf(areaCode) !== -1; | |
| 2914 | + } | |
| 2915 | + return false; | |
| 2916 | + } | |
| 2917 | + }, { | |
| 2918 | + key: "_highlightListItem", | |
| 2919 | + value: function _highlightListItem(listItem, shouldFocus) { | |
| 2920 | + var prevItem = this.highlightedItem; | |
| 2921 | + if (prevItem) prevItem.classList.remove("iti__highlight"); | |
| 2922 | + this.highlightedItem = listItem; | |
| 2923 | + this.highlightedItem.classList.add("iti__highlight"); | |
| 2924 | + if (shouldFocus) this.highlightedItem.focus(); | |
| 2925 | + } | |
| 2926 | + }, { | |
| 2927 | + key: "_getCountryData", | |
| 2928 | + value: function _getCountryData(countryCode, ignoreOnlyCountriesOption, allowFail) { | |
| 2929 | + var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries; | |
| 2930 | + for (var i = 0; i < countryList.length; i++) { | |
| 2931 | + if (countryList[i].iso2 === countryCode) { | |
| 2932 | + return countryList[i]; | |
| 2933 | + } | |
| 2934 | + } | |
| 2935 | + if (allowFail) { | |
| 2936 | + return null; | |
| 2937 | + } | |
| 2938 | + throw new Error("No country data for '".concat(countryCode, "'")); | |
| 2939 | + } | |
| 2940 | + }, { | |
| 2941 | + key: "_setFlag", | |
| 2942 | + value: function _setFlag(countryCode) { | |
| 2943 | + var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {}; | |
| 2944 | + // do this first as it will throw an error and stop if countryCode is invalid | |
| 2945 | + this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {}; | |
| 2946 | + // update the defaultCountry - we only need the iso2 from now on, so just store that | |
| 2947 | + if (this.selectedCountryData.iso2) { | |
| 2948 | + this.defaultCountry = this.selectedCountryData.iso2; | |
| 2949 | + } | |
| 2950 | + this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode)); | |
| 2951 | + // update the selected country's title attribute | |
| 2952 | + var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown"; | |
| 2953 | + this.selectedFlag.setAttribute("title", title); | |
| 2954 | + if (this.options.separateDialCode) { | |
| 2955 | + var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : ""; | |
| 2956 | + this.selectedDialCode.innerHTML = dialCode; | |
| 2957 | + // offsetWidth is zero if input is in a hidden container during initialisation | |
| 2958 | + var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth(); | |
| 2959 | + // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css | |
| 2960 | + this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px"); | |
| 2961 | + } | |
| 2962 | + // and the input's placeholder | |
| 2963 | + this._updatePlaceholder(); | |
| 2964 | + // update the active list item | |
| 2965 | + if (this.options.allowDropdown) { | |
| 2966 | + var prevItem = this.activeItem; | |
| 2967 | + if (prevItem) { | |
| 2968 | + prevItem.classList.remove("iti__active"); | |
| 2969 | + prevItem.setAttribute("aria-selected", "false"); | |
| 2970 | + } | |
| 2971 | + if (countryCode) { | |
| 2972 | + // check if there is a preferred item first, else fall back to standard | |
| 2973 | + var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode)); | |
| 2974 | + nextItem.setAttribute("aria-selected", "true"); | |
| 2975 | + nextItem.classList.add("iti__active"); | |
| 2976 | + this.activeItem = nextItem; | |
| 2977 | + this.selectedFlag.setAttribute("aria-activedescendant", nextItem.getAttribute("id")); | |
| 2978 | + } | |
| 2979 | + } | |
| 2980 | + // return if the flag has changed or not | |
| 2981 | + return prevCountry.iso2 !== countryCode; | |
| 2982 | + } | |
| 2983 | + }, { | |
| 2984 | + key: "_getHiddenSelectedFlagWidth", | |
| 2985 | + value: function _getHiddenSelectedFlagWidth() { | |
| 2986 | + // to get the right styling to apply, all we need is a shallow clone of the container, | |
| 2987 | + // and then to inject a deep clone of the selectedFlag element | |
| 2988 | + var containerClone = this.telInput.parentNode.cloneNode(); | |
| 2989 | + containerClone.style.visibility = "hidden"; | |
| 2990 | + document.body.appendChild(containerClone); | |
| 2991 | + var flagsContainerClone = this.flagsContainer.cloneNode(); | |
| 2992 | + containerClone.appendChild(flagsContainerClone); | |
| 2993 | + var selectedFlagClone = this.selectedFlag.cloneNode(true); | |
| 2994 | + flagsContainerClone.appendChild(selectedFlagClone); | |
| 2995 | + var width = selectedFlagClone.offsetWidth; | |
| 2996 | + containerClone.parentNode.removeChild(containerClone); | |
| 2997 | + return width; | |
| 2998 | + } | |
| 2999 | + }, { | |
| 3000 | + key: "_updatePlaceholder", | |
| 3001 | + value: function _updatePlaceholder() { | |
| 3002 | + var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && this.options.autoPlaceholder === "polite"; | |
| 3003 | + if (window.intlTelInputUtils && shouldSetPlaceholder) { | |
| 3004 | + var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType]; | |
| 3005 | + var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : ""; | |
| 3006 | + placeholder = this._beforeSetNumber(placeholder); | |
| 3007 | + if (typeof this.options.customPlaceholder === "function") { | |
| 3008 | + placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData); | |
| 3009 | + } | |
| 3010 | + this.telInput.setAttribute("placeholder", placeholder); | |
| 3011 | + } | |
| 3012 | + } | |
| 3013 | + }, { | |
| 3014 | + key: "_selectListItem", | |
| 3015 | + value: function _selectListItem(listItem) { | |
| 3016 | + // update selected flag and active list item | |
| 3017 | + var flagChanged = this._setFlag(listItem.getAttribute("data-country-code")); | |
| 3018 | + this._closeDropdown(); | |
| 3019 | + this._updateDialCode(listItem.getAttribute("data-dial-code"), true); | |
| 3020 | + // focus the input | |
| 3021 | + this.telInput.focus(); | |
| 3022 | + // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto | |
| 3023 | + // inserting dial code), who try to put the cursor at the beginning the first time | |
| 3024 | + var len = this.telInput.value.length; | |
| 3025 | + this.telInput.setSelectionRange(len, len); | |
| 3026 | + if (flagChanged) { | |
| 3027 | + this._triggerCountryChange(); | |
| 3028 | + } | |
| 3029 | + } | |
| 3030 | + }, { | |
| 3031 | + key: "_closeDropdown", | |
| 3032 | + value: function _closeDropdown() { | |
| 3033 | + this.countryList.classList.add("iti__hide"); | |
| 3034 | + this.selectedFlag.setAttribute("aria-expanded", "false"); | |
| 3035 | + // update the arrow | |
| 3036 | + this.dropdownArrow.classList.remove("iti__arrow--up"); | |
| 3037 | + // unbind key events | |
| 3038 | + document.removeEventListener("keydown", this._handleKeydownOnDropdown); | |
| 3039 | + document.documentElement.removeEventListener("click", this._handleClickOffToClose); | |
| 3040 | + this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList); | |
| 3041 | + this.countryList.removeEventListener("click", this._handleClickCountryList); | |
| 3042 | + // remove menu from container | |
| 3043 | + if (this.options.dropdownContainer) { | |
| 3044 | + if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll); | |
| 3045 | + if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown); | |
| 3046 | + } | |
| 3047 | + this._trigger("close:countrydropdown"); | |
| 3048 | + } | |
| 3049 | + }, { | |
| 3050 | + key: "_scrollTo", | |
| 3051 | + value: function _scrollTo(element, middle) { | |
| 3052 | + var container = this.countryList; | |
| 3053 | + // windowTop from https://stackoverflow.com/a/14384091/217866 | |
| 3054 | + var windowTop = window.pageYOffset || document.documentElement.scrollTop; | |
| 3055 | + var containerHeight = container.offsetHeight; | |
| 3056 | + var containerTop = container.getBoundingClientRect().top + windowTop; | |
| 3057 | + var containerBottom = containerTop + containerHeight; | |
| 3058 | + var elementHeight = element.offsetHeight; | |
| 3059 | + var elementTop = element.getBoundingClientRect().top + windowTop; | |
| 3060 | + var elementBottom = elementTop + elementHeight; | |
| 3061 | + var newScrollTop = elementTop - containerTop + container.scrollTop; | |
| 3062 | + var middleOffset = containerHeight / 2 - elementHeight / 2; | |
| 3063 | + if (elementTop < containerTop) { | |
| 3064 | + // scroll up | |
| 3065 | + if (middle) newScrollTop -= middleOffset; | |
| 3066 | + container.scrollTop = newScrollTop; | |
| 3067 | + } else if (elementBottom > containerBottom) { | |
| 3068 | + // scroll down | |
| 3069 | + if (middle) newScrollTop += middleOffset; | |
| 3070 | + var heightDifference = containerHeight - elementHeight; | |
| 3071 | + container.scrollTop = newScrollTop - heightDifference; | |
| 3072 | + } | |
| 3073 | + } | |
| 3074 | + }, { | |
| 3075 | + key: "_updateDialCode", | |
| 3076 | + value: function _updateDialCode(newDialCodeBare, hasSelectedListItem) { | |
| 3077 | + var inputVal = this.telInput.value; | |
| 3078 | + // save having to pass this every time | |
| 3079 | + var newDialCode = "+".concat(newDialCodeBare); | |
| 3080 | + var newNumber; | |
| 3081 | + if (inputVal.charAt(0) === "+") { | |
| 3082 | + // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not) | |
| 3083 | + var prevDialCode = this._getDialCode(inputVal); | |
| 3084 | + if (prevDialCode) { | |
| 3085 | + // current number contains a valid dial code, so replace it | |
| 3086 | + newNumber = inputVal.replace(prevDialCode, newDialCode); | |
| 3087 | + } else { | |
| 3088 | + // current number contains an invalid dial code, so ditch it | |
| 3089 | + // (no way to determine where the invalid dial code ends and the rest of the number begins) | |
| 3090 | + newNumber = newDialCode; | |
| 3091 | + } | |
| 3092 | + } else if (this.options.nationalMode || this.options.separateDialCode) { | |
| 3093 | + // don't do anything | |
| 3094 | + return; | |
| 3095 | + } else { | |
| 3096 | + // nationalMode is disabled | |
| 3097 | + if (inputVal) { | |
| 3098 | + // there is an existing value with no dial code: prefix the new dial code | |
| 3099 | + newNumber = newDialCode + inputVal; | |
| 3100 | + } else if (hasSelectedListItem || !this.options.autoHideDialCode) { | |
| 3101 | + // no existing value and either they've just selected a list item, or autoHideDialCode is | |
| 3102 | + // disabled: insert new dial code | |
| 3103 | + newNumber = newDialCode; | |
| 3104 | + } else { | |
| 3105 | + return; | |
| 3106 | + } | |
| 3107 | + } | |
| 3108 | + this.telInput.value = newNumber; | |
| 3109 | + } | |
| 3110 | + }, { | |
| 3111 | + key: "_getDialCode", | |
| 3112 | + value: function _getDialCode(number, includeAreaCode) { | |
| 3113 | + var dialCode = ""; | |
| 3114 | + // only interested in international numbers (starting with a plus) | |
| 3115 | + if (number.charAt(0) === "+") { | |
| 3116 | + var numericChars = ""; | |
| 3117 | + // iterate over chars | |
| 3118 | + for (var i = 0; i < number.length; i++) { | |
| 3119 | + var c = number.charAt(i); | |
| 3120 | + // if char is number (https://stackoverflow.com/a/8935649/217866) | |
| 3121 | + if (!isNaN(parseInt(c, 10))) { | |
| 3122 | + numericChars += c; | |
| 3123 | + // if current numericChars make a valid dial code | |
| 3124 | + if (includeAreaCode) { | |
| 3125 | + if (this.countryCodes[numericChars]) { | |
| 3126 | + // store the actual raw string (useful for matching later) | |
| 3127 | + dialCode = number.substr(0, i + 1); | |
| 3128 | + } | |
| 3129 | + } else { | |
| 3130 | + if (this.dialCodes[numericChars]) { | |
| 3131 | + dialCode = number.substr(0, i + 1); | |
| 3132 | + // if we're just looking for a dial code, we can break as soon as we find one | |
| 3133 | + break; | |
| 3134 | + } | |
| 3135 | + } | |
| 3136 | + // stop searching as soon as we can - in this case when we hit max len | |
| 3137 | + if (numericChars.length === this.countryCodeMaxLen) { | |
| 3138 | + break; | |
| 3139 | + } | |
| 3140 | + } | |
| 3141 | + } | |
| 3142 | + } | |
| 3143 | + return dialCode; | |
| 3144 | + } | |
| 3145 | + }, { | |
| 3146 | + key: "_getFullNumber", | |
| 3147 | + value: function _getFullNumber() { | |
| 3148 | + var val = this.telInput.value.trim(); | |
| 3149 | + var dialCode = this.selectedCountryData.dialCode; | |
| 3150 | + var prefix; | |
| 3151 | + var numericVal = this._getNumeric(val); | |
| 3152 | + if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) { | |
| 3153 | + // when using separateDialCode, it is visible so is effectively part of the typed number | |
| 3154 | + prefix = "+".concat(dialCode); | |
| 3155 | + } else { | |
| 3156 | + prefix = ""; | |
| 3157 | + } | |
| 3158 | + return prefix + val; | |
| 3159 | + } | |
| 3160 | + }, { | |
| 3161 | + key: "_beforeSetNumber", | |
| 3162 | + value: function _beforeSetNumber(originalNumber) { | |
| 3163 | + var number = originalNumber; | |
| 3164 | + if (this.options.separateDialCode) { | |
| 3165 | + var dialCode = this._getDialCode(number); | |
| 3166 | + // if there is a valid dial code | |
| 3167 | + if (dialCode) { | |
| 3168 | + // in case _getDialCode returned an area code as well | |
| 3169 | + dialCode = "+".concat(this.selectedCountryData.dialCode); | |
| 3170 | + // a lot of numbers will have a space separating the dial code and the main number, and | |
| 3171 | + // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get | |
| 3172 | + // rid of it | |
| 3173 | + // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc | |
| 3174 | + var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length; | |
| 3175 | + number = number.substr(start); | |
| 3176 | + } | |
| 3177 | + } | |
| 3178 | + return this._cap(number); | |
| 3179 | + } | |
| 3180 | + }, { | |
| 3181 | + key: "_triggerCountryChange", | |
| 3182 | + value: function _triggerCountryChange() { | |
| 3183 | + this._trigger("countrychange"); | |
| 3184 | + } | |
| 3185 | + }, { | |
| 3186 | + key: "handleAutoCountry", | |
| 3187 | + value: function handleAutoCountry() { | |
| 3188 | + if (this.options.initialCountry === "auto") { | |
| 3189 | + // we must set this even if there is an initial val in the input: in case the initial val is | |
| 3190 | + // invalid and they delete it - they should see their auto country | |
| 3191 | + this.defaultCountry = window.intlTelInputGlobals.autoCountry; | |
| 3192 | + // if there's no initial value in the input, then update the flag | |
| 3193 | + if (!this.telInput.value) { | |
| 3194 | + this.setCountry(this.defaultCountry); | |
| 3195 | + } | |
| 3196 | + this.resolveAutoCountryPromise(); | |
| 3197 | + } | |
| 3198 | + } | |
| 3199 | + }, { | |
| 3200 | + key: "handleUtils", | |
| 3201 | + value: function handleUtils() { | |
| 3202 | + // if the request was successful | |
| 3203 | + if (window.intlTelInputUtils) { | |
| 3204 | + // if there's an initial value in the input, then format it | |
| 3205 | + if (this.telInput.value) { | |
| 3206 | + this._updateValFromNumber(this.telInput.value); | |
| 3207 | + } | |
| 3208 | + this._updatePlaceholder(); | |
| 3209 | + } | |
| 3210 | + this.resolveUtilsScriptPromise(); | |
| 3211 | + } | |
| 3212 | + }, { | |
| 3213 | + key: "destroy", | |
| 3214 | + value: function destroy() { | |
| 3215 | + var form = this.telInput.form; | |
| 3216 | + if (this.options.allowDropdown) { | |
| 3217 | + // make sure the dropdown is closed (and unbind listeners) | |
| 3218 | + this._closeDropdown(); | |
| 3219 | + this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag); | |
| 3220 | + this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown); | |
| 3221 | + // label click hack | |
| 3222 | + var label = this._getClosestLabel(); | |
| 3223 | + if (label) label.removeEventListener("click", this._handleLabelClick); | |
| 3224 | + } | |
| 3225 | + // unbind hiddenInput listeners | |
| 3226 | + if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit); | |
| 3227 | + // unbind autoHideDialCode listeners | |
| 3228 | + if (this.options.autoHideDialCode) { | |
| 3229 | + if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent); | |
| 3230 | + this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent); | |
| 3231 | + } | |
| 3232 | + // unbind key events, and cut/paste events | |
| 3233 | + this.telInput.removeEventListener("keyup", this._handleKeyupEvent); | |
| 3234 | + this.telInput.removeEventListener("cut", this._handleClipboardEvent); | |
| 3235 | + this.telInput.removeEventListener("paste", this._handleClipboardEvent); | |
| 3236 | + // remove attribute of id instance: data-intl-tel-input-id | |
| 3237 | + this.telInput.removeAttribute("data-intl-tel-input-id"); | |
| 3238 | + // remove markup (but leave the original input) | |
| 3239 | + var wrapper = this.telInput.parentNode; | |
| 3240 | + wrapper.parentNode.insertBefore(this.telInput, wrapper); | |
| 3241 | + wrapper.parentNode.removeChild(wrapper); | |
| 3242 | + delete window.intlTelInputGlobals.instances[this.id]; | |
| 3243 | + } | |
| 3244 | + }, { | |
| 3245 | + key: "getExtension", | |
| 3246 | + value: function getExtension() { | |
| 3247 | + if (window.intlTelInputUtils) { | |
| 3248 | + return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2); | |
| 3249 | + } | |
| 3250 | + return ""; | |
| 3251 | + } | |
| 3252 | + }, { | |
| 3253 | + key: "getNumber", | |
| 3254 | + value: function getNumber(format) { | |
| 3255 | + if (window.intlTelInputUtils) { | |
| 3256 | + var iso2 = this.selectedCountryData.iso2; | |
| 3257 | + return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format); | |
| 3258 | + } | |
| 3259 | + return ""; | |
| 3260 | + } | |
| 3261 | + }, { | |
| 3262 | + key: "getNumberType", | |
| 3263 | + value: function getNumberType() { | |
| 3264 | + if (window.intlTelInputUtils) { | |
| 3265 | + return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2); | |
| 3266 | + } | |
| 3267 | + return -99; | |
| 3268 | + } | |
| 3269 | + }, { | |
| 3270 | + key: "getSelectedCountryData", | |
| 3271 | + value: function getSelectedCountryData() { | |
| 3272 | + return this.selectedCountryData; | |
| 3273 | + } | |
| 3274 | + }, { | |
| 3275 | + key: "getValidationError", | |
| 3276 | + value: function getValidationError() { | |
| 3277 | + if (window.intlTelInputUtils) { | |
| 3278 | + var iso2 = this.selectedCountryData.iso2; | |
| 3279 | + return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2); | |
| 3280 | + } | |
| 3281 | + return -99; | |
| 3282 | + } | |
| 3283 | + }, { | |
| 3284 | + key: "isValidNumber", | |
| 3285 | + value: function isValidNumber() { | |
| 3286 | + var val = this._getFullNumber().trim(); | |
| 3287 | + var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : ""; | |
| 3288 | + return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null; | |
| 3289 | + } | |
| 3290 | + }, { | |
| 3291 | + key: "setCountry", | |
| 3292 | + value: function setCountry(originalCountryCode) { | |
| 3293 | + var countryCode = originalCountryCode.toLowerCase(); | |
| 3294 | + // check if already selected | |
| 3295 | + if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) { | |
| 3296 | + this._setFlag(countryCode); | |
| 3297 | + this._updateDialCode(this.selectedCountryData.dialCode, false); | |
| 3298 | + this._triggerCountryChange(); | |
| 3299 | + } | |
| 3300 | + } | |
| 3301 | + }, { | |
| 3302 | + key: "setNumber", | |
| 3303 | + value: function setNumber(number) { | |
| 3304 | + // we must update the flag first, which updates this.selectedCountryData, which is used for | |
| 3305 | + // formatting the number before displaying it | |
| 3306 | + var flagChanged = this._updateFlagFromNumber(number); | |
| 3307 | + this._updateValFromNumber(number); | |
| 3308 | + if (flagChanged) { | |
| 3309 | + this._triggerCountryChange(); | |
| 3310 | + } | |
| 3311 | + } | |
| 3312 | + }, { | |
| 3313 | + key: "setPlaceholderNumberType", | |
| 3314 | + value: function setPlaceholderNumberType(type) { | |
| 3315 | + this.options.placeholderNumberType = type; | |
| 3316 | + this._updatePlaceholder(); | |
| 3317 | + } | |
| 3318 | + } ]); | |
| 3319 | + return Iti; | |
| 3320 | + }(); | |
| 3321 | + /******************** | |
| 3322 | + * STATIC METHODS | |
| 3323 | + ********************/ | |
| 3324 | + // get the country data object | |
| 3325 | + intlTelInputGlobals.getCountryData = function() { | |
| 3326 | + return allCountries; | |
| 3327 | + }; | |
| 3328 | + // inject a <script> element to load utils.js | |
| 3329 | + var injectScript = function injectScript(path, handleSuccess, handleFailure) { | |
| 3330 | + // inject a new script element into the page | |
| 3331 | + var script = document.createElement("script"); | |
| 3332 | + script.onload = function() { | |
| 3333 | + forEachInstance("handleUtils"); | |
| 3334 | + if (handleSuccess) handleSuccess(); | |
| 3335 | + }; | |
| 3336 | + script.onerror = function() { | |
| 3337 | + forEachInstance("rejectUtilsScriptPromise"); | |
| 3338 | + if (handleFailure) handleFailure(); | |
| 3339 | + }; | |
| 3340 | + script.className = "iti-load-utils"; | |
| 3341 | + script.async = true; | |
| 3342 | + script.src = path; | |
| 3343 | + document.body.appendChild(script); | |
| 3344 | + }; | |
| 3345 | + // load the utils script | |
| 3346 | + intlTelInputGlobals.loadUtils = function(path) { | |
| 3347 | + // 2 options: | |
| 3348 | + // 1) not already started loading (start) | |
| 3349 | + // 2) already started loading (do nothing - just wait for the onload callback to fire, which will | |
| 3350 | + // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions) | |
| 3351 | + if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) { | |
| 3352 | + // only do this once | |
| 3353 | + window.intlTelInputGlobals.startedLoadingUtilsScript = true; | |
| 3354 | + // if we have promises, then return a promise | |
| 3355 | + if (typeof Promise !== "undefined") { | |
| 3356 | + return new Promise(function(resolve, reject) { | |
| 3357 | + return injectScript(path, resolve, reject); | |
| 3358 | + }); | |
| 3359 | + } | |
| 3360 | + injectScript(path); | |
| 3361 | + } | |
| 3362 | + return null; | |
| 3363 | + }; | |
| 3364 | + // default options | |
| 3365 | + intlTelInputGlobals.defaults = defaults; | |
| 3366 | + // version | |
| 3367 | + intlTelInputGlobals.version = "17.0.16"; | |
| 3368 | + // convenience wrapper | |
| 3369 | + return function(input, options) { | |
| 3370 | + var iti = new Iti(input, options); | |
| 3371 | + iti._init(); | |
| 3372 | + input.setAttribute("data-intl-tel-input-id", iti.id); | |
| 3373 | + window.intlTelInputGlobals.instances[iti.id] = iti; | |
| 3374 | + return iti; | |
| 3375 | + }; | |
| 3376 | + }(); | |
| 3377 | +}); | |
| 3378 | +},{}],27:[function(require,module,exports){ | |
| 3379 | +/** | |
| 3380 | + * Exposing intl-tel-input as a component | |
| 3381 | + */ | |
| 3382 | +module.exports = require("./build/js/intlTelInput"); | |
| 3383 | + | |
| 3384 | +},{"./build/js/intlTelInput":26}],28:[function(require,module,exports){ | |
| 3385 | +(function (process){ | |
| 3386 | +/** | |
| 3387 | + * Memize options object. | |
| 3388 | + * | |
| 3389 | + * @typedef MemizeOptions | |
| 3390 | + * | |
| 3391 | + * @property {number} [maxSize] Maximum size of the cache. | |
| 3392 | + */ | |
| 3393 | + | |
| 3394 | +/** | |
| 3395 | + * Internal cache entry. | |
| 3396 | + * | |
| 3397 | + * @typedef MemizeCacheNode | |
| 3398 | + * | |
| 3399 | + * @property {?MemizeCacheNode|undefined} [prev] Previous node. | |
| 3400 | + * @property {?MemizeCacheNode|undefined} [next] Next node. | |
| 3401 | + * @property {Array<*>} args Function arguments for cache | |
| 3402 | + * entry. | |
| 3403 | + * @property {*} val Function result. | |
| 3404 | + */ | |
| 3405 | + | |
| 3406 | +/** | |
| 3407 | + * Properties of the enhanced function for controlling cache. | |
| 3408 | + * | |
| 3409 | + * @typedef MemizeMemoizedFunction | |
| 3410 | + * | |
| 3411 | + * @property {()=>void} clear Clear the cache. | |
| 3412 | + */ | |
| 3413 | + | |
| 3414 | +/** | |
| 3415 | + * Accepts a function to be memoized, and returns a new memoized function, with | |
| 3416 | + * optional options. | |
| 3417 | + * | |
| 3418 | + * @template {Function} F | |
| 3419 | + * | |
| 3420 | + * @param {F} fn Function to memoize. | |
| 3421 | + * @param {MemizeOptions} [options] Options object. | |
| 3422 | + * | |
| 3423 | + * @return {F & MemizeMemoizedFunction} Memoized function. | |
| 3424 | + */ | |
| 3425 | +function memize( fn, options ) { | |
| 3426 | + var size = 0; | |
| 3427 | + | |
| 3428 | + /** @type {?MemizeCacheNode|undefined} */ | |
| 3429 | + var head; | |
| 3430 | + | |
| 3431 | + /** @type {?MemizeCacheNode|undefined} */ | |
| 3432 | + var tail; | |
| 3433 | + | |
| 3434 | + options = options || {}; | |
| 3435 | + | |
| 3436 | + function memoized( /* ...args */ ) { | |
| 3437 | + var node = head, | |
| 3438 | + len = arguments.length, | |
| 3439 | + args, i; | |
| 3440 | + | |
| 3441 | + searchCache: while ( node ) { | |
| 3442 | + // Perform a shallow equality test to confirm that whether the node | |
| 3443 | + // under test is a candidate for the arguments passed. Two arrays | |
| 3444 | + // are shallowly equal if their length matches and each entry is | |
| 3445 | + // strictly equal between the two sets. Avoid abstracting to a | |
| 3446 | + // function which could incur an arguments leaking deoptimization. | |
| 3447 | + | |
| 3448 | + // Check whether node arguments match arguments length | |
| 3449 | + if ( node.args.length !== arguments.length ) { | |
| 3450 | + node = node.next; | |
| 3451 | + continue; | |
| 3452 | + } | |
| 3453 | + | |
| 3454 | + // Check whether node arguments match arguments values | |
| 3455 | + for ( i = 0; i < len; i++ ) { | |
| 3456 | + if ( node.args[ i ] !== arguments[ i ] ) { | |
| 3457 | + node = node.next; | |
| 3458 | + continue searchCache; | |
| 3459 | + } | |
| 3460 | + } | |
| 3461 | + | |
| 3462 | + // At this point we can assume we've found a match | |
| 3463 | + | |
| 3464 | + // Surface matched node to head if not already | |
| 3465 | + if ( node !== head ) { | |
| 3466 | + // As tail, shift to previous. Must only shift if not also | |
| 3467 | + // head, since if both head and tail, there is no previous. | |
| 3468 | + if ( node === tail ) { | |
| 3469 | + tail = node.prev; | |
| 3470 | + } | |
| 3471 | + | |
| 3472 | + // Adjust siblings to point to each other. If node was tail, | |
| 3473 | + // this also handles new tail's empty `next` assignment. | |
| 3474 | + /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next; | |
| 3475 | + if ( node.next ) { | |
| 3476 | + node.next.prev = node.prev; | |
| 3477 | + } | |
| 3478 | + | |
| 3479 | + node.next = head; | |
| 3480 | + node.prev = null; | |
| 3481 | + /** @type {MemizeCacheNode} */ ( head ).prev = node; | |
| 3482 | + head = node; | |
| 3483 | + } | |
| 3484 | + | |
| 3485 | + // Return immediately | |
| 3486 | + return node.val; | |
| 3487 | + } | |
| 3488 | + | |
| 3489 | + // No cached value found. Continue to insertion phase: | |
| 3490 | + | |
| 3491 | + // Create a copy of arguments (avoid leaking deoptimization) | |
| 3492 | + args = new Array( len ); | |
| 3493 | + for ( i = 0; i < len; i++ ) { | |
| 3494 | + args[ i ] = arguments[ i ]; | |
| 3495 | + } | |
| 3496 | + | |
| 3497 | + node = { | |
| 3498 | + args: args, | |
| 3499 | + | |
| 3500 | + // Generate the result from original function | |
| 3501 | + val: fn.apply( null, args ), | |
| 3502 | + }; | |
| 3503 | + | |
| 3504 | + // Don't need to check whether node is already head, since it would | |
| 3505 | + // have been returned above already if it was | |
| 3506 | + | |
| 3507 | + // Shift existing head down list | |
| 3508 | + if ( head ) { | |
| 3509 | + head.prev = node; | |
| 3510 | + node.next = head; | |
| 3511 | + } else { | |
| 3512 | + // If no head, follows that there's no tail (at initial or reset) | |
| 3513 | + tail = node; | |
| 3514 | + } | |
| 3515 | + | |
| 3516 | + // Trim tail if we're reached max size and are pending cache insertion | |
| 3517 | + if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) { | |
| 3518 | + tail = /** @type {MemizeCacheNode} */ ( tail ).prev; | |
| 3519 | + /** @type {MemizeCacheNode} */ ( tail ).next = null; | |
| 3520 | + } else { | |
| 3521 | + size++; | |
| 3522 | + } | |
| 3523 | + | |
| 3524 | + head = node; | |
| 3525 | + | |
| 3526 | + return node.val; | |
| 3527 | + } | |
| 3528 | + | |
| 3529 | + memoized.clear = function() { | |
| 3530 | + head = null; | |
| 3531 | + tail = null; | |
| 3532 | + size = 0; | |
| 3533 | + }; | |
| 3534 | + | |
| 3535 | + if ( process.env.NODE_ENV === 'test' ) { | |
| 3536 | + // Cache is not exposed in the public API, but used in tests to ensure | |
| 3537 | + // expected list progression | |
| 3538 | + memoized.getCache = function() { | |
| 3539 | + return [ head, tail, size ]; | |
| 3540 | + }; | |
| 3541 | + } | |
| 3542 | + | |
| 3543 | + // Ignore reason: There's not a clear solution to create an intersection of | |
| 3544 | + // the function with additional properties, where the goal is to retain the | |
| 3545 | + // function signature of the incoming argument and add control properties | |
| 3546 | + // on the return value. | |
| 3547 | + | |
| 3548 | + // @ts-ignore | |
| 3549 | + return memoized; | |
| 3550 | +} | |
| 3551 | + | |
| 3552 | +module.exports = memize; | |
| 3553 | + | |
| 3554 | +}).call(this,require('_process')) | |
| 3555 | +},{"_process":29}],29:[function(require,module,exports){ | |
| 3556 | +// shim for using process in browser | |
| 3557 | +var process = module.exports = {}; | |
| 3558 | + | |
| 3559 | +// cached from whatever global is present so that test runners that stub it | |
| 3560 | +// don't break things. But we need to wrap it in a try catch in case it is | |
| 3561 | +// wrapped in strict mode code which doesn't define any globals. It's inside a | |
| 3562 | +// function because try/catches deoptimize in certain engines. | |
| 3563 | + | |
| 3564 | +var cachedSetTimeout; | |
| 3565 | +var cachedClearTimeout; | |
| 3566 | + | |
| 3567 | +function defaultSetTimout() { | |
| 3568 | + throw new Error('setTimeout has not been defined'); | |
| 3569 | +} | |
| 3570 | +function defaultClearTimeout () { | |
| 3571 | + throw new Error('clearTimeout has not been defined'); | |
| 3572 | +} | |
| 3573 | +(function () { | |
| 3574 | + try { | |
| 3575 | + if (typeof setTimeout === 'function') { | |
| 3576 | + cachedSetTimeout = setTimeout; | |
| 3577 | + } else { | |
| 3578 | + cachedSetTimeout = defaultSetTimout; | |
| 3579 | + } | |
| 3580 | + } catch (e) { | |
| 3581 | + cachedSetTimeout = defaultSetTimout; | |
| 3582 | + } | |
| 3583 | + try { | |
| 3584 | + if (typeof clearTimeout === 'function') { | |
| 3585 | + cachedClearTimeout = clearTimeout; | |
| 3586 | + } else { | |
| 3587 | + cachedClearTimeout = defaultClearTimeout; | |
| 3588 | + } | |
| 3589 | + } catch (e) { | |
| 3590 | + cachedClearTimeout = defaultClearTimeout; | |
| 3591 | + } | |
| 3592 | +} ()) | |
| 3593 | +function runTimeout(fun) { | |
| 3594 | + if (cachedSetTimeout === setTimeout) { | |
| 3595 | + //normal enviroments in sane situations | |
| 3596 | + return setTimeout(fun, 0); | |
| 3597 | + } | |
| 3598 | + // if setTimeout wasn't available but was latter defined | |
| 3599 | + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { | |
| 3600 | + cachedSetTimeout = setTimeout; | |
| 3601 | + return setTimeout(fun, 0); | |
| 3602 | + } | |
| 3603 | + try { | |
| 3604 | + // when when somebody has screwed with setTimeout but no I.E. maddness | |
| 3605 | + return cachedSetTimeout(fun, 0); | |
| 3606 | + } catch(e){ | |
| 3607 | + try { | |
| 3608 | + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | |
| 3609 | + return cachedSetTimeout.call(null, fun, 0); | |
| 3610 | + } catch(e){ | |
| 3611 | + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error | |
| 3612 | + return cachedSetTimeout.call(this, fun, 0); | |
| 3613 | + } | |
| 3614 | + } | |
| 3615 | + | |
| 3616 | + | |
| 3617 | +} | |
| 3618 | +function runClearTimeout(marker) { | |
| 3619 | + if (cachedClearTimeout === clearTimeout) { | |
| 3620 | + //normal enviroments in sane situations | |
| 3621 | + return clearTimeout(marker); | |
| 3622 | + } | |
| 3623 | + // if clearTimeout wasn't available but was latter defined | |
| 3624 | + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { | |
| 3625 | + cachedClearTimeout = clearTimeout; | |
| 3626 | + return clearTimeout(marker); | |
| 3627 | + } | |
| 3628 | + try { | |
| 3629 | + // when when somebody has screwed with setTimeout but no I.E. maddness | |
| 3630 | + return cachedClearTimeout(marker); | |
| 3631 | + } catch (e){ | |
| 3632 | + try { | |
| 3633 | + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally | |
| 3634 | + return cachedClearTimeout.call(null, marker); | |
| 3635 | + } catch (e){ | |
| 3636 | + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. | |
| 3637 | + // Some versions of I.E. have different rules for clearTimeout vs setTimeout | |
| 3638 | + return cachedClearTimeout.call(this, marker); | |
| 3639 | + } | |
| 3640 | + } | |
| 3641 | + | |
| 3642 | + | |
| 3643 | + | |
| 3644 | +} | |
| 3645 | +var queue = []; | |
| 3646 | +var draining = false; | |
| 3647 | +var currentQueue; | |
| 3648 | +var queueIndex = -1; | |
| 3649 | + | |
| 3650 | +function cleanUpNextTick() { | |
| 3651 | + if (!draining || !currentQueue) { | |
| 3652 | + return; | |
| 3653 | + } | |
| 3654 | + draining = false; | |
| 3655 | + if (currentQueue.length) { | |
| 3656 | + queue = currentQueue.concat(queue); | |
| 3657 | + } else { | |
| 3658 | + queueIndex = -1; | |
| 3659 | + } | |
| 3660 | + if (queue.length) { | |
| 3661 | + drainQueue(); | |
| 3662 | + } | |
| 3663 | +} | |
| 3664 | + | |
| 3665 | +function drainQueue() { | |
| 3666 | + if (draining) { | |
| 3667 | + return; | |
| 3668 | + } | |
| 3669 | + var timeout = runTimeout(cleanUpNextTick); | |
| 3670 | + draining = true; | |
| 3671 | + | |
| 3672 | + var len = queue.length; | |
| 3673 | + while(len) { | |
| 3674 | + currentQueue = queue; | |
| 3675 | + queue = []; | |
| 3676 | + while (++queueIndex < len) { | |
| 3677 | + if (currentQueue) { | |
| 3678 | + currentQueue[queueIndex].run(); | |
| 3679 | + } | |
| 3680 | + } | |
| 3681 | + queueIndex = -1; | |
| 3682 | + len = queue.length; | |
| 3683 | + } | |
| 3684 | + currentQueue = null; | |
| 3685 | + draining = false; | |
| 3686 | + runClearTimeout(timeout); | |
| 3687 | +} | |
| 3688 | + | |
| 3689 | +process.nextTick = function (fun) { | |
| 3690 | + var args = new Array(arguments.length - 1); | |
| 3691 | + if (arguments.length > 1) { | |
| 3692 | + for (var i = 1; i < arguments.length; i++) { | |
| 3693 | + args[i - 1] = arguments[i]; | |
| 3694 | + } | |
| 3695 | + } | |
| 3696 | + queue.push(new Item(fun, args)); | |
| 3697 | + if (queue.length === 1 && !draining) { | |
| 3698 | + runTimeout(drainQueue); | |
| 3699 | + } | |
| 3700 | +}; | |
| 3701 | + | |
| 3702 | +// v8 likes predictible objects | |
| 3703 | +function Item(fun, array) { | |
| 3704 | + this.fun = fun; | |
| 3705 | + this.array = array; | |
| 3706 | +} | |
| 3707 | +Item.prototype.run = function () { | |
| 3708 | + this.fun.apply(null, this.array); | |
| 3709 | +}; | |
| 3710 | +process.title = 'browser'; | |
| 3711 | +process.browser = true; | |
| 3712 | +process.env = {}; | |
| 3713 | +process.argv = []; | |
| 3714 | +process.version = ''; // empty string to avoid regexp issues | |
| 3715 | +process.versions = {}; | |
| 3716 | + | |
| 3717 | +function noop() {} | |
| 3718 | + | |
| 3719 | +process.on = noop; | |
| 3720 | +process.addListener = noop; | |
| 3721 | +process.once = noop; | |
| 3722 | +process.off = noop; | |
| 3723 | +process.removeListener = noop; | |
| 3724 | +process.removeAllListeners = noop; | |
| 3725 | +process.emit = noop; | |
| 3726 | +process.prependListener = noop; | |
| 3727 | +process.prependOnceListener = noop; | |
| 3728 | + | |
| 3729 | +process.listeners = function (name) { return [] } | |
| 3730 | + | |
| 3731 | +process.binding = function (name) { | |
| 3732 | + throw new Error('process.binding is not supported'); | |
| 3733 | +}; | |
| 3734 | + | |
| 3735 | +process.cwd = function () { return '/' }; | |
| 3736 | +process.chdir = function (dir) { | |
| 3737 | + throw new Error('process.chdir is not supported'); | |
| 3738 | +}; | |
| 3739 | +process.umask = function() { return 0; }; | |
| 3740 | + | |
| 3741 | +},{}],30:[function(require,module,exports){ | |
| 3742 | +'use strict'; | |
| 3743 | + | |
| 3744 | +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | |
| 3745 | + | |
| 3746 | +var pluralForms = _interopDefault(require('@tannin/plural-forms')); | |
| 3747 | + | |
| 3748 | +/** | |
| 3749 | + * Tannin constructor options. | |
| 3750 | + * | |
| 3751 | + * @typedef {Object} TanninOptions | |
| 3752 | + * | |
| 3753 | + * @property {string} [contextDelimiter] Joiner in string lookup with context. | |
| 3754 | + * @property {Function} [onMissingKey] Callback to invoke when key missing. | |
| 3755 | + */ | |
| 3756 | + | |
| 3757 | +/** | |
| 3758 | + * Domain metadata. | |
| 3759 | + * | |
| 3760 | + * @typedef {Object} TanninDomainMetadata | |
| 3761 | + * | |
| 3762 | + * @property {string} [domain] Domain name. | |
| 3763 | + * @property {string} [lang] Language code. | |
| 3764 | + * @property {(string|Function)} [plural_forms] Plural forms expression or | |
| 3765 | + * function evaluator. | |
| 3766 | + */ | |
| 3767 | + | |
| 3768 | +/** | |
| 3769 | + * Domain translation pair respectively representing the singular and plural | |
| 3770 | + * translation. | |
| 3771 | + * | |
| 3772 | + * @typedef {[string,string]} TanninTranslation | |
| 3773 | + */ | |
| 3774 | + | |
| 3775 | +/** | |
| 3776 | + * Locale data domain. The key is used as reference for lookup, the value an | |
| 3777 | + * array of two string entries respectively representing the singular and plural | |
| 3778 | + * translation. | |
| 3779 | + * | |
| 3780 | + * @typedef {{[key:string]:TanninDomainMetadata|TanninTranslation,'':TanninDomainMetadata|TanninTranslation}} TanninLocaleDomain | |
| 3781 | + */ | |
| 3782 | + | |
| 3783 | +/** | |
| 3784 | + * Jed-formatted locale data. | |
| 3785 | + * | |
| 3786 | + * @see http://messageformat.github.io/Jed/ | |
| 3787 | + * | |
| 3788 | + * @typedef {{[domain:string]:TanninLocaleDomain}} TanninLocaleData | |
| 3789 | + */ | |
| 3790 | + | |
| 3791 | +/** | |
| 3792 | + * Default Tannin constructor options. | |
| 3793 | + * | |
| 3794 | + * @type {TanninOptions} | |
| 3795 | + */ | |
| 3796 | +var DEFAULT_OPTIONS = { | |
| 3797 | + contextDelimiter: '\u0004', | |
| 3798 | + onMissingKey: null, | |
| 3799 | +}; | |
| 3800 | + | |
| 3801 | +/** | |
| 3802 | + * Given a specific locale data's config `plural_forms` value, returns the | |
| 3803 | + * expression. | |
| 3804 | + * | |
| 3805 | + * @example | |
| 3806 | + * | |
| 3807 | + * ``` | |
| 3808 | + * getPluralExpression( 'nplurals=2; plural=(n != 1);' ) === '(n != 1)' | |
| 3809 | + * ``` | |
| 3810 | + * | |
| 3811 | + * @param {string} pf Locale data plural forms. | |
| 3812 | + * | |
| 3813 | + * @return {string} Plural forms expression. | |
| 3814 | + */ | |
| 3815 | +function getPluralExpression( pf ) { | |
| 3816 | + var parts, i, part; | |
| 3817 | + | |
| 3818 | + parts = pf.split( ';' ); | |
| 3819 | + | |
| 3820 | + for ( i = 0; i < parts.length; i++ ) { | |
| 3821 | + part = parts[ i ].trim(); | |
| 3822 | + if ( part.indexOf( 'plural=' ) === 0 ) { | |
| 3823 | + return part.substr( 7 ); | |
| 3824 | + } | |
| 3825 | + } | |
| 3826 | +} | |
| 3827 | + | |
| 3828 | +/** | |
| 3829 | + * Tannin constructor. | |
| 3830 | + * | |
| 3831 | + * @class | |
| 3832 | + * | |
| 3833 | + * @param {TanninLocaleData} data Jed-formatted locale data. | |
| 3834 | + * @param {TanninOptions} [options] Tannin options. | |
| 3835 | + */ | |
| 3836 | +function Tannin( data, options ) { | |
| 3837 | + var key; | |
| 3838 | + | |
| 3839 | + /** | |
| 3840 | + * Jed-formatted locale data. | |
| 3841 | + * | |
| 3842 | + * @name Tannin#data | |
| 3843 | + * @type {TanninLocaleData} | |
| 3844 | + */ | |
| 3845 | + this.data = data; | |
| 3846 | + | |
| 3847 | + /** | |
| 3848 | + * Plural forms function cache, keyed by plural forms string. | |
| 3849 | + * | |
| 3850 | + * @name Tannin#pluralForms | |
| 3851 | + * @type {Object<string,Function>} | |
| 3852 | + */ | |
| 3853 | + this.pluralForms = {}; | |
| 3854 | + | |
| 3855 | + /** | |
| 3856 | + * Effective options for instance, including defaults. | |
| 3857 | + * | |
| 3858 | + * @name Tannin#options | |
| 3859 | + * @type {TanninOptions} | |
| 3860 | + */ | |
| 3861 | + this.options = {}; | |
| 3862 | + | |
| 3863 | + for ( key in DEFAULT_OPTIONS ) { | |
| 3864 | + this.options[ key ] = options !== undefined && key in options | |
| 3865 | + ? options[ key ] | |
| 3866 | + : DEFAULT_OPTIONS[ key ]; | |
| 3867 | + } | |
| 3868 | +} | |
| 3869 | + | |
| 3870 | +/** | |
| 3871 | + * Returns the plural form index for the given domain and value. | |
| 3872 | + * | |
| 3873 | + * @param {string} domain Domain on which to calculate plural form. | |
| 3874 | + * @param {number} n Value for which plural form is to be calculated. | |
| 3875 | + * | |
| 3876 | + * @return {number} Plural form index. | |
| 3877 | + */ | |
| 3878 | +Tannin.prototype.getPluralForm = function( domain, n ) { | |
| 3879 | + var getPluralForm = this.pluralForms[ domain ], | |
| 3880 | + config, plural, pf; | |
| 3881 | + | |
| 3882 | + if ( ! getPluralForm ) { | |
| 3883 | + config = this.data[ domain ][ '' ]; | |
| 3884 | + | |
| 3885 | + pf = ( | |
| 3886 | + config[ 'Plural-Forms' ] || | |
| 3887 | + config[ 'plural-forms' ] || | |
| 3888 | + // Ignore reason: As known, there's no way to document the empty | |
| 3889 | + // string property on a key to guarantee this as metadata. | |
| 3890 | + // @ts-ignore | |
| 3891 | + config.plural_forms | |
| 3892 | + ); | |
| 3893 | + | |
| 3894 | + if ( typeof pf !== 'function' ) { | |
| 3895 | + plural = getPluralExpression( | |
| 3896 | + config[ 'Plural-Forms' ] || | |
| 3897 | + config[ 'plural-forms' ] || | |
| 3898 | + // Ignore reason: As known, there's no way to document the empty | |
| 3899 | + // string property on a key to guarantee this as metadata. | |
| 3900 | + // @ts-ignore | |
| 3901 | + config.plural_forms | |
| 3902 | + ); | |
| 3903 | + | |
| 3904 | + pf = pluralForms( plural ); | |
| 3905 | + } | |
| 3906 | + | |
| 3907 | + getPluralForm = this.pluralForms[ domain ] = pf; | |
| 3908 | + } | |
| 3909 | + | |
| 3910 | + return getPluralForm( n ); | |
| 3911 | +}; | |
| 3912 | + | |
| 3913 | +/** | |
| 3914 | + * Translate a string. | |
| 3915 | + * | |
| 3916 | + * @param {string} domain Translation domain. | |
| 3917 | + * @param {string|void} context Context distinguishing terms of the same name. | |
| 3918 | + * @param {string} singular Primary key for translation lookup. | |
| 3919 | + * @param {string=} plural Fallback value used for non-zero plural | |
| 3920 | + * form index. | |
| 3921 | + * @param {number=} n Value to use in calculating plural form. | |
| 3922 | + * | |
| 3923 | + * @return {string} Translated string. | |
| 3924 | + */ | |
| 3925 | +Tannin.prototype.dcnpgettext = function( domain, context, singular, plural, n ) { | |
| 3926 | + var index, key, entry; | |
| 3927 | + | |
| 3928 | + if ( n === undefined ) { | |
| 3929 | + // Default to singular. | |
| 3930 | + index = 0; | |
| 3931 | + } else { | |
| 3932 | + // Find index by evaluating plural form for value. | |
| 3933 | + index = this.getPluralForm( domain, n ); | |
| 3934 | + } | |
| 3935 | + | |
| 3936 | + key = singular; | |
| 3937 | + | |
| 3938 | + // If provided, context is prepended to key with delimiter. | |
| 3939 | + if ( context ) { | |
| 3940 | + key = context + this.options.contextDelimiter + singular; | |
| 3941 | + } | |
| 3942 | + | |
| 3943 | + entry = this.data[ domain ][ key ]; | |
| 3944 | + | |
| 3945 | + // Verify not only that entry exists, but that the intended index is within | |
| 3946 | + // range and non-empty. | |
| 3947 | + if ( entry && entry[ index ] ) { | |
| 3948 | + return entry[ index ]; | |
| 3949 | + } | |
| 3950 | + | |
| 3951 | + if ( this.options.onMissingKey ) { | |
| 3952 | + this.options.onMissingKey( singular, domain ); | |
| 3953 | + } | |
| 3954 | + | |
| 3955 | + // If entry not found, fall back to singular vs. plural with zero index | |
| 3956 | + // representing the singular value. | |
| 3957 | + return index === 0 ? singular : plural; | |
| 3958 | +}; | |
| 3959 | + | |
| 3960 | +module.exports = Tannin; | |
| 3961 | + | |
| 3962 | +},{"@tannin/plural-forms":19}]},{},[2]); | |