PageSourceSearch

https://boating.ae/assets/vendor/libs/bootstrap-maxlength/bootstrap-maxlength.js

js boating.ae collected 2026-10-01 14:25:59 UTC 24,298 bytes, 705 lines download raw bytes

1(function webpackUniversalModuleDefinition(root, factory) {
2	if(typeof exports === 'object' && typeof module === 'object')
3		module.exports = factory();
4	else if(typeof define === 'function' && define.amd)
5		define([], factory);
6	else {
7		var a = factory();
8		for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
9	}
10})(self, function() {
11return /******/ (function() { // webpackBootstrap
12/******/ 	var __webpack_modules__ = ({
13
vendor: 20,086 bytes, lines 14-620
14/***/ "./node_modules/bootstrap-maxlength/src/bootstrap-maxlength.js":
15/*!*********************************************************************!*\
16  !*** ./node_modules/bootstrap-maxlength/src/bootstrap-maxlength.js ***!
17  \*********************************************************************/
18/***/ (function() {
19
20/* ==========================================================
21 * bootstrap-maxlength.js v1.10.0
22 *
23 * Copyright (c) 2013-2021 Maurizio Napoleoni;
24 *
25 * Licensed under the terms of the MIT license.
26 * See: https://github.com/mimo84/bootstrap-maxlength/blob/master/LICENSE
27 * ========================================================== */
28/*global  jQuery*/
29
30(function ($) {
31  'use strict';
32  /**
33   * We need an event when the elements are destroyed
34   * because if an input is removed, we have to remove the
35   * maxlength object associated (if any).
36   * From:
37   * http://stackoverflow.com/questions/2200494/jquery-trigger-event-when-an-element-is-removed-from-the-dom
38   */
39  if (!$.event.special.destroyed) {
40    $.event.special.destroyed = {
41      remove: function (o) {
42        if (o.handler) {
43          o.handler();
44        }
45      }
46    };
47  }
48
49
50  $.fn.extend({
51    maxlength: function (options, callback) {
52      var documentBody = $('body'),
53        defaults = {
54          showOnReady: false, // true to always show when indicator is ready
55          alwaysShow: true, // if true the indicator it's always shown.
56          threshold: 0, // Represents how many chars left are needed to show up the counter
57          warningClass: 'small form-text text-muted',
58          limitReachedClass: 'small form-text text-danger',
59          limitExceededClass: '',
60          separator: ' / ',
61          preText: '',
62          postText: '',
63          showMaxLength: true,
64          placement: 'bottom-right-inside',
65          message: null, // an alternative way to provide the message text
66          showCharsTyped: true, // show the number of characters typed and not the number of characters remaining
67          validate: false, // if the browser doesn't support the maxlength attribute, attempt to type more than the indicated chars, will be prevented.
68          utf8: false, // counts using bytesize rather than length. eg: '£' is counted as 2 characters.
69          appendToParent: false, // append the indicator to the input field's parent instead of body
70          twoCharLinebreak: true, // count linebreak as 2 characters to match IE/Chrome textarea validation. As well as DB storage.
71          customMaxAttribute: null, // null = use maxlength attribute and browser functionality, string = use specified attribute instead.
72          customMaxClass: 'overmax', // Class to add to the input field when the maxlength is exceeded.
73          allowOverMax: false, // Form submit validation is handled on your own.  when maxlength has been exceeded 'overmax' class added to element
74          zIndex: 1099
75        };
76
77      if ($.isFunction(options) && !callback) {
78        callback = options;
79        options = {};
80      }
81      options = $.extend(defaults, options);
82
83
84      /**
85       * Return the byte count of the specified character in UTF8 encoding.
86       * Note: This won't cover UTF-8 characters that are 4 bytes long.
87       *
88       * @param input
89       * @return {number}
90       */
91      function utf8CharByteCount(character) {
92        var c = character.charCodeAt();
93        // Not c then 0, else c < 128 then 1, else c < 2048 then 2, else 3
94        return !c ? 0 : c < 128 ? 1 : c < 2048 ? 2 : 3;
95      }
96
97      /**
98       * Return the length of the specified input in UTF8 encoding.
99       *
100       * @param input
101       * @return {number}
102       */
103      function utf8Length(string) {
104        return string.split("")
105          .map(utf8CharByteCount)
106          // Prevent reduce from throwing an error if the string is empty.
107          .concat(0)
108          .reduce(function (sum, val) {
109            return sum + val;
110          });
111      }
112
113      /**
114       * Return the length of the specified input.
115       *
116       * @param input
117       * @return {number}
118       */
119      function inputLength(input) {
120        var text = input.val();
121
122        if (options.twoCharLinebreak) {
123          // Count all line breaks as 2 characters
124          text = text.replace(/\r(?!\n)|\n(?!\r)/g, '\r\n');
125        } else {
126          // Remove all double-character (\r\n) linebreaks, so they're counted only once.
127          text = text.replace(/(?:\r\n|\r|\n)/g, '\n');
128        }
129
130        var currentLength = 0;
131
132        if (options.utf8) {
133          currentLength = utf8Length(text);
134        } else {
135          currentLength = text.length;
136        }
137
138        // Remove "C:\fakepath\" from counter when using file input
139        // Fix https://github.com/mimo84/bootstrap-maxlength/issues/146
140        if (input.prop("type") === "file" && input.val() !== "") {
141          currentLength -= 12;
142        }
143
144        return currentLength;
145      }
146
147      /**
148       * Truncate the text of the specified input.
149       *
150       * @param input
151       * @param limit
152       */
153      function truncateChars(input, maxlength) {
154        var text = input.val();
155
156        if (options.twoCharLinebreak) {
157          text = text.replace(/\r(?!\n)|\n(?!\r)/g, '\r\n');
158
159          if (text[text.length - 1] === '\n') {
160            maxlength -= text.length % 2;
161          }
162        }
163
164        if (options.utf8) {
165          var indexedSize = text.split("").map(utf8CharByteCount);
166          for (
167            var removedBytes = 0,
168            bytesPastMax = utf8Length(text) - maxlength; removedBytes < bytesPastMax; removedBytes += indexedSize.pop()
169          );
170          maxlength -= (maxlength - indexedSize.length);
171        }
172
173        input.val(text.substr(0, maxlength));
174      }
175
176      /**
177       * Return true if the indicator should be showing up.
178       *
179       * @param input
180       * @param threshold
181       * @param maxlength
182       * @return {number}
183       */
184      function charsLeftThreshold(input, threshold, maxlength) {
185        var output = true;
186        if (!options.alwaysShow && (maxlength - inputLength(input) > threshold)) {
187          output = false;
188        }
189        return output;
190      }
191
192      /**
193       * Returns how many chars are left to complete the fill up of the form.
194       *
195       * @param input
196       * @param maxlength
197       * @return {number}
198       */
199      function remainingChars(input, maxlength) {
200        var length = maxlength - inputLength(input);
201        return length;
202      }
203
204      /**
205       * When called displays the indicator.
206       *
207       * @param indicator
208       */
209      function showRemaining(currentInput, indicator) {
210        indicator.css({
211          display: 'block'
212        });
213        currentInput.trigger('maxlength.shown');
214      }
215
216      /**
217       * When called shows the indicator.
218       *
219       * @param indicator
220       */
221      function hideRemaining(currentInput, indicator) {
222
223        if (options.alwaysShow) {
224          return;
225        }
226
227        indicator.css({
228          display: 'none'
229        });
230        currentInput.trigger('maxlength.hidden');
231      }
232
233      /**
234       * This function updates the value in the indicator
235       *
236       * @param maxLengthThisInput
237       * @param typedChars
238       * @return String
239       */
240      function updateMaxLengthHTML(currentInputText, maxLengthThisInput, typedChars) {
241        var output = '';
242        if (options.message) {
243          if (typeof options.message === 'function') {
244            output = options.message(currentInputText, maxLengthThisInput);
245          } else {
246            output = options.message.replace('%charsTyped%', typedChars)
247              .replace('%charsRemaining%', maxLengthThisInput - typedChars)
248              .replace('%charsTotal%', maxLengthThisInput);
249          }
250        } else {
251          if (options.preText) {
252            output += options.preText;
253          }
254          if (!options.showCharsTyped) {
255            output += maxLengthThisInput - typedChars;
256          } else {
257            output += typedChars;
258          }
259          if (options.showMaxLength) {
260            output += options.separator + maxLengthThisInput;
261          }
262          if (options.postText) {
263            output += options.postText;
264          }
265        }
266        return output;
267      }
268
269      /**
270       * This function updates the value of the counter in the indicator.
271       * Wants as parameters: the number of remaining chars, the element currently managed,
272       * the maxLength for the current input and the indicator generated for it.
273       *
274       * @param remaining
275       * @param currentInput
276       * @param maxLengthCurrentInput
277       * @param maxLengthIndicator
278       */
279      function manageRemainingVisibility(remaining, currentInput, maxLengthCurrentInput, maxLengthIndicator) {
280        if (maxLengthIndicator) {
281          maxLengthIndicator.html(updateMaxLengthHTML(currentInput.val(), maxLengthCurrentInput, (maxLengthCurrentInput - remaining)));
282
283          if (remaining > 0) {
284            if (charsLeftThreshold(currentInput, options.threshold, maxLengthCurrentInput)) {
285              showRemaining(currentInput, maxLengthIndicator.removeClass(options.limitReachedClass + ' ' + options.limitExceededClass).addClass(options.warningClass));
286            } else {
287              hideRemaining(currentInput, maxLengthIndicator);
288            }
289          } else {
290            if (!options.limitExceededClass) {
291              showRemaining(currentInput, maxLengthIndicator.removeClass(options.warningClass).addClass(options.limitReachedClass));
292            } else {
293              if (remaining === 0) {
294                showRemaining(currentInput, maxLengthIndicator.removeClass(options.warningClass + ' ' + options.limitExceededClass).addClass(options.limitReachedClass));
295              } else {
296                showRemaining(currentInput, maxLengthIndicator.removeClass(options.warningClass + ' ' + options.limitReachedClass).addClass(options.limitExceededClass));
297              }
298            }
299          }
300        }
301
302        if (options.customMaxAttribute) {
303          // class to use for form validation on custom maxlength attribute
304          if (remaining < 0) {
305            currentInput.addClass(options.customMaxClass);
306          } else {
307            currentInput.removeClass(options.customMaxClass);
308          }
309        }
310      }
311
312      /**
313       * This function returns an object containing all the
314       * informations about the position of the current input
315       *
316       * @param currentInput
317       * @return object {bottom height left right top width}
318       *
319       */
320      function getPosition(currentInput) {
321        var el = currentInput[0];
322        return $.extend({}, (typeof el.getBoundingClientRect === 'function') ? el.getBoundingClientRect() : {
323          width: el.offsetWidth,
324          height: el.offsetHeight
325        }, currentInput.offset());
326      }
327
328      /**
329       * This function places the maxLengthIndicator based on placement config object.
330       *
331       * @param {object} placement
332       * @param {$} maxLengthIndicator
333       * @return null
334       *
335       */
336      function placeWithCSS(placement, maxLengthIndicator) {
337        if (!placement || !maxLengthIndicator) {
338          return;
339        }
340
341        var POSITION_KEYS = [
342          'top',
343          'bottom',
344          'left',
345          'right',
346          'position'
347        ];
348
349        var cssPos = {};
350
351        // filter css properties to position
352        $.each(POSITION_KEYS, function (i, key) {
353          var val = options.placement[key];
354          if (typeof val !== 'undefined') {
355            cssPos[key] = val;
356          }
357        });
358
359        maxLengthIndicator.css(cssPos);
360
361        return;
362      }
363
364
365      /**
366       * This function places the maxLengthIndicator at the
367       * top / bottom / left / right of the currentInput
368       *
369       * @param currentInput
370       * @param maxLengthIndicator
371       * @return null
372       *
373       */
374      function place(currentInput, maxLengthIndicator) {
375        var pos = getPosition(currentInput);
376
377        // Supports custom placement handler
378        if ($.type(options.placement) === 'function') {
379          options.placement(currentInput, maxLengthIndicator, pos);
380          return;
381        }
382
383        // Supports custom placement via css positional properties
384        if ($.isPlainObject(options.placement)) {
385          placeWithCSS(options.placement, maxLengthIndicator);
386          return;
387        }
388
389        var inputOuter = currentInput.outerWidth(),
390          outerWidth = maxLengthIndicator.outerWidth(),
391          actualWidth = maxLengthIndicator.width(),
392          actualHeight = maxLengthIndicator.height();
393
394        // get the right position if the indicator is appended to the input's parent
395        if (options.appendToParent) {
396          pos.top -= currentInput.parent().offset().top;
397          pos.left -= currentInput.parent().offset().left;
398        }
399
400        switch (options.placement) {
401          case 'bottom':
402            maxLengthIndicator.css({
403              top: pos.top + pos.height,
404              left: pos.left + pos.width / 2 - actualWidth / 2
405            });
406            break;
407          case 'top':
408            maxLengthIndicator.css({
409              top: pos.top - actualHeight,
410              left: pos.left + pos.width / 2 - actualWidth / 2
411            });
412            break;
413          case 'left':
414            maxLengthIndicator.css({
415              top: pos.top + pos.height / 2 - actualHeight / 2,
416              left: pos.left - actualWidth
417            });
418            break;
419          case 'right':
420            maxLengthIndicator.css({
421              top: pos.top + pos.height / 2 - actualHeight / 2,
422              left: pos.left + pos.width
423            });
424            break;
425          case 'bottom-right':
426            maxLengthIndicator.css({
427              top: pos.top + pos.height,
428              left: pos.left + pos.width
429            });
430            break;
431          case 'top-right':
432            maxLengthIndicator.css({
433              top: pos.top - actualHeight,
434              left: pos.left + inputOuter
435            });
436            break;
437          case 'top-left':
438            maxLengthIndicator.css({
439              top: pos.top - actualHeight,
440              left: pos.left - outerWidth
441            });
442            break;
443          case 'bottom-left':
444            maxLengthIndicator.css({
445              top: pos.top + currentInput.outerHeight(),
446              left: pos.left - outerWidth
447            });
448            break;
449          case 'centered-right':
450            maxLengthIndicator.css({
451              top: pos.top + (actualHeight / 2),
452              left: pos.left + inputOuter - outerWidth - 3
453            });
454            break;
455
456          // Some more options for placements
457          case 'bottom-right-inside':
458            maxLengthIndicator.css({
459              top: pos.top + pos.height,
460              left: pos.left + pos.width - outerWidth
461            });
462            break;
463          case 'top-right-inside':
464            maxLengthIndicator.css({
465              top: pos.top - actualHeight,
466              left: pos.left + inputOuter - outerWidth
467            });
468            break;
469          case 'top-left-inside':
470            maxLengthIndicator.css({
471              top: pos.top - actualHeight,
472              left: pos.left
473            });
474            break;
475          case 'bottom-left-inside':
476            maxLengthIndicator.css({
477              top: pos.top + currentInput.outerHeight(),
478              left: pos.left
479            });
480            break;
481        }
482      }
483
484      /**
485       * This function returns true if the indicator position needs to
486       * be recalculated when the currentInput changes
487       *
488       * @return {boolean}
489       *
490       */
491      function isPlacementMutable() {
492        return options.placement === 'bottom-right-inside' || options.placement === 'top-right-inside' || typeof options.placement === 'function' || (options.message && typeof options.message === 'function');
493      }
494
495      /**
496       * This function retrieves the maximum length of currentInput
497       *
498       * @param currentInput
499       * @return {number}
500       *
501       */
502      function getMaxLength(currentInput) {
503        var max = currentInput.attr('maxlength') || options.customMaxAttribute;
504
505        if (options.customMaxAttribute && !options.allowOverMax) {
506          var custom = currentInput.attr(options.customMaxAttribute);
507          if (!max || custom < max) {
508            max = custom;
509          }
510        }
511
512        if (!max) {
513          max = currentInput.attr('size');
514        }
515        return max;
516      }
517
518      return this.each(function () {
519
520        var currentInput = $(this),
521          maxLengthCurrentInput,
522          maxLengthIndicator;
523
524        $(window).resize(function () {
525          if (maxLengthIndicator) {
526            place(currentInput, maxLengthIndicator);
527          }
528        });
529
530        function firstInit() {
531          var maxlengthContent = updateMaxLengthHTML(currentInput.val(), maxLengthCurrentInput, '0');
532          maxLengthCurrentInput = getMaxLength(currentInput);
533
534          if (!maxLengthIndicator) {
535            maxLengthIndicator = $('<span class="bootstrap-maxlength"></span>').css({
536              display: 'none',
537              position: 'absolute',
538              whiteSpace: 'nowrap',
539              zIndex: options.zIndex
540            }).html(maxlengthContent);
541          }
542
543          // We need to detect resizes if we are dealing with a textarea:
544          if (currentInput.is('textarea')) {
545            currentInput.data('maxlenghtsizex', currentInput.outerWidth());
546            currentInput.data('maxlenghtsizey', currentInput.outerHeight());
547
548            currentInput.mouseup(function () {
549              if (currentInput.outerWidth() !== currentInput.data('maxlenghtsizex') || currentInput.outerHeight() !== currentInput.data('maxlenghtsizey')) {
550                place(currentInput, maxLengthIndicator);
551              }
552
553              currentInput.data('maxlenghtsizex', currentInput.outerWidth());
554              currentInput.data('maxlenghtsizey', currentInput.outerHeight());
555            });
556          }
557
558          if (options.appendToParent) {
559            currentInput.parent().append(maxLengthIndicator);
560            currentInput.parent().css('position', 'relative');
561          } else {
562            documentBody.append(maxLengthIndicator);
563          }
564
565          var remaining = remainingChars(currentInput, getMaxLength(currentInput));
566          manageRemainingVisibility(remaining, currentInput, maxLengthCurrentInput, maxLengthIndicator);
567          place(currentInput, maxLengthIndicator);
568        }
569
570        if (options.showOnReady) {
571          currentInput.ready(function () {
572            firstInit();
573          });
574        } else {
575          currentInput.focus(function () {
576            firstInit();
577          });
578        }
579
580        currentInput.on('maxlength.reposition', function () {
581          place(currentInput, maxLengthIndicator);
582        });
583
584
585        currentInput.on('destroyed', function () {
586          if (maxLengthIndicator) {
587            maxLengthIndicator.remove();
588          }
589        });
590
591        currentInput.on('blur', function () {
592          if (maxLengthIndicator && !options.showOnReady) {
593            maxLengthIndicator.remove();
594          }
595        });
596
597        currentInput.on('input', function () {
598          var maxlength = getMaxLength(currentInput),
599            remaining = remainingChars(currentInput, maxlength),
600            output = true;
601
602          if (options.validate && remaining < 0) {
603            truncateChars(currentInput, maxlength);
604            output = false;
605          } else {
606            manageRemainingVisibility(remaining, currentInput, maxLengthCurrentInput, maxLengthIndicator);
607          }
608
609          // if (isPlacementMutable()) {
610          //   place(currentInput, maxLengthIndicator);
611          // }
612
613          return output;
614        });
615      });
616    }
617  });
618}(jQuery));
619
620/***/ })
vendor: 3,763 bytes, lines 620-705
620
621
622/******/ 	});
623/************************************************************************/
624/******/ 	// The module cache
625/******/ 	var __webpack_module_cache__ = {};
626/******/ 	
627/******/ 	// The require function
628/******/ 	function __webpack_require__(moduleId) {
629/******/ 		// Check if module is in cache
630/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
631/******/ 		if (cachedModule !== undefined) {
632/******/ 			return cachedModule.exports;
633/******/ 		}
634/******/ 		// Create a new module (and put it into the cache)
635/******/ 		var module = __webpack_module_cache__[moduleId] = {
636/******/ 			// no module.id needed
637/******/ 			// no module.loaded needed
638/******/ 			exports: {}
639/******/ 		};
640/******/ 	
641/******/ 		// Execute the module function
642/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
643/******/ 	
644/******/ 		// Return the exports of the module
645/******/ 		return module.exports;
646/******/ 	}
647/******/ 	
648/************************************************************************/
649/******/ 	/* webpack/runtime/compat get default export */
650/******/ 	!function() {
651/******/ 		// getDefaultExport function for compatibility with non-harmony modules
652/******/ 		__webpack_require__.n = function(module) {
653/******/ 			var getter = module && module.__esModule ?
654/******/ 				function() { return module['default']; } :
655/******/ 				function() { return module; };
656/******/ 			__webpack_require__.d(getter, { a: getter });
657/******/ 			return getter;
658/******/ 		};
659/******/ 	}();
660/******/ 	
661/******/ 	/* webpack/runtime/define property getters */
662/******/ 	!function() {
663/******/ 		// define getter functions for harmony exports
664/******/ 		__webpack_require__.d = function(exports, definition) {
665/******/ 			for(var key in definition) {
666/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
667/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
668/******/ 				}
669/******/ 			}
670/******/ 		};
671/******/ 	}();
672/******/ 	
673/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
674/******/ 	!function() {
675/******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
676/******/ 	}();
677/******/ 	
678/******/ 	/* webpack/runtime/make namespace object */
679/******/ 	!function() {
680/******/ 		// define __esModule on exports
681/******/ 		__webpack_require__.r = function(exports) {
682/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
683/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
684/******/ 			}
685/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
686/******/ 		};
687/******/ 	}();
688/******/ 	
689/************************************************************************/
690var __webpack_exports__ = {};
691// This entry need to be wrapped in an IIFE because it need to be in strict mode.
692!function() {
693"use strict";
694/*!*********************************************************************************!*\
695  !*** ./resources/assets/vendor/libs/bootstrap-maxlength/bootstrap-maxlength.js ***!
696  \*********************************************************************************/
697__webpack_require__.r(__webpack_exports__);
698/* harmony import */ var bootstrap_maxlength_src_bootstrap_maxlength__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! bootstrap-maxlength/src/bootstrap-maxlength */ "./node_modules/bootstrap-maxlength/src/bootstrap-maxlength.js");
699/* harmony import */ var bootstrap_maxlength_src_bootstrap_maxlength__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(bootstrap_maxlength_src_bootstrap_maxlength__WEBPACK_IMPORTED_MODULE_0__);
700
701}();
702/******/ 	return __webpack_exports__;
703/******/ })()
704;
705});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.