Skip to content

Commit b22eb62

Browse files
committed
Fixed Requirejs usage
1 parent 2f6d3d9 commit b22eb62

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

demo/load-by-requirejs.html

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<body>
1010

11-
<form id="form1" class="form" data-validator-option="{timely:2}">
11+
<form id="form1" class="form">
1212
<div class="form-item">
1313
<input type="text" name="user[email]" data-rule="required;email" placeholder="Email">
1414
</div>
@@ -27,29 +27,32 @@
2727
baseUrl: '../',
2828
paths: {
2929
jquery: 'http://cdn.jsdelivr.net/jquery/1.12.3/jquery.min',
30-
validator: 'dist/jquery.validator.js?local=en'
30+
validator: 'dist/local/zh-CN'
31+
},
32+
shim: {
33+
validator: ['../dist/jquery.validator.js?css']
3134
}
3235
});
3336

34-
// Just include nice-validator
35-
require(['validator']);
3637

37-
38-
/*
39-
// Use plugin methods
38+
// Way 1: Use plugin methods
4039
require(['jquery', 'validator'], function($){
41-
$('#form1').validator();
40+
$('#form1').validator({
41+
timely: 2,
42+
stopOnError: true,
43+
theme: 'yellow_right'
44+
});
4245
});
43-
*/
4446

4547

46-
/*
47-
// Define a module dependency nice-validator
48-
define('some-module', ['jquery', 'validator'], function($){
49-
// some code
50-
});
51-
*/
48+
// Way 2: Just include nice-validator
49+
// require(['validator']);
50+
5251

52+
// Way 3: Define a module dependency nice-validator
53+
// define('some-module', ['jquery', 'validator'], function($){
54+
// // some code
55+
// });
5356
</script>
5457
</body>
55-
</html>
58+
</html>

src/jquery.validator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;(function(factory) {
22
typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
3-
typeof define === 'function' && define.amd ? require(['jquery'], factory) :
3+
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
44
factory(jQuery);
55
}(function($, undefined) {
66
"use strict";
@@ -2105,7 +2105,7 @@
21052105
el.href = Validator.css = dir + 'jquery.validator.css';
21062106
node.parentNode.insertBefore(el, node);
21072107
}
2108-
if (!Validator.local && params.local !== '') {
2108+
if (!Validator.local && ~str.indexOf('local') && params.local !== '') {
21092109
Validator.local = (params.local || doc.documentElement.lang || 'en').replace('_','-');
21102110
Validator.pending = 1;
21112111
el = doc.createElement('script');

src/local/_config.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*********************************/
55
(function(factory) {
66
typeof module === "object" && module.exports ? module.exports = factory( require( "jquery" ) ) :
7-
typeof define === 'function' && define.amd ? require(['jquery'], factory) :
7+
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
88
factory(jQuery);
99
}(function($) {
1010

0 commit comments

Comments
 (0)