Skip to content

Mask & Timepicker - Code Review #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 118 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
cd38320
Mask: Adding some widget/unit test boilerplates
gnarf Jul 27, 2011
936193f
Mask tests: cleanup.
scottgonzalez Jul 27, 2011
5b7fa97
Unit Tests: Adding mask to all.html
gnarf Jul 27, 2011
9dacfd1
Mask: Initial draft of _caret, implementation borrowed from @digitalB…
gnarf Jul 27, 2011
deb6023
Mask: First draft of parsing the mask into a 'buffer'
gnarf Jul 29, 2011
3dd3425
Mask: First Draft - Structuring key handling methods based on the mas…
gnarf Jul 31, 2011
e30e09d
Mask: adding a _validValue helper
gnarf Jul 31, 2011
d86229d
Mask: Adding refresh method, Adding unit tests for mask/placeholder o…
gnarf Jul 31, 2011
d400395
Mask: Adding a unit test for refresh method
gnarf Jul 31, 2011
96d7949
Mask: Adding in paste/blur handlers, minor adjustments to backspace u…
gnarf Jul 31, 2011
719aae5
Mask: Adding more unit tests copied from the specs used for maskedInput
gnarf Aug 1, 2011
9d7ea79
Mask: adding a value method to get and set raw value without mask lit…
gnarf Aug 1, 2011
af2edfe
Mask: Adding a valid method which can tell if a mask has been completed
gnarf Aug 2, 2011
af9da8f
Mask: Updating regexp to include ö and å (etc), also making sure inpu…
gnarf Aug 2, 2011
a84baa5
Mask: Visual Test
gnarf Aug 2, 2011
548ccae
Mask: Adding a short delay to setting the caret position on focus
gnarf Aug 2, 2011
3ac0bb4
Mask: Handling overtyping multiple values better - rewrote shiftRight…
gnarf Aug 2, 2011
1441608
Mask: Adding the complete event
gnarf Aug 10, 2011
75ab04a
Mask: Cleaning up whitespace in tests
gnarf Aug 10, 2011
2414a94
Mask: Optional mask position with marked with a ?
gnarf Aug 10, 2011
84c16bd
Mask: Updating visual test
gnarf Aug 10, 2011
9a1bcc5
Mask: More work on multi-character fields. Reorganizing methods alpha…
gnarf Aug 10, 2011
e59b0bc
Mask: clearEmpty option
gnarf Aug 12, 2011
5eb1843
Mask: Correcting typo
gnarf Aug 12, 2011
c00071b
Mask: Fixing global leak
gnarf Aug 12, 2011
93a5fca
Mask: Renaming empty to isEmpty to match with isValid
gnarf Aug 12, 2011
9723d6f
Mask: Update to visual tests
gnarf Aug 12, 2011
926c08a
Mask: Adding the regexp for ~ to the eye script in the visual test
gnarf Aug 12, 2011
b21fc2f
Mask: playing with the handling of the multi character fields
gnarf Aug 12, 2011
f8e7a2d
Merge branch 'master' into mask
jzaefferer Sep 12, 2011
52e0daa
Mask: Refactor events method to use _bind and _delay, getting rid of …
jzaefferer Sep 12, 2011
08db455
Mask: Refactor _events method into _events property, pass to _bind on…
jzaefferer Sep 12, 2011
126f08d
Mask: Remove some unused variables and unnecessary else statements
jzaefferer Sep 13, 2011
a20b825
Mask: Adding left key event to also highlight each field in multi-cha…
gnarf Sep 14, 2011
71b5d86
Timepicker: initial boilerplate commit
gnarf Sep 14, 2011
6209642
Mask: Adding a unit test for parsing multi-character fields from input
gnarf Sep 14, 2011
889ce2b
Mask: fixing some merge conflicts
gnarf Sep 14, 2011
4bcc41c
Mask: fixing some more bugs in the key events
gnarf Sep 14, 2011
c7fce88
Timepicker: First draft of functionality
gnarf Sep 14, 2011
c1a15ff
Timepicker: removing a console.log - adding a second timepicker to th…
gnarf Sep 14, 2011
ca03a09
Mask: Using event.which instead of event.keyCode or event.charCode
gnarf Sep 14, 2011
dcf1499
Timepicker: ampm and seconds options
gnarf Sep 14, 2011
1e7b135
Timepicker: _setOption for ampm / seconds
gnarf Sep 14, 2011
9495f2a
Mask: Fixing a focus caret position issue, adding _caretSelect to sel…
gnarf Sep 14, 2011
d377234
Timepicker: checking position on clicks, using _caretSelect
gnarf Sep 14, 2011
00701c7
Mask: more fixes for focus positioning / fixing unit tests
gnarf Sep 14, 2011
97ad824
Timepicker: Changing 'pp' to 'tt' to be more compatible with the form…
gnarf Sep 14, 2011
df92f8d
Timepicker: fixing a leftover instance of 'Mask' in the comment header
gnarf Sep 15, 2011
203404c
Mask: removing the complete event
gnarf Sep 15, 2011
2184d1e
Timepicker: fixing a call to _super - bug spotted by @rxaviers
gnarf Sep 19, 2011
593b4d7
Timepicker: Now correctly stops you from entering invalid numbers
gnarf Sep 22, 2011
e2f562e
Mask: Unit tests for validating multi-byte fields
gnarf Sep 22, 2011
fed204e
Mask: Allow returning a 'default' value from the custom mask functions
gnarf Sep 22, 2011
4cb59bb
Timepicker: Default Values & Unit Tests
gnarf Sep 22, 2011
3d5b7ee
Mask: Fixing a Unit failure in IE
gnarf Sep 26, 2011
6450d87
Timepicker: mask function generator to save code size
gnarf Sep 27, 2011
e3911a6
Timepicker: Globalize support
gnarf Sep 27, 2011
3a7693d
Timepicker: cleaning up a half-finished thought with the validAmPm fu…
gnarf Sep 27, 2011
98df014
Timepicker: Fixing up from 23 to go to 0 instead of 12
gnarf Sep 28, 2011
676d995
Timepicker: Adding mousewheel to the visual tests page
gnarf Oct 5, 2011
ed05e2d
Timepicker: Trying to make the mosue interactions a little cleaner
gnarf Oct 5, 2011
a71766f
Tests: adding timepicker to unit/all.html
gnarf Oct 11, 2011
eda2ac5
Mask: fixing a broken unit test
gnarf Oct 11, 2011
ae3904f
Mask: Updating code with some suggestions from review
gnarf Oct 11, 2011
f35821b
Mask: Updating style from @rdworth's comments on the PR
gnarf Oct 11, 2011
27e229a
Mask: More updates from review - adresses comments from @jzaeffer
gnarf Oct 12, 2011
23fb658
Mask: Optional fields not displayed until the value is 'valid', or th…
gnarf Oct 12, 2011
9a1483a
Mask: Tweaks to optional position handling - should now hide optional…
gnarf Oct 12, 2011
8becf44
Merge branch 'master' into mask
gnarf Oct 13, 2011
912b8b2
Timepicker: Quick updates from code review.
gnarf Oct 13, 2011
6abb3c9
Spinner: Adjust height check for IE 6 rendering.
scottgonzalez Oct 13, 2011
22708e1
Merge branch 'master' into mask
gnarf Oct 25, 2011
90484cf
Unit Tests: Updating mask and timepicker units to conform to new suite.
gnarf Oct 25, 2011
0c2aca1
Visual Tests: Updating version of jQuery for timepicker and mask
gnarf Oct 25, 2011
a4b4fed
Mask: Updating tests to use correct focus/blur triggers - cleaning up…
gnarf Oct 25, 2011
009347c
Mask: removing some dead code / cleanup
gnarf Oct 26, 2011
23bd881
Timepicker: Fixing up tests and removing some unneeded code surroundi…
gnarf Oct 26, 2011
8d0e3c8
Timepicker: value method
gnarf Oct 26, 2011
9e3d21c
Timepicker: Refactoring culture to be an option
gnarf Oct 27, 2011
dd55dbc
Mask Demos: First draft of some demos in mask
gnarf Oct 28, 2011
b230414
Mask: Don't interfere with the natural behavior of shift+arrows
gnarf Oct 28, 2011
283c1f3
Merge branch 'master' into mask
jzaefferer Nov 18, 2011
45d6cb5
Remove method argument from _super and _superApply.
jzaefferer Nov 18, 2011
956579f
Merge branch 'master' into mask
jzaefferer Nov 24, 2011
9c1991a
Upgrade jQuery to 1.7.1.
jzaefferer Nov 24, 2011
1081ba0
Merge branch 'master' into mask
scottgonzalez Mar 14, 2012
bab9d81
Merge branch 'master' into mask
gnarf Aug 3, 2012
e3db34b
Mask: Bringing branch up to date with master
gnarf Aug 3, 2012
76db764
Mask: making sure fields are reformated as you leave them in multi ch…
gnarf Aug 7, 2012
3711469
Mask: Handle backspacing when in an already deleted field
gnarf Aug 7, 2012
6fde7ac
Merge branch 'master' into mask
gnarf Sep 4, 2012
537b4d4
Merge branch 'master' into mask
gnarf Sep 4, 2012
3f90530
Adding mask/timepicker to swarm for mask branch
gnarf Sep 4, 2012
d268aad
Merge remote-tracking branch 'origin/master' into mask
Oct 15, 2012
38931cf
mask/timepicker: use jquery files from tests directory, which actuall…
Oct 15, 2012
dd0b0b6
mask: update demos following merge
Oct 15, 2012
9d038dd
Mask: fix bug in visual test case
Oct 15, 2012
26c1864
Mask: add visual display of field's value and validity in visual test…
Oct 15, 2012
74f4439
Mask: fix isValid logic; previously, any call to getValue(true) resul…
Oct 15, 2012
2a03859
Mask: add visual test for removing an invalid value on blur
Oct 15, 2012
dab7f29
Mask: fix focus-related test bug which causes false-negatives in Chrome
Oct 15, 2012
8cca5e5
Mask: fix bug in raw-value-retrieval logic
Oct 15, 2012
3f23f5e
Mask: add unit tests for optional section
Oct 16, 2012
5cacdca
Mask: use setTimeout to work around Chrome caret positioning issue
Oct 16, 2012
9d768f6
Mask: address Chrome timing issue in qunit-friendly way
Oct 16, 2012
2d5ed8e
Mask: fix visual test to bind to blur as stated in the test's textual…
Oct 17, 2012
26b70df
Mask: Add support for '<...>' placeholders
Oct 16, 2012
14a8967
Timepicker: use proposed syntax
Oct 16, 2012
f6e5c2d
Mask: remove 'aa' defininitions from event test cases for simplicity
Oct 19, 2012
e880b34
Mask: add test cases for masks with multiple optional inputs and esca…
Oct 19, 2012
a1d4d9b
Mask: add support for escaped characters and processes additional opt…
Oct 19, 2012
54ddbf4
Timepicker: Use multi-version jquery.js
jzaefferer Nov 4, 2012
62eb666
Tests: Adding links to mask and timepicker visual tests
gnarf Nov 12, 2012
4929eed
Merge branch 'master' into mask
jzaefferer Nov 17, 2012
4f5a83c
Mask/Timepicker: Lint fixes. Units still fail.
jzaefferer Nov 17, 2012
6efbdbf
Mask: Update unit tests to use namespaced data property
jzaefferer Nov 18, 2012
8edaf14
Mask: Disable timepicker tests for phantomjs
jzaefferer Nov 18, 2012
c0bb9be
Timepicker: Use namespaced data property
jzaefferer Nov 18, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build/tasks/testswarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var versions = {
"Draggable": "draggable/draggable.html",
"Droppable": "droppable/droppable.html",
"Effects": "effects/effects.html",
"Mask": "mask/mask.html",
"Menu": "menu/menu.html",
"Position": "position/position.html",
"Progressbar": "progressbar/progressbar.html",
Expand All @@ -27,6 +28,7 @@ var versions = {
"Sortable": "sortable/sortable.html",
"Spinner": "spinner/spinner.html",
"Tabs": "tabs/tabs.html",
"Timepicker": "timepicker/timepicker.html",
"Tooltip": "tooltip/tooltip.html",
"Widget": "widget/widget.html"
};
Expand Down
2 changes: 2 additions & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<li><a href="droppable/">droppable</a></li>
<li><a href="effect/">effect</a></li>
<li><a href="hide/">hide</a></li>
<li><a href="mask/">mask</a></li>
<li><a href="menu/">menu</a></li>
<li><a href="position/">position</a></li>
<li><a href="progressbar/">progressbar</a></li>
Expand All @@ -30,6 +31,7 @@
<li><a href="spinner/">spinner</a></li>
<li><a href="switchClass/">switchClass</a></li>
<li><a href="tabs/">tabs</a></li>
<li><a href="timepicker/">timepicker</a></li>
<li><a href="toggle/">toggle</a></li>
<li><a href="toggleClass/">toggleClass</a></li>
<li><a href="tooltip/">tooltip</a></li>
Expand Down
38 changes: 38 additions & 0 deletions demos/mask/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>jQuery UI Mask - Simple Mask Demo</title>
<link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" />
<script src="../../jquery-1.8.2.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.mask.js"></script>
<link href="../demos.css" rel="stylesheet" />
<script>
$(function() {
$("#phone").mask({
mask: "(999) 999-9999"
});
});
</script>
<style>

</style>
</head>
<body>

<div class="demo">
Phone Number: <input id="phone"> (999) 999-9999<br>
</div><!-- End demo -->

<div class="demo-description">

<p>A few simple masks</p>

</div><!-- End demo-description -->



</body>
</html>
93 changes: 93 additions & 0 deletions demos/mask/functiondefinition.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>jQuery UI Mask - Function Definition Demo</title>
<link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" />
<script src="../../jquery-1.8.2.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.mask.js"></script>
<link href="../demos.css" rel="stylesheet" />
<script>
$(function() {

function createTwoDigitDefinition( maximum ) {
return function( value ) {
var number = parseInt( value, 10 );

if ( value === "" || /\D/.test( value ) ) {
return;
}

// allow "0" if it is the only character in the value,
// otherwise allow anything from 1 to maximum
if ( !number && value.length === 2 ) {
return;
}

// pad to 2 characters
number = ( number < 10 ? "0" : "" ) + number;
if ( number <= maximum ) {
return number;
}
}
}

function yearsDefinition( value ) {
var temp;

// if the value is empty, or contains a non-digit, it is invalid
if ( value === "" || /\D/.test( value ) ) {
return false;
}

// convert 2 digit years to 4 digits, this allows us to type 80 <right>
if ( value.length <= 2 ) {
temp = parseInt( value, 10 );
// before "32" we assume 2000's otherwise 1900's
if ( temp < 10 ) {
return "200" + temp;
} else if ( temp < 32 ) {
return "20" + temp;
} else {
return "19" + temp;
}
}
if ( value.length === 3 ) {
return "0"+value;
}
if ( value.length === 4 ) {
return value;
}
}
$("#date").mask({
mask: "yyyy/mm/dd",
definitions: {
"mm": createTwoDigitDefinition( 12 ),
"dd": createTwoDigitDefinition( 31 ),
"yyyy": yearsDefinition
}
});
});
</script>
<style>

</style>
</head>
<body>

<div class="demo">
Date: <input id="date"> Format: yyyy/mm/dd<br>
</div><!-- End demo -->

<div class="demo-description">

<p>An example of using functions to define new mask definitions. These definitions are "multiple character" fields that allow us to have a date formatted input that validates.</p>

</div><!-- End demo-description -->



</body>
</html>
17 changes: 17 additions & 0 deletions demos/mask/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>jQuery UI Mask Demos</title>
</head>
<body>
<div class="demos-nav">
<h4>Examples</h4>
<ul>
<li class="demo-config-on"><a href="default.html">Simple Masks</a></li>
<li><a href="regulardefinition.html">RegExp Definition</a></li>
<li><a href="functiondefinition.html">Function Definition</a></li>
</ul>
</div>
</body>
</html>
41 changes: 41 additions & 0 deletions demos/mask/regulardefinition.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>jQuery UI Mask - Regular Expressions Demo</title>
<link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" />
<script src="../../jquery-1.8.2.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.mask.js"></script>
<link href="../demos.css" rel="stylesheet" />
<script>
$(function() {
$("#rx").mask({
mask: "~9.99 ~9.99 999",
definitions: {
"~": /[+-]/
}
});
});
</script>
<style>

</style>
</head>
<body>

<div class="demo">
Lens Perscription: <input id="rx"> Format: ~9.99 ~9.99 999<br>
</div><!-- End demo -->

<div class="demo-description">

<p>An example of using a regular expression to define a new mask definition. Using the <code>definitions</code> option we define the <code>~</code> in the mask to only accept a <code>+</code> or a <code>-</code>.</p>

</div><!-- End demo-description -->



</body>
</html>
2 changes: 1 addition & 1 deletion grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ grunt.initConfig({
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
// disabling everything that doesn't (quite) work with PhantomJS for now
// TODO except for all|index|test, try to include more as we go
return !( /(all|index|test|dialog|tabs|tooltip)\.html$/ ).test( file );
return !( /(all|index|test|dialog|tabs|timepicker|tooltip)\.html$/ ).test( file );
})
},
lint: {
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"draggable/draggable.html",
"droppable/droppable.html",
"effects/effects.html",
"mask/mask.html",
"menu/menu.html",
"position/position.html",
"progressbar/progressbar.html",
Expand All @@ -34,6 +35,8 @@
"sortable/sortable.html",
"spinner/spinner.html",
"tabs/tabs.html",
"tabs/tabs_deprecated.html",
"timepicker/timepicker.html",
"tooltip/tooltip.html",
"widget/widget.html"
];
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ <h2>Widgets</h2>
<li><a href="button/button.html">Button</a></li>
<li><a href="datepicker/datepicker.html">Datepicker</a></li>
<li><a href="dialog/dialog.html">Dialog</a></li>
<li><a href="mask/mask.html">Mask</a></li>
<li><a href="menu/menu.html">Menu</a></li>
<li><a href="progressbar/progressbar.html">Progressbar</a></li>
<li><a href="slider/slider.html">Slider</a></li>
<li><a href="spinner/spinner.html">Spinner</a></li>
<li><a href="tabs/tabs.html">Tabs</a></li>
<li><a href="timepicker/timepicker.html">Timepicker</a></li>
<li><a href="tooltip/tooltip.html">Tooltip</a></li>
</ul>

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/mask/all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Mask Test Suite</title>

