/lib/source/js/kendo.numerictextbox.js

http://luckyloot.codeplex.com · JavaScript · 867 lines · 447 code · 113 blank · 307 comment · 102 complexity · 1a15560d63daa2b08d2b7d6788d8e8e4 MD5 · raw file

  1. /*
  2. * Kendo UI Web v2012.2.710 (http://kendoui.com)
  3. * Copyright 2012 Telerik AD. All rights reserved.
  4. *
  5. * Kendo UI Web commercial licenses may be obtained at http://kendoui.com/web-license
  6. * If you do not own a commercial license, this file shall be governed by the
  7. * GNU General Public License (GPL) version 3.
  8. * For GPL requirements, please review: http://www.gnu.org/copyleft/gpl.html
  9. */
  10. (function($, undefined) {
  11. /**
  12. * @name kendo.ui.NumericTextBox.Description
  13. *
  14. * @section
  15. * <p>
  16. * The NumericTextBox widget can convert an INPUT element into a numeric, percentage or currency textbox.
  17. * The type is defined depending on the specified format. The widget renders spin buttons and with their help you can
  18. * increment/decrement the value with a predefined step. The NumericTextBox widget accepts only numeric entries.
  19. * The widget uses <em>kendo.culture.current</em> culture in order to determine number precision and other culture
  20. * specific properties.
  21. * </p>
  22. *
  23. * <h3>Getting Started</h3>
  24. *
  25. * @exampleTitle Creating a NumericTextBox from existing INPUT element
  26. * @example
  27. * <input id="textBox" />
  28. *
  29. * @exampleTitle NumericTextBox initialization
  30. * @example
  31. * $(document).ready(function(){
  32. * $("#textBox").kendoNumericTextBox();
  33. * });
  34. *
  35. * @section
  36. * <p>
  37. * When a <b>NumericTextBox</b> is initialized, it will automatically
  38. * wraps the input element with span element and will render spin
  39. * buttons.
  40. * </p>
  41. * <h3>Configuring NumericTextBox behaviors</h3>
  42. * <p>
  43. * The <b>NumericTextBox</b> provides configuration options that can be
  44. * easily set during initialization. Among the properties that can be
  45. * controlled:
  46. * </p>
  47. * <ul>
  48. * <li>Value of the <b>NumericTextBox</b></li>
  49. * <li>Minimum and/or maximum values</li>
  50. * <li>Increment step</li>
  51. * <li>Precision of the number</li>
  52. * <li>Number format (any valid number format is allowed)</li>
  53. * </ul>
  54. * <p>
  55. * To see a full list of available properties and values, review the
  56. * Slider Configuration API documentation tab.
  57. * </p>
  58. * @exampleTitle Customizing NumericTextBox defaults
  59. * @example
  60. * $("#textbox").kendoNumericTextBox({
  61. * value: 10,
  62. * min: -10,
  63. * max: 100,
  64. * step: 0.75,
  65. * format: "n",
  66. * decimals: 3
  67. * });
  68. * @section
  69. * @exampleTitle Create Currency NumericTextBox widget
  70. * @example
  71. * $("#textbox").kendoNumericTextBox({
  72. * format: "c2" //Define currency type and 2 digits precision
  73. * });
  74. * @section
  75. * @exampleTitle Create Percentage NumericTextBox widget
  76. * @example
  77. * $("#textbox").kendoNumericTextBox({
  78. * format: "p",
  79. * value: 0.15 // 15 %
  80. * });
  81. *
  82. * @section
  83. * <h3>Accessing an Existing NumericTextBox</h3>
  84. * <p>
  85. * You can reference an existing <b>NumericTextBox</b> instance via
  86. * <a href="http://api.jquery.com/jQuery.data/">jQuery.data()</a>.
  87. * Once a reference has been established, you can use the API to control
  88. * its behavior.
  89. * </p>
  90. *
  91. * @exampleTitle Accessing an existing NumericTextBox instance
  92. * @example
  93. * var numericTextBox = $("#numericTextBox").data("kendoNumericTextBox");
  94. *
  95. */
  96. var kendo = window.kendo,
  97. keys = kendo.keys,
  98. ui = kendo.ui,
  99. Widget = ui.Widget,
  100. parse = kendo.parseFloat,
  101. placeholderSupported = kendo.support.placeholder,
  102. touch = kendo.support.touch,
  103. getCulture = kendo.getCulture,
  104. CHANGE = "change",
  105. DISABLED = "disabled",
  106. INPUT = "k-input",
  107. SPIN = "spin",
  108. TOUCHEND = "touchend",
  109. MOUSEDOWN = touch ? "touchstart" : "mousedown",
  110. MOUSEUP = touch ? "touchmove " + TOUCHEND : "mouseup mouseleave",
  111. DEFAULT = "k-state-default",
  112. FOCUSED = "k-state-focused",
  113. HOVER = "k-state-hover",
  114. HOVEREVENTS = "mouseenter mouseleave",
  115. POINT = ".",
  116. SELECTED = "k-state-selected",
  117. STATEDISABLED = "k-state-disabled",
  118. TYPE = touch ? "number" : "text",
  119. NULL = null,
  120. proxy = $.proxy,
  121. decimals = {
  122. 190 : ".",
  123. 188 : ","
  124. };
  125. var NumericTextBox = Widget.extend(/** @lends kendo.ui.NumericTextBox.prototype */{
  126. /**
  127. * @constructs
  128. * @extends kendo.ui.Widget
  129. * @param {Element} element DOM element
  130. * @param {Object} options Configuration options
  131. * @option {Number} [value] <null> Specifies the value of the NumericTextBox widget.
  132. * _example
  133. * // specify in the HTML
  134. * <input id="numeric" value="10" type="number" min="-100" max="100" step="10"/>
  135. *
  136. * // specify on widget initialization
  137. * $("#numeric").kendoNumericTextBox({
  138. * min: 0,
  139. * max: 100,
  140. * value: 50
  141. * });
  142. * @option {Number} [min] <null> Specifies the smallest value the user can enter.
  143. * _example
  144. * // specify in the HTML
  145. * <input id="numeric" value="10" type="number" min="-100" max="100" step="10"/>
  146. * <br />
  147. * // specify on widget initialization
  148. * $("#numeric").kendoNumericTextBox({
  149. * min: 0,
  150. * max: 100,
  151. * value: 50
  152. * });
  153. * @option {Number} [max] <null> Specifies the largest value the user can enter.
  154. * _example
  155. * // specify in the HTML
  156. * <input id="numeric" value="10" type="number" min="-100" max="100" step="10"/>
  157. * <br />
  158. * // specify on widget initialization
  159. * $("#numeric").kendoNumericTextBox({
  160. * min: 0,
  161. * max: 100,
  162. * value: 50
  163. * });
  164. * @option {Number} [decimals] <null> Specifies the number precision. If not set precision defined by current culture is used.
  165. * _example
  166. * // specify on widget initialization
  167. * $("#numeric").kendoNumericTextBox({
  168. * min: 0,
  169. * max: 1,
  170. * step: 0.1,
  171. * decimals: 1
  172. * });
  173. * @option {Number} [step] <1> Specifies the increment/decrement step.
  174. * _example
  175. * // specify in the HTML
  176. * <input id="numeric" value="10" type="number" />
  177. * <br />
  178. * // specify on widget initialization
  179. * $("#numeric").kendoNumericTextBox({
  180. * min: 0,
  181. * max: 1,
  182. * step: 0.1
  183. * });
  184. * @option {String} [format] <n> Specifies the format of the number. Any valid number format is allowed.
  185. * _example
  186. * $("#numeric").kendoNumericTextBox({
  187. * format: "p0", // format as percentage with % sign
  188. * min: 0,
  189. * max: 1,
  190. * step: 0.01
  191. * });
  192. * @option {String} [placeholder] <""> Specifies the text displayed when the input is empty.
  193. * _example
  194. * // specify on widget initialization
  195. * $("#numeric").kendoNumericTextBox({
  196. * min: 0,
  197. * max: 100,
  198. * value: 50,
  199. * placeholder: "Select A Value"
  200. * });
  201. * @option {String} [upArrowText] <Increase value> Specifies the text of the tooltip on the up arrow.
  202. * _example
  203. * // specify on widget initialization
  204. * $("#numeric").kendoNumericTextBox({
  205. * min: 0,
  206. * max: 100,
  207. * value: 50,
  208. * upArrowText: "More",
  209. * downArrowText: "Less"
  210. * });
  211. * @option {String} [downArrowText] <Decrease value> Specifies the text of the tooltip on the down arrow.
  212. * _example
  213. * // specify on widget initialization
  214. * $("#numeric").kendoNumericTextBox({
  215. * min: 0,
  216. * max: 100,
  217. * value: 50,
  218. * upArrowText: "More",
  219. * downArrowText: "Less"
  220. * });
  221. * @option {String} [culture] <en-US> Specifies the culture info used by the NumericTextBox widget.
  222. * _example
  223. *
  224. * // specify on widget initialization
  225. * $("#numeric").kendoNumericTextBox({
  226. * culture: "de-DE"
  227. * });
  228. */
  229. init: function(element, options) {
  230. var that = this,
  231. isStep = options && options.step !== undefined,
  232. min, max, step, value, format;
  233. Widget.fn.init.call(that, element, options);
  234. options = that.options;
  235. element = that.element.addClass(INPUT)
  236. .bind({
  237. keydown: proxy(that._keydown, that),
  238. paste: proxy(that._paste, that),
  239. blur: proxy(that._focusout, that)
  240. });
  241. element.closest("form")
  242. .bind("reset", function() {
  243. setTimeout(function() {
  244. that.value(element[0].value);
  245. });
  246. });
  247. options.placeholder = options.placeholder || element.attr("placeholder");
  248. that._wrapper();
  249. that._arrows();
  250. that._input();
  251. that._text.focus(proxy(that._click, that));
  252. min = that.min(element.attr("min"));
  253. max = that.max(element.attr("max"));
  254. step = that._parse(element.attr("step"));
  255. if (options.min === NULL && min !== NULL) {
  256. options.min = min;
  257. }
  258. if (options.max === NULL && max !== NULL) {
  259. options.max = max;
  260. }
  261. if (!isStep && step !== NULL) {
  262. options.step = step;
  263. }
  264. format = options.format;
  265. if (format.slice(0,3) === "{0:") {
  266. options.format = format.slice(3, format.length - 1);
  267. }
  268. value = options.value;
  269. that.value(value !== NULL ? value : element.val());
  270. that.enable(!element.is('[disabled]'));
  271. kendo.notify(that);
  272. },
  273. options: {
  274. name: "NumericTextBox",
  275. decimals: NULL,
  276. min: NULL,
  277. max: NULL,
  278. value: NULL,
  279. step: 1,
  280. culture: "",
  281. format: "n",
  282. spinners: true,
  283. placeholder: "",
  284. upArrowText: "Increase value",
  285. downArrowText: "Decrease value"
  286. },
  287. events: [
  288. /**
  289. * Fires when the value is changed
  290. * @name kendo.ui.NumericTextBox#change
  291. * @event
  292. * @param {Event} e
  293. * @example
  294. * $("#numeric").kendoNumericTextBox({
  295. * change: function(e) {
  296. * // handle event
  297. * }
  298. * });
  299. * @exampleTitle To set after initialization
  300. * @example
  301. * // get a reference to the numeric textbox widget
  302. * var numeric = $("#numeric").data("kendoNumericTextBox");
  303. * // bind to the change event
  304. * numeric.bind("change", function(e) {
  305. * // handle event
  306. * });
  307. */
  308. CHANGE,
  309. /**
  310. * Fires when the value is changed from the spin buttons
  311. * @name kendo.ui.NumericTextBox#spin
  312. * @event
  313. * @param {Event} e
  314. * @example
  315. * $("#numeric").kendoNumericTextBox({
  316. * spin: function(e) {
  317. * // handle event
  318. * }
  319. * });
  320. * @exampleTitle To set after initialization
  321. * @example
  322. * // get a reference to the numeric textbox widget
  323. * var numeric = $("#numeric").data("kendoNumericTextBox");
  324. * // bind to the spin event
  325. * numeric.bind("spin", function(e) {
  326. * // handle event
  327. * });
  328. */
  329. SPIN
  330. ],
  331. /**
  332. * Enable/Disable the numerictextbox widget.
  333. * @param {Boolean} enable The argument, which defines whether to enable/disable tha numerictextbox.
  334. * @example
  335. * // get a reference to the numeric textbox
  336. * var textbox = $("#textbox").data("kendoNumericTextBox");
  337. *
  338. * // disables the numerictextbox
  339. * numerictextbox.enable(false);
  340. *
  341. * // enables the numerictextbox
  342. * numerictextbox.enable(true);
  343. */
  344. enable: function(enable) {
  345. var that = this,
  346. text = that._text.add(that.element),
  347. wrapper = that._inputWrapper.unbind(HOVEREVENTS),
  348. upArrow = that._upArrow.unbind(MOUSEDOWN),
  349. downArrow = that._downArrow.unbind(MOUSEDOWN);
  350. that._toggleText(true);
  351. if (enable === false) {
  352. wrapper
  353. .removeClass(DEFAULT)
  354. .addClass(STATEDISABLED);
  355. text.attr(DISABLED, DISABLED);
  356. } else {
  357. wrapper
  358. .addClass(DEFAULT)
  359. .removeClass(STATEDISABLED)
  360. .bind(HOVEREVENTS, that._toggleHover);
  361. text.removeAttr(DISABLED);
  362. upArrow.bind(MOUSEDOWN, function(e) {
  363. e.preventDefault();
  364. that._spin(1);
  365. that._upArrow.addClass(SELECTED);
  366. });
  367. downArrow.bind(MOUSEDOWN, function(e) {
  368. e.preventDefault();
  369. that._spin(-1);
  370. that._downArrow.addClass(SELECTED);
  371. });
  372. }
  373. },
  374. /**
  375. * Gets/Sets the min value of the NumericTextBox.
  376. * @param {Number | String} value The min value to set.
  377. * @returns {Number} The min value of the NumericTextBox.
  378. * @example
  379. * // get a reference to the NumericTextBox widget
  380. * var numerictextbox = $("#numerictextbox").data("kendoNumericTextBox");
  381. *
  382. * // get the min value of the numerictextbox.
  383. * var min = numerictextbox.min();
  384. *
  385. * // set the min value of the numerictextbox.
  386. * numerictextbox.min(-10);
  387. */
  388. min: function(value) {
  389. return this._option("min", value);
  390. },
  391. /**
  392. * Gets/Sets the max value of the NumericTextBox.
  393. * @param {Number | String} value The max value to set.
  394. * @returns {Number} The max value of the NumericTextBox.
  395. * @example
  396. * // get a reference to the NumericTextBox widget
  397. * var numerictextbox = $("#numerictextbox").data("kendoNumericTextBox");
  398. *
  399. * // get the max value of the numerictextbox.
  400. * var max = numerictextbox.max();
  401. *
  402. * // set the max value of the numerictextbox.
  403. * numerictextbox.max(10);
  404. */
  405. max: function(value) {
  406. return this._option("max", value);
  407. },
  408. /**
  409. * Gets/Sets the step value of the NumericTextBox.
  410. * @param {Number | String} value The step value to set.
  411. * @returns {Number} The step value of the NumericTextBox.
  412. * @example
  413. * // get a reference to the NumericTextBox widget
  414. * var numerictextbox = $("#numerictextbox").data("kendoNumericTextBox");
  415. *
  416. * // get the step value of the numerictextbox.
  417. * var step = numerictextbox.step();
  418. *
  419. * // set the step value of the numerictextbox.
  420. * numerictextbox.step(0.1);
  421. */
  422. step: function(value) {
  423. return this._option("step", value);
  424. },
  425. /**
  426. * Gets/Sets the value of the numerictextbox.
  427. * @param {Number | String} value The value to set.
  428. * @returns {Number} The value of the numerictextbox.
  429. * @example
  430. * // get a referene to the numeric textbox
  431. * var numerictextbox = $("#textbox").data("kendoNumericTextBox");
  432. *
  433. * // get the value of the numerictextbox.
  434. * var value = numerictextbox.value();
  435. *
  436. * // set the value of the numerictextbox.
  437. * numerictextbox.value("10.20");
  438. */
  439. value: function(value) {
  440. var that = this, adjusted;
  441. if (value === undefined) {
  442. return that._value;
  443. }
  444. value = that._parse(value);
  445. adjusted = that._adjust(value);
  446. if (value !== adjusted) {
  447. return;
  448. }
  449. that._update(value);
  450. that._old = that._value;
  451. },
  452. _adjust: function(value) {
  453. var that = this,
  454. options = that.options,
  455. min = options.min,
  456. max = options.max;
  457. if (value === NULL) {
  458. return value;
  459. }
  460. if (min !== NULL && value < min) {
  461. value = min;
  462. } else if (max !== NULL && value > max) {
  463. value = max;
  464. }
  465. return value;
  466. },
  467. _arrows: function() {
  468. var that = this,
  469. arrows,
  470. options = that.options,
  471. spinners = options.spinners,
  472. element = that.element;
  473. arrows = element.siblings(".k-icon");
  474. if (!arrows[0]) {
  475. arrows = $(buttonHtml("n", options.upArrowText) + buttonHtml("s", options.downArrowText))
  476. .insertAfter(element);
  477. arrows.wrapAll('<span class="k-select"/>');
  478. }
  479. arrows.bind(MOUSEUP, function(e) {
  480. if (!touch || kendo.eventTarget(e) != e.currentTarget || e.type === TOUCHEND) {
  481. clearTimeout( that._spinning );
  482. }
  483. arrows.removeClass(SELECTED);
  484. });
  485. if (!spinners) {
  486. arrows.toggle(spinners);
  487. that._inputWrapper.addClass("k-expand-padding");
  488. }
  489. that._upArrow = arrows.eq(0);
  490. that._downArrow = arrows.eq(1);
  491. },
  492. _blur: function() {
  493. var that = this;
  494. that._toggleText(true);
  495. that._change(that.element.val());
  496. },
  497. _click: function(e) {
  498. var that = this;
  499. clearTimeout(that._focusing);
  500. that._focusing = setTimeout(function() {
  501. var input = e.target,
  502. idx = caret(input),
  503. value = input.value.substring(0, idx),
  504. format = that._format(that.options.format),
  505. group = format[","],
  506. groupRegExp = new RegExp("\\" + group, "g"),
  507. extractRegExp = new RegExp("([\\d\\" + group + "]+)(\\" + format[POINT] + ")?(\\d+)?"),
  508. result = extractRegExp.exec(value),
  509. caretPosition = 0;
  510. if (result) {
  511. caretPosition = result[0].replace(groupRegExp, "").length;
  512. if (value.indexOf("(") != -1 && that._value < 0) {
  513. caretPosition++;
  514. }
  515. }
  516. that._focusin();
  517. caret(that.element[0], caretPosition);
  518. });
  519. },
  520. _change: function(value) {
  521. var that = this;
  522. that._update(value);
  523. value = that._value;
  524. if (that._old != value) {
  525. that._old = value;
  526. that.trigger(CHANGE);
  527. // trigger the DOM change event so any subscriber gets notified
  528. that.element.trigger(CHANGE);
  529. }
  530. },
  531. _culture: function(culture) {
  532. return culture || getCulture(this.options.culture);
  533. },
  534. _focusin: function() {
  535. var that = this;
  536. that._toggleText(false);
  537. that.element.focus();
  538. that._inputWrapper.addClass(FOCUSED);
  539. },
  540. _focusout: function() {
  541. var that = this;
  542. clearTimeout(that._focusing);
  543. that._inputWrapper.removeClass(FOCUSED);
  544. that._blur();
  545. },
  546. _format: function(format, culture) {
  547. var numberFormat = this._culture(culture).numberFormat;
  548. format = format.toLowerCase();
  549. if (format.indexOf("c") > -1) {
  550. numberFormat = numberFormat.currency;
  551. } else if (format.indexOf("p") > -1) {
  552. numberFormat = numberFormat.percent;
  553. }
  554. return numberFormat;
  555. },
  556. _input: function() {
  557. var that = this,
  558. CLASSNAME = "k-formatted-value",
  559. element = that.element.show()[0],
  560. wrapper = that.wrapper,
  561. text;
  562. text = wrapper.find(POINT + CLASSNAME);
  563. if (!text[0]) {
  564. text = $("<input />").insertBefore(element).addClass(CLASSNAME);
  565. }
  566. element.type = TYPE;
  567. text[0].type = "text";
  568. text[0].style.cssText = element.style.cssText;
  569. text.attr("placeholder", that.options.placeholder);
  570. that._text = text.attr("readonly", true)
  571. .addClass(element.className);
  572. },
  573. _keydown: function(e) {
  574. var that = this,
  575. key = e.keyCode;
  576. if (key == keys.DOWN) {
  577. that._step(-1);
  578. } else if (key == keys.UP) {
  579. that._step(1);
  580. } else if (key == keys.ENTER) {
  581. that._change(that.element.val());
  582. }
  583. if (that._prevent(key) && !e.ctrlKey) {
  584. e.preventDefault();
  585. }
  586. },
  587. _paste: function(e) {
  588. var that = this,
  589. element = e.target,
  590. value = element.value;
  591. setTimeout(function() {
  592. if (that._parse(element.value) === NULL) {
  593. that._update(value);
  594. }
  595. });
  596. },
  597. _prevent: function(key) {
  598. var that = this,
  599. element = that.element[0],
  600. value = element.value,
  601. options = that.options,
  602. min = options.min,
  603. numberFormat = that._format(options.format),
  604. separator = numberFormat[POINT],
  605. precision = options.decimals,
  606. idx = caret(element),
  607. prevent = true,
  608. end;
  609. if (precision === NULL) {
  610. precision = numberFormat.decimals;
  611. }
  612. if ((key > 16 && key < 21) ||
  613. (key > 32 && key < 37) ||
  614. (key > 47 && key < 58) ||
  615. (key > 95 && key < 106) ||
  616. key == keys.INSERT ||
  617. key == keys.DELETE ||
  618. key == keys.LEFT ||
  619. key == keys.RIGHT ||
  620. key == keys.TAB ||
  621. key == keys.BACKSPACE ||
  622. key == keys.ENTER) {
  623. prevent = false;
  624. } else if (decimals[key] === separator && precision > 0 && value.indexOf(separator) == -1) {
  625. prevent = false;
  626. } else if ((min === NULL || min < 0) && value.indexOf("-") == -1 && (key == 189 || key == 109) && idx === 0) { //sign
  627. prevent = false;
  628. } else if (key == 110 && precision > 0 && value.indexOf(separator) == -1) {
  629. end = value.substring(idx);
  630. element.value = value.substring(0, idx) + separator + end;
  631. }
  632. return prevent;
  633. },
  634. _option: function(option, value) {
  635. var that = this,
  636. options = that.options;
  637. if (value === undefined) {
  638. return options[option];
  639. }
  640. value = that._parse(value);
  641. if (!value && option === "step") {
  642. return;
  643. }
  644. options[option] = that._parse(value);
  645. },
  646. _spin: function(step, timeout) {
  647. var that = this;
  648. timeout = timeout || 500;
  649. clearTimeout( that._spinning );
  650. that._spinning = setTimeout(function() {
  651. that._spin(step, 50);
  652. }, timeout );
  653. that._step(step);
  654. },
  655. _step: function(step) {
  656. var that = this,
  657. element = that.element,
  658. value = that._parse(element.val()) || 0;
  659. if (document.activeElement != element[0]) {
  660. that._focusin();
  661. }
  662. value += that.options.step * step;
  663. that._update(that._adjust(value));
  664. that.trigger(SPIN);
  665. },
  666. _toggleHover: function(e) {
  667. if (!touch) {
  668. $(e.currentTarget).toggleClass(HOVER, e.type === "mouseenter");
  669. }
  670. },
  671. _toggleText: function(toggle) {
  672. var that = this;
  673. toggle = !!toggle;
  674. that._text.toggle(toggle);
  675. that.element.toggle(!toggle);
  676. },
  677. _parse: function(value, culture) {
  678. return parse(value, this._culture(culture), this.options.format);
  679. },
  680. _update: function(value) {
  681. var that = this,
  682. options = that.options,
  683. format = options.format,
  684. decimals = options.decimals,
  685. culture = that._culture(),
  686. numberFormat = that._format(format, culture),
  687. isNotNull;
  688. if (decimals === NULL) {
  689. decimals = numberFormat.decimals;
  690. }
  691. value = that._parse(value, culture);
  692. isNotNull = value !== NULL;
  693. if (isNotNull) {
  694. value = parseFloat(value.toFixed(decimals));
  695. }
  696. that._value = value = that._adjust(value);
  697. that._placeholder(kendo.toString(value, format, culture));
  698. that.element.val(isNotNull ? value.toString().replace(POINT, numberFormat[POINT]) : "");
  699. },
  700. _placeholder: function(value) {
  701. this._text.val(value);
  702. if (!placeholderSupported && !value) {
  703. this._text.val(this.options.placeholder);
  704. }
  705. },
  706. _wrapper: function() {
  707. var that = this,
  708. element = that.element,
  709. wrapper;
  710. wrapper = element.parents(".k-numerictextbox");
  711. if (!wrapper.is("span.k-numerictextbox")) {
  712. wrapper = element.hide().wrap('<span class="k-numeric-wrap k-state-default" />').parent();
  713. wrapper = wrapper.wrap("<span/>").parent();
  714. }
  715. wrapper[0].style.cssText = element[0].style.cssText;
  716. element[0].style.width = "";
  717. that.wrapper = wrapper.addClass("k-widget k-numerictextbox").show();
  718. that._inputWrapper = $(wrapper[0].firstChild);
  719. }
  720. });
  721. function buttonHtml(className, text) {
  722. return '<span unselectable="on" class="k-link"><span unselectable="on" class="k-icon k-i-arrow-' + className + '" title="' + text + '">' + text + '</span></span>';
  723. }
  724. function caret(element, position) {
  725. var range,
  726. isPosition = position !== undefined;
  727. if (document.selection) {
  728. if ($(element).is(":visible")) {
  729. element.focus();
  730. }
  731. range = document.selection.createRange();
  732. if (isPosition) {
  733. range.move("character", position);
  734. range.select();
  735. } else {
  736. var rangeElement = element.createTextRange(),
  737. rangeDuplicated = rangeElement.duplicate();
  738. rangeElement.moveToBookmark(range.getBookmark());
  739. rangeDuplicated.setEndPoint('EndToStart', rangeElement);
  740. position = rangeDuplicated.text.length;
  741. }
  742. } else if (element.selectionStart !== undefined) {
  743. if (isPosition) {
  744. element.focus();
  745. element.setSelectionRange(position, position);
  746. } else {
  747. position = element.selectionStart;
  748. }
  749. }
  750. return position;
  751. }
  752. ui.plugin(NumericTextBox);
  753. })(jQuery);
  754. ;