Skip to content

Commit

Permalink
netteForms: supports Common.JS and AMD loading [Closes #69]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 14, 2015
1 parent a5c269d commit ad09c0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

var Nette = Nette || {};
(function(global, factory) {
if (typeof define === 'function' && define.amd) {
define(function() {
return factory(global);
});
} else if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = factory(global);
} else {
global.Nette = factory(global);
global.Nette.initOnLoad();
}

}(typeof window !== 'undefined' ? window : this, function(window) {

var Nette = {};

/**
* Attaches a handler to an event for the element.
Expand Down Expand Up @@ -261,7 +275,7 @@ Nette.validators = {
filled: function(elem, arg, val) {
return val !== '' && val !== false && val !== null
&& (!Nette.isArray(val) || !!val.length)
&& (!window.FileList || !(val instanceof FileList) || val.length);
&& (!window.FileList || !(val instanceof window.FileList) || val.length);
},

blank: function(elem, arg, val) {
Expand Down Expand Up @@ -378,7 +392,7 @@ Nette.validators = {
},

image: function (elem, arg, val) {
if (window.FileList && val instanceof FileList) {
if (window.FileList && val instanceof window.FileList) {
for (var i = 0; i < val.length; i++) {
var type = val[i].type;
if (type && type !== 'image/gif' && type !== 'image/png' && type !== 'image/jpeg') {
Expand Down Expand Up @@ -572,4 +586,5 @@ Nette.webalize = function(s) {

Nette.webalizeTable = {\u00e1: 'a', \u00e4: 'a', \u010d: 'c', \u010f: 'd', \u00e9: 'e', \u011b: 'e', \u00ed: 'i', \u013e: 'l', \u0148: 'n', \u00f3: 'o', \u00f4: 'o', \u0159: 'r', \u0161: 's', \u0165: 't', \u00fa: 'u', \u016f: 'u', \u00fd: 'y', \u017e: 'z'};

Nette.initOnLoad();
return Nette;
}));
2 changes: 1 addition & 1 deletion tests/netteForms/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
"predef" : [ // Custom globals.
"FileList"
"define", "module"
],

"debug" : false, // Allow debugger statements e.g. browser breakpoints.
Expand Down

0 comments on commit ad09c0e

Please sign in to comment.