<script src="../../../jquery-1.7.2.js"></script>

<link rel="stylesheet" href="../../../external/qunit.css">
<link rel="stylesheet" href="../qunit-composite.css">
<script src="../../../external/qunit.js"></script>
<script src="../qunit-composite.js"></script>
<script src="../subsuite.js"></script>

<script>
testAllVersions( "mask" );
</script>
</head>
<body>

<h1 id="qunit-header">jQuery UI Mask Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">

</div>
</body>
</html>
39 changes: 39 additions & 0 deletions tests/unit/mask/mask.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Mask Test Suite</title>

<link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">

<script src="../../jquery.js"></script>
<script src="../../../ui/jquery.ui.core.js"></script>
<script src="../../../ui/jquery.ui.widget.js"></script>
<script src="../../../ui/jquery.ui.mask.js"></script>

<link rel="stylesheet" href="../../../external/qunit.css">
<script src="../../../external/qunit.js"></script>
<script src="../../jquery.simulate.js"></script>
<script src="../testsuite.js"></script>

<script src="mask_test_helpers.js"></script>
<script src="mask_common.js"></script>
<script src="mask_core.js"></script>
<script src="mask_events.js"></script>
<script src="mask_methods.js"></script>
<script src="mask_options.js"></script>

<script src="../swarminject.js"></script>
</head>
<body>

<h1 id="qunit-header">jQuery UI Mask Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<input id="mask1" type="text">
</div>
</body>
</html>
16 changes: 16 additions & 0 deletions tests/unit/mask/mask_common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
TestHelpers.commonWidgetTests( "mask", {
defaults: {
clearEmpty: true,
definitions: {
'9': /[0-9]/,
'a': /[A-Za-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]/,
'*': /[A-Za-z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]/
},
disabled: false,
mask: null,
placeholder: "_",

// callbacks
create: null
}
});
Loading