1 (function ($) { 2 // ÑзнаÑÑ Ð¿Ð¾Ð·Ð¸ÑÐ¸Ñ ÐºÑÑÑоÑа 3 $.fn.getCursorPosition = function () { 4 var input = this.get(0); 5 if (!input) return; 6 if ('selectionStart' in input) { 7 return input.selectionStart; 8 } else if (document.selection) { 9 input.focus(); 10 var sel = document.selection.createRange(); 11 var selLen = document.selection.createRange().text.length; 12 sel.moveStart('character', -input.value.length); 13 return sel.text.length - selLen; 14 } 15 } 16 // ÑÑÑановиÑÑ Ð¿Ð¾Ð·Ð¸ÑÐ¸Ñ ÐºÑÑÑоÑа 17 $.fn.setCursorPosition = function (pos) { 18 if ($(this).get(0).setSelectionRange) { 19 $(this).get(0).setSelectionRange(pos, pos); 20 } else if ($(this).get(0).createTextRange) { 21 var range = $(this).get(0).createTextRange(); 22 range.collapse(true); 23 range.moveEnd('character', pos); 24 range.moveStart('character', pos); 25 range.select(); 26 } 27 } 28 // ÑдалиÑÑ Ð²ÑделеннÑй ÑекÑÑ 29 $.fn.delSelected = function () { 30 var input = $(this); 31 var value = input.val(); 32 var start = input[0].selectionStart; 33 var end = input[0].selectionEnd; 34 input.val( 35 value.substr(0, start) + value.substring(end, value.length) 36 ); 37 return end - start; 38 }; 39 40 $.fn.priceFormat = function () { 41 42 function priceFormatted(element) { 43 element = String(element).replace(/[^\d]/g, ''); 44 if(!element) return ''; 45 return (String(parseInt(element))).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 '); 46 } 47 48 $(this) 49 // ÐÑмена пеÑеÑаÑÐºÐ¸Ð²Ð°Ð½Ð¸Ñ ÑекÑÑа и вÑÑавки ÑеÑез конÑекÑÑное Ð¼ÐµÐ½Ñ 50 .bind('contextmenu', function (event) { 51 event.preventDefault(); 52 }) 53 .bind('drop', function (event) { 54 var value = $(this).val(); 55 $(this).val(''); // Ñ Ð°Ðº Ð´Ð»Ñ Ñ Ñома 56 $(this).val(value); 57 event.preventDefault(); 58 }) 59 .keydown(function (event) { 60 var cursor = $(this).getCursorPosition(); 61 var code = event.keyCode; 62 var startValue = $(this).val(); 63 if ((event.ctrlKey === true && code == 86) || // Ctrl+V | Shift+insert 64 (event.metaKey === true && code == 86) || 65 (event.shiftKey === true && code == 45)) { 66 return false; 67 } else if ( 68 code == 9 || // tab 69 code == 27 || // ecs 70 event.ctrlKey === true || // вÑе ÑÑо вмеÑÑе Ñ ctrl 71 event.metaKey === true || 72 event.altKey === true || // вÑе ÑÑо вмеÑÑе Ñ alt 73 event.shiftKey === true || // вÑе ÑÑо вмеÑÑе Ñ shift 74 (code >= 112 && code <= 123) || // F1 - F12 75 (code >= 35 && code <= 39)) // end, home, ÑÑÑелки 76 { 77 return; 78 79 } else if (code == 8) {// backspace 80 81 var delCount = $(this).delSelected(); 82 if (!delCount) { 83 if (startValue[cursor - 1] === ' ') { 84 cursor--; 85 } 86 $(this).val(startValue.substr(0, cursor - 1) + startValue.substring(cursor, startValue.length)); 87 } 88 $(this).val(priceFormatted($(this).val())); 89 $(this).setCursorPosition(cursor - (startValue.length - $(this).val().length - delCount)); 90 91 } else if (code == 46) { // delete 92 93 var delCount = $(this).delSelected(); 94 if (!delCount) { 95 if (startValue[cursor] === ' ') { 96 cursor++; 97 } 98 $(this).val(startValue.substr(0, cursor) + startValue.substring(cursor + 1, startValue.length)); 99 } 100 if (!delCount)delCount = 1; 101 $(this).val(priceFormatted($(this).val())); 102 $(this).setCursorPosition(cursor - (startValue.length - $(this).val().length - delCount)); 103 104 } else { 105 $(this).delSelected(); 106 startValue = $(this).val(); 107 var key = false;
108 // ÑиÑÑовÑе клавиÑи 109 if ((code >= 48 && code <= 57)) { 110 key = (code - 48); 111 } 112 // numpad 113 else if ((code >= 96 && code <= 105 )) { 114 key = (code - 96); 115 } else { 116 $(this).val(priceFormatted($(this).val())); 117 $(this).setCursorPosition(cursor); 118 return false; 119 } 120 var length = startValue.length 121 var value = startValue.substr(0, cursor) + key + startValue.substring(cursor, startValue.length); 122 $(this).val(priceFormatted(value)); 123 $(this).setCursorPosition(cursor + $(this).val().length - startValue.length); 124 } 125 event.preventDefault(); 126 }); 127 }; 128 })(jQuery); 129 130 $(document).ready(function () { 131 $('.money-format').priceFormat(); 132 });
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.