Permalink
Browse files

Merge branch 'opt-jshint' of https://github.com/MarcelloDiSimone/back…

…bone-forms

Conflicts:
	distribution.amd/backbone-forms.js
	distribution.amd/backbone-forms.min.js
	distribution.amd/editors/jquery-ui.min.js
	distribution.amd/editors/list.min.js
	distribution/adapters/backbone.bootstrap-modal.min.js
	distribution/backbone-forms.js
	distribution/backbone-forms.min.js
	distribution/editors/list.min.js
	src/editors.js
  • Loading branch information...
2 parents 6f67b5a + 6fe8b6c commit b9f52e75b06d660f1e6bbe58cc12a946e4dbcef0 @powmedia committed Oct 12, 2012
Showing with 63 additions and 58 deletions.
  1. +4 −1 .gitignore
  2. +24 −26 src/editors.js
  3. +7 −7 src/editors/jquery-ui.js
  4. +13 −9 src/editors/list.js
  5. +7 −7 src/form.js
  6. +4 −4 src/helpers.js
  7. +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, '_');
},
/**
@@ -124,7 +124,7 @@ Form.editors = (function() {
_.every(validators, function(validator) {
error = getValidator(validator)(value, formValues);
- return continueLoop = error ? false : true;
+ return error ? false : true;
});
}
@@ -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;
@@ -270,10 +270,10 @@ Form.editors = (function() {
setTimeout(function() {
self.determineChange();
}, 0);
- }
+ };
//Allow backspace
- if (event.charCode == 0) {
+ if (event.charCode === 0) {
delayedDetermineChange();
return;
}
@@ -519,7 +519,7 @@ Form.editors = (function() {
//Or Backbone collection
else if (options instanceof Backbone.Collection) {
- html = this._collectionToHtml(options)
+ html = this._collectionToHtml(options);
}
//Insert options
@@ -610,7 +610,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;
@@ -666,12 +666,12 @@ Form.editors = (function() {
var itemHtml = '<li>';
if (_.isObject(option)) {
var val = (option.val || option.val === 0) ? 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);
@@ -699,7 +699,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;
@@ -754,12 +754,12 @@ Form.editors = (function() {
var itemHtml = '<li>';
if (_.isObject(option)) {
var val = (option.val || option.val === 0) ? 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);
@@ -853,11 +853,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);
}
@@ -887,9 +887,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,
@@ -960,12 +958,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({
@@ -1151,7 +1149,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
@@ -83,7 +83,7 @@
var self = this;
this.$('input').datepicker('option', 'onSelect', function() {
self.trigger('change', self);
- })
+ });
this.$('input').datepicker('option', 'onClose', function() {
if (!self.hasFocus) return;
self.trigger('blur', self);
@@ -108,7 +108,7 @@
render: function() {
function pad(n) {
- return n < 10 ? '0' + n : n
+ return n < 10 ? '0' + n : n;
}
//Render the date element first
@@ -213,7 +213,7 @@
this.schema.listType = this.schema.listType || 'Text';
- if (this.schema.listType == 'NestedModel' && !this.schema.model)
+ if (this.schema.listType === 'NestedModel' && !this.schema.model)
throw "Missing required option 'schema.model'";
},
@@ -290,7 +290,7 @@
if (schema.itemToString) return schema.itemToString(data);
//Otherwise check if it's NestedModel with it's own toString() method
- if (this.schema.listType == 'NestedModel') {
+ if (this.schema.listType === 'NestedModel') {
var model = new (this.schema.model)(data);
return model.toString();
@@ -417,13 +417,13 @@
callback(editor.getValue(), editor);
container.dialog('close');
- }
+ };
var handleEnterPressed = function(event) {
- if (event.keyCode != 13) return;
+ if (event.keyCode !== 13) return;
saveAndClose();
- }
+ };
$(container).dialog({
resizable: false,
View
@@ -105,10 +105,10 @@
self.$list.append(item.el);
item.editor.on('all', function(event) {
- if (event == 'change') return;
+ if (event === 'change') return;
// args = ["key:change", itemEditor, fieldEditor]
- args = _.toArray(arguments);
+ var args = _.toArray(arguments);
args[0] = 'item:' + event;
args.splice(1, 0, self);
// args = ["item:key:change", this=listEditor, itemEditor, fieldEditor]
@@ -206,7 +206,7 @@
blur: function() {
if (!this.hasFocus) return;
- focusedItem = _.find(this.items, function(item) { return item.editor.hasFocus; });
+ var focusedItem = _.find(this.items, function(item) { return item.editor.hasFocus; });
if (focusedItem) focusedItem.editor.blur();
},
@@ -265,7 +265,7 @@
this.list.removeItem(this);
},
'keydown input[type=text]': function(event) {
- if(event.keyCode != 13) return;
+ if(event.keyCode !== 13) return;
event.preventDefault();
this.list.addItem();
this.list.$list.find("> li:last input").focus();
@@ -338,11 +338,15 @@
_.every(validators, function(validator) {
error = getValidator(validator)(value, formValues);
- return continueLoop = error ? false : true;
+ return error ? false : true;
});
//Show/hide error
- error ? this.setError(error) : this.clearError();
+ if (error){
+ this.setError(error);
+ } else {
+ this.clearError();
+ }
//Return error to be aggregated by list
return error ? error : null;
@@ -391,14 +395,14 @@
if (!editors.List.Modal.ModalAdapter) throw 'A ModalAdapter is required';
//Get nested schema if Object
- if (schema.itemType == 'Object') {
+ if (schema.itemType === 'Object') {
if (!schema.subSchema) throw 'Missing required option "schema.subSchema"';
this.nestedSchema = schema.subSchema;
}
//Get nested schema if NestedModel
- if (schema.itemType == 'NestedModel') {
+ if (schema.itemType === 'NestedModel') {
if (!schema.model) throw 'Missing required option "schema.model"';
this.nestedSchema = schema.model.prototype.schema;
@@ -479,7 +483,7 @@
if (schema.itemToString) return schema.itemToString(value);
//Otherwise check if it's NestedModel with it's own toString() method
- if (schema.itemType == 'NestedModel') {
+ if (schema.itemType === 'NestedModel') {
return new (schema.model)(value).toString();
}
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;
},
@@ -352,7 +352,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();
},
@@ -372,10 +372,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
Oops, something went wrong.

0 comments on commit b9f52e7

Please sign in to comment.