Permalink
Browse files

*Fixed variable assignment where "var" was missing

*Added strict comparison
*Added missing semicolons
*Escaped "-" in regular expressions
  • Loading branch information...
1 parent 02ca560 commit 4daa557f0e2d6e6f454a2d598cd6d96c3cd88edc @MarcelloDiSimone MarcelloDiSimone committed Aug 6, 2012
Showing with 42 additions and 41 deletions.
  1. +4 −1 .gitignore
  2. +23 −25 src/editors.js
  3. +7 −7 src/form.js
  4. +4 −4 src/helpers.js
  5. +4 −4 src/validators.js
View
@@ -1,2 +1,5 @@
/node_modules/*
-!/node_modules/buildify
+!/node_modules/buildify
+*.iml
+*.ipr
+*.iws
View
@@ -83,7 +83,7 @@ Form.editors = (function() {
var key = this.key || '';
//Replace periods with underscores (e.g. for when using paths)
- return key.replace(/\./g, '_')
+ return key.replace(/\./g, '_');
},
/**
@@ -133,10 +133,10 @@ Form.editors = (function() {
trigger: function(event) {
- if (event == 'focus') {
+ if (event === 'focus') {
this.hasFocus = true;
}
- else if (event == 'blur') {
+ else if (event === 'blur') {
this.hasFocus = false;
}
@@ -198,7 +198,7 @@ Form.editors = (function() {
determineChange: function(event) {
var currentValue = this.$el.val();
- var changed = (currentValue != this.previousValue);
+ var changed = (currentValue !== this.previousValue);
if (changed) {
this.previousValue = currentValue;
@@ -269,10 +269,10 @@ Form.editors = (function() {
setTimeout(function() {
self.determineChange();
}, 0);
- }
+ };
//Allow backspace
- if (event.charCode == 0) {
+ if (event.charCode === 0) {
delayedDetermineChange();
return;
}
@@ -518,7 +518,7 @@ Form.editors = (function() {
//Or Backbone collection
else if (options instanceof Backbone.Collection) {
- html = this._collectionToHtml(options)
+ html = this._collectionToHtml(options);
}
//Insert options
@@ -609,7 +609,7 @@ Form.editors = (function() {
events: {
'click input[type=radio]:not(:checked)': function() {
- this.trigger('change', this)
+ this.trigger('change', this);
},
'focus input[type=radio]': function() {
if (this.hasFocus) return;
@@ -665,12 +665,12 @@ Form.editors = (function() {
var itemHtml = '<li>';
if (_.isObject(option)) {
var val = option.val ? option.val : '';
- itemHtml += ('<input type="radio" name="'+self.id+'" value="'+val+'" id="'+self.id+'-'+index+'" />')
- itemHtml += ('<label for="'+self.id+'-'+index+'">'+option.label+'</label>')
+ itemHtml += ('<input type="radio" name="'+self.id+'" value="'+val+'" id="'+self.id+'-'+index+'" />');
+ itemHtml += ('<label for="'+self.id+'-'+index+'">'+option.label+'</label>');
}
else {
- itemHtml += ('<input type="radio" name="'+self.id+'" value="'+option+'" id="'+self.id+'-'+index+'" />')
- itemHtml += ('<label for="'+self.id+'-'+index+'">'+option+'</label>')
+ itemHtml += ('<input type="radio" name="'+self.id+'" value="'+option+'" id="'+self.id+'-'+index+'" />');
+ itemHtml += ('<label for="'+self.id+'-'+index+'">'+option+'</label>');
}
itemHtml += '</li>';
html.push(itemHtml);
@@ -698,7 +698,7 @@ Form.editors = (function() {
events: {
'click input[type=checkbox]': function() {
- this.trigger('change', this)
+ this.trigger('change', this);
},
'focus input[type=checkbox]': function() {
if (this.hasFocus) return;
@@ -753,12 +753,12 @@ Form.editors = (function() {
var itemHtml = '<li>';
if (_.isObject(option)) {
var val = option.val ? option.val : '';
- itemHtml += ('<input type="checkbox" name="'+self.id+'" value="'+val+'" id="'+self.id+'-'+index+'" />')
- itemHtml += ('<label for="'+self.id+'-'+index+'">'+option.label+'</label>')
+ itemHtml += ('<input type="checkbox" name="'+self.id+'" value="'+val+'" id="'+self.id+'-'+index+'" />');
+ itemHtml += ('<label for="'+self.id+'-'+index+'">'+option.label+'</label>');
}
else {
- itemHtml += ('<input type="checkbox" name="'+self.id+'" value="'+option+'" id="'+self.id+'-'+index+'" />')
- itemHtml += ('<label for="'+self.id+'-'+index+'">'+option+'</label>')
+ itemHtml += ('<input type="checkbox" name="'+self.id+'" value="'+option+'" id="'+self.id+'-'+index+'" />');
+ itemHtml += ('<label for="'+self.id+'-'+index+'">'+option+'</label>');
}
itemHtml += '</li>';
html.push(itemHtml);
@@ -852,11 +852,11 @@ Form.editors = (function() {
_observeFormEvents: function() {
this.form.on('all', function() {
// args = ["key:change", form, fieldEditor]
- args = _.toArray(arguments);
+ var args = _.toArray(arguments);
args[1] = this;
// args = ["key:change", this=objectEditor, fieldEditor]
- this.trigger.apply(this, args)
+ this.trigger.apply(this, args);
}, this);
}
@@ -886,9 +886,7 @@ Form.editors = (function() {
nestedModel = this.schema.model;
//Wrap the data in a model if it isn't already a model instance
- var modelInstance = (data.constructor == nestedModel)
- ? data
- : new nestedModel(data);
+ var modelInstance = (data.constructor === nestedModel) ? data : new nestedModel(data);
this.form = new Form({
model: modelInstance,
@@ -959,12 +957,12 @@ Form.editors = (function() {
},
initialize: function(options) {
- options = options || {}
+ options = options || {};
editors.Base.prototype.initialize.call(this, options);
var Self = editors.Date,
- today = new Date;
+ today = new Date();
//Option defaults
this.options = _.extend({
@@ -1147,7 +1145,7 @@ Form.editors = (function() {
render: function() {
function pad(n) {
- return n < 10 ? '0' + n : n
+ return n < 10 ? '0' + n : n;
}
var schema = this.schema;
View
@@ -152,12 +152,12 @@ var Form = (function() {
field.editor.on('all', function(event) {
// args = ["change", editor]
- args = _.toArray(arguments);
+ var args = _.toArray(arguments);
args[0] = key + ':' + event;
args.splice(1, 0, this);
// args = ["key:change", this=form, editor]
- this.trigger.apply(this, args)
+ this.trigger.apply(this, args);
}, self);
field.editor.on('change', function() {
@@ -177,12 +177,12 @@ var Form = (function() {
}, 0);
}, self);
- if (itemSchema.type != 'Hidden') {
+ if (itemSchema.type !== 'Hidden') {
$fieldsContainer.append(fieldEl);
}
});
- $fieldsContainer = $fieldsContainer.children().unwrap()
+ $fieldsContainer = $fieldsContainer.children().unwrap();
return $fieldset;
},
@@ -343,7 +343,7 @@ var Form = (function() {
blur: function() {
if (!this.hasFocus) return;
- focusedField = _.find(this.fields, function(field) { return field.editor.hasFocus; });
+ var focusedField = _.find(this.fields, function(field) { return field.editor.hasFocus; });
if (focusedField) focusedField.editor.blur();
},
@@ -363,10 +363,10 @@ var Form = (function() {
trigger: function(event) {
- if (event == 'focus') {
+ if (event === 'focus') {
this.hasFocus = true;
}
- else if (event == 'blur') {
+ else if (event === 'blur') {
this.hasFocus = false;
}
View
@@ -22,7 +22,7 @@ Form.helpers = (function() {
result = result[fields[i]];
}
return result;
- }
+ };
/**
* This function is used to transform the key from a schema into the title used in a label.
@@ -63,7 +63,7 @@ Form.helpers = (function() {
_.templateSettings.interpolate = _interpolateBackup;
return template;
- }
+ };
/**
* Helper to create a template with the {{mustache}} style tags.
@@ -89,7 +89,7 @@ Form.helpers = (function() {
*/
helpers.setTemplateCompiler = function(compiler) {
helpers.compileTemplate = compiler;
- }
+ };
/**
@@ -169,7 +169,7 @@ Form.helpers = (function() {
args.push(callback);
fn.apply(context, args);
- }
+ };
/**
* Returns a validation function based on the type defined in the schema
View
@@ -13,7 +13,7 @@ Form.validators = (function() {
email: 'Invalid email address',
url: 'Invalid URL',
match: 'Must match field "{{field}}"'
- }
+ };
validators.required = function(options) {
options = _.extend({
@@ -70,7 +70,7 @@ Form.validators = (function() {
options = _.extend({
type: 'url',
message: this.errMessages.url,
- regexp: /^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i
+ regexp: /^(http|https):\/\/(([A-Z0-9][A-Z0-9_\-]*)(\.[A-Z0-9][A-Z0-9_\-]*)+)(:(\d+))?\/?/i
}, options);
return validators.regexp(options);
@@ -95,8 +95,8 @@ Form.validators = (function() {
//Don't check empty values (add a 'required' validator for this)
if (value === null || value === undefined || value === '') return;
- if (value != attrs[options.field]) return err;
- }
+ if (value !== attrs[options.field]) return err;
+ };
};

0 comments on commit 4daa557

Please sign in to comment.