(input)
| 2363 | } |
| 2364 | } |
| 2365 | function initializeColorMask(input) { |
| 2366 | var computedStyle = (input.ownerDocument.defaultView || window).getComputedStyle(input, null); |
| 2367 | function findCaretPos(clientx) { |
| 2368 | var e = document.createElement("span"), caretPos; |
| 2369 | for (var style in computedStyle) { |
| 2370 | if (isNaN(style) && style.indexOf("font") !== -1) { |
| 2371 | e.style[style] = computedStyle[style]; |
| 2372 | } |
| 2373 | } |
| 2374 | e.style.textTransform = computedStyle.textTransform; |
| 2375 | e.style.letterSpacing = computedStyle.letterSpacing; |
| 2376 | e.style.position = "absolute"; |
| 2377 | e.style.height = "auto"; |
| 2378 | e.style.width = "auto"; |
| 2379 | e.style.visibility = "hidden"; |
| 2380 | e.style.whiteSpace = "nowrap"; |
| 2381 | document.body.appendChild(e); |
| 2382 | var inputText = input.inputmask._valueGet(), previousWidth = 0, itl; |
| 2383 | for (caretPos = 0, itl = inputText.length; caretPos <= itl; caretPos++) { |
| 2384 | e.innerHTML += inputText.charAt(caretPos) || "_"; |
| 2385 | if (e.offsetWidth >= clientx) { |
| 2386 | var offset1 = clientx - previousWidth; |
| 2387 | var offset2 = e.offsetWidth - clientx; |
| 2388 | e.innerHTML = inputText.charAt(caretPos); |
| 2389 | offset1 -= e.offsetWidth / 3; |
| 2390 | caretPos = offset1 < offset2 ? caretPos - 1 : caretPos; |
| 2391 | break; |
| 2392 | } |
| 2393 | previousWidth = e.offsetWidth; |
| 2394 | } |
| 2395 | document.body.removeChild(e); |
| 2396 | return caretPos; |
| 2397 | } |
| 2398 | var template = document.createElement("div"); |
| 2399 | template.style.width = computedStyle.width; |
| 2400 | template.style.textAlign = computedStyle.textAlign; |
| 2401 | colorMask = document.createElement("div"); |
| 2402 | input.inputmask.colorMask = colorMask; |
| 2403 | colorMask.className = "im-colormask"; |
| 2404 | input.parentNode.insertBefore(colorMask, input); |
| 2405 | input.parentNode.removeChild(input); |
| 2406 | colorMask.appendChild(input); |
| 2407 | colorMask.appendChild(template); |
| 2408 | input.style.left = template.offsetLeft + "px"; |
| 2409 | $(colorMask).on("mouseleave", function(e) { |
| 2410 | return EventHandlers.mouseleaveEvent.call(input, [ e ]); |
| 2411 | }); |
| 2412 | $(colorMask).on("mouseenter", function(e) { |
| 2413 | return EventHandlers.mouseenterEvent.call(input, [ e ]); |
| 2414 | }); |
| 2415 | $(colorMask).on("click", function(e) { |
| 2416 | caret(input, findCaretPos(e.clientX)); |
| 2417 | return EventHandlers.clickEvent.call(input, [ e ]); |
| 2418 | }); |
| 2419 | } |
| 2420 | Inputmask.prototype.positionColorMask = function(input, template) { |
| 2421 | input.style.left = template.offsetLeft + "px"; |
| 2422 | }; |
no test coverage detected