jquery - Why do I have a JavaScript parser error with this mask code? -
i have javascript parser plug-in in visual studios 2012 , throwing error @ line 30 of code, closing curly brace $.mask piece mr. bush:
/* masked input plugin jquery copyright (c) 2007-2013 josh bush (digitalbush.com) licensed under mit license (http://digitalbush.com/projects/masked-input-plugin/#license) version: 1.3.1 */ (function($) { function getpasteevent() { var el = document.createelement('input'), name = 'onpaste'; el.setattribute(name, ''); return (typeof el[name] === 'function') ? 'paste': 'input'; } var pasteeventname = getpasteevent() + ".mask", ua = navigator.useragent, iphone = /iphone/i.test(ua), android = /android/i.test(ua), carettimeoutid; $.mask = { //predefined character definitions definitions: { '9': "[0-9]", 'a': "[a-za-z]", '*': "[a-za-z0-9]" }, dataname: "rawmaskfn", placeholder: '_', }; $.fn.extend({ //helper function caret positioning caret: function(begin, end) { var range; if (this.length === 0 || this.is(":hidden")) { return; } if (typeof begin == 'number') { end = (typeof end === 'number') ? end: begin; return this.each(function() { if (this.setselectionrange) { this.setselectionrange(begin, end); } else if (this.createtextrange) { range = this.createtextrange(); range.collapse(true); range.moveend('character', end); range.movestart('character', begin); range.select(); } }); } else { if (this[0].setselectionrange) { begin = this[0].selectionstart; end = this[0].selectionend; } else if (document.selection && document.selection.createrange) { range = document.selection.createrange(); begin = 0 - range.duplicate().movestart('character', -100000); end = begin + range.text.length; } return { begin: begin, end: end }; } }, unmask: function() { return this.trigger("unmask"); }, mask: function(mask, settings) { var input, defs, tests, partialposition, firstnonmaskpos, len; if (!mask && this.length > 0) { input = $(this[0]); return input.data($.mask.dataname)(); } settings = $.extend({ placeholder: $.mask.placeholder, // load default placeholder completed: null }, settings); defs = $.mask.definitions; tests = []; partialposition = len = mask.length; firstnonmaskpos = null; $.each(mask.split(""), function(i, c) { if (c == '?') { len--; partialposition = i; } else if (defs[c]) { tests.push(new regexp(defs[c])); if (firstnonmaskpos === null) { firstnonmaskpos = tests.length - 1; } } else { tests.push(null); } }); return this.trigger("unmask").each(function() { var input = $(this), buffer = $.map(mask.split(""), function(c, i) { if (c != '?') { return defs[c] ? settings.placeholder: c; } }), focustext = input.val(); function seeknext(pos) { while (++pos < len && !tests[pos]); return pos; } function seekprev(pos) { while (--pos >= 0 && !tests[pos]); return pos; } function shiftl(begin, end) { var i, j; if (begin < 0) { return; } (i = begin, j = seeknext(end); < len; i++) { if (tests[i]) { if (j < len && tests[i].test(buffer[j])) { buffer[i] = buffer[j]; buffer[j] = settings.placeholder; } else { break; } j = seeknext(j); } } writebuffer(); input.caret(math.max(firstnonmaskpos, begin)); } function shiftr(pos) { var i, c, j, t; (i = pos, c = settings.placeholder; < len; i++) { if (tests[i]) { j = seeknext(i); t = buffer[i]; buffer[i] = c; if (j < len && tests[j].test(t)) { c = t; } else { break; } } } } function keydownevent(e) { var k = e.which, pos, begin, end; //backspace, delete, , escape special treatment if (k === 8 || k === 46 || (iphone && k === 127)) { pos = input.caret(); begin = pos.begin; end = pos.end; if (end - begin === 0) { begin = k !== 46 ? seekprev(begin) : (end = seeknext(begin - 1)); end = k === 46 ? seeknext(end) : end; } clearbuffer(begin, end); shiftl(begin, end - 1); e.preventdefault(); } else if (k == 27) { //escape input.val(focustext); input.caret(0, checkval()); e.preventdefault(); } } function keypressevent(e) { var k = e.which, pos = input.caret(), p, c, next; if (e.ctrlkey || e.altkey || e.metakey || k < 32) { //ignore return; } else if (k) { if (pos.end - pos.begin !== 0) { clearbuffer(pos.begin, pos.end); shiftl(pos.begin, pos.end - 1); } p = seeknext(pos.begin - 1); if (p < len) { c = string.fromcharcode(k); if (tests[p].test(c)) { shiftr(p); buffer[p] = c; writebuffer(); next = seeknext(p); if (android) { settimeout($.proxy($.fn.caret, input, next), 0); } else { input.caret(next); } if (settings.completed && next >= len) { settings.completed.call(input); } } } e.preventdefault(); } } function clearbuffer(start, end) { var i; (i = start; < end && < len; i++) { if (tests[i]) { buffer[i] = settings.placeholder; } } } function writebuffer() { input.val(buffer.join('')); } function checkval(allow) { //try place characters belong var test = input.val(), lastmatch = -1, i, c; (i = 0, pos = 0; < len; i++) { if (tests[i]) { buffer[i] = settings.placeholder; while (pos++<test.length) { c = test.charat(pos - 1); if (tests[i].test(c)) { buffer[i] = c; lastmatch = i; break; } } if (pos > test.length) { break; } } else if (buffer[i] === test.charat(pos) && !== partialposition) { pos++; lastmatch = i; } } if (allow) { writebuffer(); } else if (lastmatch + 1 < partialposition) { input.val(""); clearbuffer(0, len); } else { writebuffer(); input.val(input.val().substring(0, lastmatch + 1)); } return (partialposition ? i: firstnonmaskpos); } input.data($.mask.dataname, function() { return $.map(buffer, function(c, i) { return tests[i] && c != settings.placeholder ? c: null; }).join(''); }); if (!input.attr("readonly")) input.one("unmask", function() { input.unbind(".mask").removedata($.mask.dataname); }).bind("focus.mask", function() { cleartimeout(carettimeoutid); var pos, movecaret; focustext = input.val(); pos = checkval(); carettimeoutid = settimeout(function() { writebuffer(); if (pos == mask.length) { input.caret(0, pos); } else { input.caret(pos); } }, 10); }).bind("blur.mask", function() { checkval(); if (input.val() != focustext) input.change(); }).bind("keydown.mask", keydownevent).bind("keypress.mask", keypressevent).bind(pasteeventname, function() { settimeout(function() { var pos = checkval(true); input.caret(pos); if (settings.completed && pos == input.val().length) settings.completed.call(input); }, 0); }); checkval(); //perform initial check existing values }); } }); })(jquery);
i'm still pretty new js , jquery, can tell me why? arrived here while investigating why mask code causing errors in ie8.
again, parser doesn't closing curly of block:
$.mask = { //predefined character definitions definitions: { '9': "[0-9]", 'a': "[a-za-z]", '*': "[a-za-z0-9]" }, dataname: "rawmaskfn", placeholder: '_', };
any appreciated!
maybe because of additional comma after placeholder: ...
line?
Comments
Post a Comment