diff --git a/.hound.yml b/.hound.yml new file mode 100644 index 000000000..762af91d4 --- /dev/null +++ b/.hound.yml @@ -0,0 +1,4 @@ +java_script: + enabled: true + config_file: config/.jshint.json + ignore_file: config/.jshint_ignore diff --git a/Gemfile b/Gemfile index 9cbeeb992..8697a61b1 100644 --- a/Gemfile +++ b/Gemfile @@ -217,6 +217,9 @@ group :development do gem 'rb-fsevent', '0.9.4', :require => false gem 'rb-inotify', '0.9.5', :require => false + # Linters + gem 'jshint', '1.3.1' + # Preloading environment gem 'spring', '1.2.0' @@ -261,5 +264,5 @@ group :development, :test do # Jasmine (client side application tests (JS)) gem 'jasmine', '2.1.0' gem 'jasmine-jquery-rails', '2.0.3' - gem 'sinon-rails', '1.10.3' + gem 'sinon-rails', '1.10.3' end diff --git a/Gemfile.lock b/Gemfile.lock index b1da44a53..71b14c7ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -308,12 +308,17 @@ GEM sprockets-rails js_image_paths (0.0.1) rails (~> 4.0) + jshint (1.3.1) + execjs (>= 1.4.0) + multi_json (~> 1.0) + therubyracer (~> 0.12.1) json (1.8.1) jwt (1.0.0) kaminari (0.16.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) kgio (2.9.2) + libv8 (3.16.14.7) listen (2.8.3) celluloid (>= 0.15.2) rb-fsevent (>= 0.9.3) @@ -488,6 +493,7 @@ GEM redis (3.1.0) redis-namespace (1.5.1) redis (~> 3.0, >= 3.0.4) + ref (1.0.5) remotipart (1.2.1) request_store (1.1.0) responders (1.1.2) @@ -569,6 +575,9 @@ GEM systemu (2.6.4) test_after_commit (0.4.0) activerecord (>= 3.2) + therubyracer (0.12.1) + libv8 (~> 3.16.14.0) + ref thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) @@ -658,6 +667,7 @@ DEPENDENCIES jquery-rails (= 3.1.2) js-routes (= 0.9.9) js_image_paths (= 0.0.1) + jshint (= 1.3.1) json (= 1.8.1) markerb (= 1.0.2) messagebus_ruby_api (= 1.0.3) diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js index 89a79031b..a3aa65c5e 100644 --- a/app/assets/javascripts/app/app.js +++ b/app/assets/javascripts/app/app.js @@ -35,8 +35,11 @@ var app = { events: _.extend({}, Backbone.Events), user: function(userAttrs) { - if(userAttrs) { return this._user = new app.models.User(userAttrs) } - return this._user || false + if(userAttrs) { + this._user = new app.models.User(userAttrs); + return this._user; + } + return this._user || false; }, initialize: function() { @@ -52,25 +55,25 @@ var app = { }, hasPreload : function(prop) { - return !!(window.gon.preloads && window.gon.preloads[prop]) //returning boolean variable so that parsePreloads, which cleans up properly is used instead + return !!(window.gon.preloads && window.gon.preloads[prop]); //returning boolean variable so that parsePreloads, which cleans up properly is used instead }, setPreload : function(prop, val) { - window.gon.preloads = window.gon.preloads || {} - window.gon.preloads[prop] = val + window.gon.preloads = window.gon.preloads || {}; + window.gon.preloads[prop] = val; }, parsePreload : function(prop) { if(!app.hasPreload(prop)) { return } - var preload = window.gon.preloads[prop] - delete window.gon.preloads[prop] //prevent dirty state across navigates + var preload = window.gon.preloads[prop]; + delete window.gon.preloads[prop]; //prevent dirty state across navigates - return(preload) + return(preload); }, setupDummyPreloads: function() { - if (window.gon == undefined) { + if (window.gon === undefined) { window.gon = {preloads:{}}; } }, @@ -101,8 +104,8 @@ var app = { evt.preventDefault(); var link = $(this); - $(".stream_title").text(link.text()) - app.router.navigate(link.attr("href").substring(1) ,true) + $(".stream_title").text(link.text()); + app.router.navigate(link.attr("href").substring(1) ,true); }); }, @@ -118,7 +121,7 @@ var app = { /* mixpanel wrapper function */ instrument : function(type, name, object, callback) { if(!window.mixpanel) { return } - window.mixpanel[type](name, object, callback) + window.mixpanel[type](name, object, callback); }, setupDisabledLinks: function() { @@ -132,4 +135,3 @@ $(function() { app.initialize(); }); // @license-end - diff --git a/app/assets/javascripts/app/collections/aspect_memberships.js b/app/assets/javascripts/app/collections/aspect_memberships.js index dd8ee1b5d..dc3c0410b 100644 --- a/app/assets/javascripts/app/collections/aspect_memberships.js +++ b/app/assets/javascripts/app/collections/aspect_memberships.js @@ -2,5 +2,5 @@ app.collections.AspectMemberships = Backbone.Collection.extend({ model: app.models.AspectMembership -}) +}); // @license-end diff --git a/app/assets/javascripts/app/collections/aspects.js b/app/assets/javascripts/app/collections/aspects.js index ce9fca6f5..1e284274b 100644 --- a/app/assets/javascripts/app/collections/aspects.js +++ b/app/assets/javascripts/app/collections/aspects.js @@ -25,6 +25,5 @@ app.collections.Aspects = Backbone.Collection.extend({ var separator = Diaspora.I18n.t("comma") + ' '; return this.selectedAspects('name').join(separator).replace(/,\s([^,]+)$/, ' ' + Diaspora.I18n.t("and") + ' $1') || Diaspora.I18n.t("my_aspects"); } -}) +}); // @license-end - diff --git a/app/assets/javascripts/app/collections/comments.js b/app/assets/javascripts/app/collections/comments.js index 34f4e8251..f096363e0 100644 --- a/app/assets/javascripts/app/collections/comments.js +++ b/app/assets/javascripts/app/collections/comments.js @@ -16,8 +16,8 @@ app.collections.Comments = Backbone.Collection.extend({ var deferred = comment.save({}, { url: '/posts/'+this.post.id+'/comments', success: function() { - comment.set({author: app.currentUser.toJSON(), parent: self.post }) - self.add(comment) + comment.set({author: app.currentUser.toJSON(), parent: self.post }); + self.add(comment); } }); @@ -25,4 +25,3 @@ app.collections.Comments = Backbone.Collection.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/collections/likes.js b/app/assets/javascripts/app/collections/likes.js index d34a92270..76168237b 100644 --- a/app/assets/javascripts/app/collections/likes.js +++ b/app/assets/javascripts/app/collections/likes.js @@ -4,8 +4,7 @@ app.collections.Likes = Backbone.Collection.extend({ model: app.models.Like, initialize : function(models, options) { - this.url = "/posts/" + options.post.id + "/likes" //not delegating to post.url() because when it is in a stream collection it delegates to that url + this.url = "/posts/" + options.post.id + "/likes"; //not delegating to post.url() because when it is in a stream collection it delegates to that url } }); // @license-end - diff --git a/app/assets/javascripts/app/collections/photos.js b/app/assets/javascripts/app/collections/photos.js index da8c636a9..978858304 100644 --- a/app/assets/javascripts/app/collections/photos.js +++ b/app/assets/javascripts/app/collections/photos.js @@ -4,7 +4,7 @@ app.collections.Photos = Backbone.Collection.extend({ url : "/photos", model: function(attrs, options) { - var modelClass = app.models.Photo + var modelClass = app.models.Photo; return new modelClass(attrs, options); }, @@ -13,4 +13,3 @@ app.collections.Photos = Backbone.Collection.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/helpers/date_formatter.js b/app/assets/javascripts/app/helpers/date_formatter.js index 1226d94c7..395e55f65 100644 --- a/app/assets/javascripts/app/helpers/date_formatter.js +++ b/app/assets/javascripts/app/helpers/date_formatter.js @@ -14,7 +14,6 @@ return timestamp || 0; } - } + }; })(); // @license-end - diff --git a/app/assets/javascripts/app/helpers/handlebars-helpers.js b/app/assets/javascripts/app/helpers/handlebars-helpers.js index 0b59ba93b..c428bfdd7 100644 --- a/app/assets/javascripts/app/helpers/handlebars-helpers.js +++ b/app/assets/javascripts/app/helpers/handlebars-helpers.js @@ -1,7 +1,7 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later Handlebars.registerHelper('t', function(scope, values) { - return Diaspora.I18n.t(scope, values.hash) + return Diaspora.I18n.t(scope, values.hash); }); Handlebars.registerHelper('txtDirClass', function(str) { @@ -29,7 +29,7 @@ Handlebars.registerHelper('linkToAuthor', function(context, block) { html += block.fn(context); html += ""; - return html + return html; }); Handlebars.registerHelper('linkToPerson', function(context, block) { @@ -38,7 +38,7 @@ Handlebars.registerHelper('linkToPerson', function(context, block) { html += block.fn(context); html += ""; - return html + return html; }); // relationship indicator for profile page @@ -61,7 +61,7 @@ Handlebars.registerHelper('sharingMessage', function(person) { // allow hovercards for users that are not the current user. // returns the html class name used to trigger hovercards. Handlebars.registerHelper('hovercardable', function(person) { - if( app.currentUser.get('guid') != person.guid ) { + if( app.currentUser.get('guid') !== person.guid ) { return 'hovercardable'; } return ''; @@ -104,7 +104,7 @@ Handlebars.registerHelper('fmtText', function(text) { Handlebars.registerHelper('isCurrentPage', function(path_helper, id, options){ var currentPage = "/"+Backbone.history.fragment; - if (currentPage == Handlebars.helpers.urlTo(path_helper, id, options.data)) { + if (currentPage === Handlebars.helpers.urlTo(path_helper, id, options.data)) { return options.fn(this); } else { return options.inverse(this); @@ -121,7 +121,7 @@ Handlebars.registerHelper('aspectMembershipIndicator', function(contact,in_aspec if(!app.aspect || !app.aspect.get('id')) return '
'; var html = '' + if (data.type === "photo") { + return ''; } else { - return data.html || "" + return data.html || ""; } } - } + }; })(); // @license-end - diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index 2e0c7b7ca..fefcfa2b8 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -6,7 +6,7 @@ var punycodeURL = function(url){ try { - while(url.indexOf("%") !== -1 && url != decodeURI(url)) url = decodeURI(url); + while(url.indexOf("%") !== -1 && url !== decodeURI(url)) url = decodeURI(url); } catch(e){} @@ -15,7 +15,7 @@ url = // rebuild the url (!addr.scheme ? '' : addr.scheme + - ( (addr.scheme.toLowerCase()=="mailto" || addr.scheme.toLowerCase()=="xmpp") ? ':' : '://')) + + ( (addr.scheme.toLowerCase() === "mailto" || addr.scheme.toLowerCase() === "xmpp") ? ':' : '://')) + (!addr.user ? '' : addr.user + (!addr.pass ? '' : ':'+addr.pass) + '@') + punycode.toASCII(addr.host) + diff --git a/app/assets/javascripts/app/helpers/truncate.js b/app/assets/javascripts/app/helpers/truncate.js index 122a259b7..7cfa6aa59 100644 --- a/app/assets/javascripts/app/helpers/truncate.js +++ b/app/assets/javascripts/app/helpers/truncate.js @@ -1,6 +1,6 @@ (function() { app.helpers.truncate = function(passedString, length) { - if (passedString == null || passedString == undefined) { + if (passedString === null || passedString === undefined) { return passedString; } diff --git a/app/assets/javascripts/app/models/contact.js b/app/assets/javascripts/app/models/contact.js index a1e014c4c..5457f2c4e 100644 --- a/app/assets/javascripts/app/models/contact.js +++ b/app/assets/javascripts/app/models/contact.js @@ -7,7 +7,7 @@ app.models.Contact = Backbone.Model.extend({ }, inAspect : function(id) { - return this.aspect_memberships.any(function(membership){ return membership.get('aspect').id == id; }); + return this.aspect_memberships.any(function(membership){ return membership.get('aspect').id === id; }); } }); // @license-end diff --git a/app/assets/javascripts/app/models/person.js b/app/assets/javascripts/app/models/person.js index 79a04c067..0cfcc9f66 100644 --- a/app/assets/javascripts/app/models/person.js +++ b/app/assets/javascripts/app/models/person.js @@ -12,20 +12,20 @@ app.models.Person = Backbone.Model.extend({ isSharing: function() { var rel = this.get('relationship'); - return (rel == 'mutual' || rel == 'sharing'); + return (rel === 'mutual' || rel === 'sharing'); }, isReceiving: function() { var rel = this.get('relationship'); - return (rel == 'mutual' || rel == 'receiving'); + return (rel === 'mutual' || rel === 'receiving'); }, isMutual: function() { - return (this.get('relationship') == 'mutual'); + return (this.get('relationship') === 'mutual'); }, isBlocked: function() { - return (this.get('relationship') == 'blocked'); + return (this.get('relationship') === 'blocked'); }, block: function() { diff --git a/app/assets/javascripts/app/models/post.js b/app/assets/javascripts/app/models/post.js index d2aa388db..30da8f71c 100644 --- a/app/assets/javascripts/app/models/post.js +++ b/app/assets/javascripts/app/models/post.js @@ -4,17 +4,17 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, urlRoot : "/posts", initialize : function() { - this.interactions = new app.models.Post.Interactions(_.extend({post : this}, this.get("interactions"))) - this.delegateToInteractions() + this.interactions = new app.models.Post.Interactions(_.extend({post : this}, this.get("interactions"))); + this.delegateToInteractions(); }, delegateToInteractions : function(){ - this.comments = this.interactions.comments - this.likes = this.interactions.likes + this.comments = this.interactions.comments; + this.likes = this.interactions.likes; this.comment = function(){ - this.interactions.comment.apply(this.interactions, arguments) - } + this.interactions.comment.apply(this.interactions, arguments); + }; }, interactedAt : function() { @@ -22,11 +22,12 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, }, reshare : function(){ - return this._reshare = this._reshare || new app.models.Reshare({root_guid : this.get("guid")}); + this._reshare = this._reshare || new app.models.Reshare({root_guid : this.get("guid")}); + return this._reshare; }, reshareAuthor : function(){ - return this.get("author") + return this.get("author"); }, blockAuthor: function() { @@ -38,7 +39,7 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, }, toggleFavorite : function(options){ - this.set({favorite : !this.get("favorite")}) + this.set({favorite : !this.get("favorite")}); /* guard against attempting to save a model that a user doesn't own */ if(options.save){ this.save() } @@ -46,28 +47,28 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, headline : function() { var headline = this.get("text").trim() - , newlineIdx = headline.indexOf("\n") - return (newlineIdx > 0 ) ? headline.substr(0, newlineIdx) : headline + , newlineIdx = headline.indexOf("\n"); + return (newlineIdx > 0 ) ? headline.substr(0, newlineIdx) : headline; }, body : function(){ var body = this.get("text").trim() - , newlineIdx = body.indexOf("\n") - return (newlineIdx > 0 ) ? body.substr(newlineIdx+1, body.length) : "" + , newlineIdx = body.indexOf("\n"); + return (newlineIdx > 0 ) ? body.substr(newlineIdx+1, body.length) : ""; }, //returns a promise preloadOrFetch : function(){ - var action = app.hasPreload("post") ? this.set(app.parsePreload("post")) : this.fetch() - return $.when(action) + var action = app.hasPreload("post") ? this.set(app.parsePreload("post")) : this.fetch(); + return $.when(action); }, hasPhotos : function(){ - return this.get("photos") && this.get("photos").length > 0 + return this.get("photos") && this.get("photos").length > 0; }, hasText : function(){ - return $.trim(this.get("text")) !== "" + return $.trim(this.get("text")) !== ""; } })); // @license-end diff --git a/app/assets/javascripts/app/models/post/interactions.js b/app/assets/javascripts/app/models/post/interactions.js index 5a157ef32..ce52650a7 100644 --- a/app/assets/javascripts/app/models/post/interactions.js +++ b/app/assets/javascripts/app/models/post/interactions.js @@ -4,137 +4,136 @@ app.models.Post.Interactions = Backbone.Model.extend({ url : function(){ - return this.post.url() + "/interactions" + return this.post.url() + "/interactions"; }, initialize : function(options){ - this.post = options.post - this.comments = new app.collections.Comments(this.get("comments"), {post : this.post}) + this.post = options.post; + this.comments = new app.collections.Comments(this.get("comments"), {post : this.post}); this.likes = new app.collections.Likes(this.get("likes"), {post : this.post}); this.reshares = new app.collections.Reshares(this.get("reshares"), {post : this.post}); }, parse : function(resp){ - this.comments.reset(resp.comments) - this.likes.reset(resp.likes) - this.reshares.reset(resp.reshares) + this.comments.reset(resp.comments); + this.likes.reset(resp.likes); + this.reshares.reset(resp.reshares); var comments = this.comments , likes = this.likes - , reshares = this.reshares + , reshares = this.reshares; return { comments : comments, likes : likes, reshares : reshares, fetched : true - } + }; }, likesCount : function(){ - return (this.get("fetched") ? this.likes.models.length : this.get("likes_count") ) + return (this.get("fetched") ? this.likes.models.length : this.get("likes_count") ); }, resharesCount : function(){ - return this.get("fetched") ? this.reshares.models.length : this.get("reshares_count") + return this.get("fetched") ? this.reshares.models.length : this.get("reshares_count"); }, commentsCount : function(){ - return this.get("fetched") ? this.comments.models.length : this.get("comments_count") + return this.get("fetched") ? this.comments.models.length : this.get("comments_count"); }, userLike : function(){ - return this.likes.select(function(like){ return like.get("author").guid == app.currentUser.get("guid")})[0] + return this.likes.select(function(like){ return like.get("author").guid === app.currentUser.get("guid")})[0]; }, userReshare : function(){ return this.reshares.select(function(reshare){ - return reshare.get("author") && reshare.get("author").guid == app.currentUser.get("guid")})[0] + return reshare.get("author") && reshare.get("author").guid === app.currentUser.get("guid")})[0]; }, toggleLike : function() { if(this.userLike()) { - this.unlike() + this.unlike(); } else { - this.like() + this.like(); } }, like : function() { var self = this; this.likes.create({}, {success : function(){ - self.trigger("change") - self.set({"likes_count" : self.get("likes_count") + 1}) - }}) + self.trigger("change"); + self.set({"likes_count" : self.get("likes_count") + 1}); + }}); - app.instrument("track", "Like") + app.instrument("track", "Like"); }, unlike : function() { var self = this; - this.userLike().destroy({success : function(model, resp) { - self.trigger('change') - self.set({"likes_count" : self.get("likes_count") - 1}) + this.userLike().destroy({success : function() { + self.trigger('change'); + self.set({"likes_count" : self.get("likes_count") - 1}); }}); - app.instrument("track", "Unlike") + app.instrument("track", "Unlike"); }, comment : function (text) { var self = this; this.comments.make(text).fail(function () { - flash = new Diaspora.Widgets.FlashMessages; + var flash = new Diaspora.Widgets.FlashMessages(); flash.render({ success: false, notice: Diaspora.I18n.t("failed_to_post_message") }); }).done(function() { - self.trigger('change') //updates after sync + self.trigger('change'); //updates after sync }); - this.trigger("change") //updates count in an eager manner + this.trigger("change"); //updates count in an eager manner - app.instrument("track", "Comment") + app.instrument("track", "Comment"); }, reshare : function(){ var interactions = this , reshare = this.post.reshare() - , flash = new Diaspora.Widgets.FlashMessages; + , flash = new Diaspora.Widgets.FlashMessages(); reshare.save({}, { - success : function(resp){ + success : function(){ flash.render({ success: true, notice: Diaspora.I18n.t("reshares.successful") }); }, - error: function(resp){ + error: function(){ flash.render({ success: false, notice: Diaspora.I18n.t("reshares.duplicate") }); } }).done(function(){ - interactions.reshares.add(reshare) + interactions.reshares.add(reshare); }).done(function(){ - interactions.trigger("change") + interactions.trigger("change"); }); - app.instrument("track", "Reshare") + app.instrument("track", "Reshare"); }, userCanReshare : function(){ - var isReshare = this.post.get("post_type") == "Reshare" + var isReshare = this.post.get("post_type") === "Reshare" , rootExists = (isReshare ? this.post.get("root") : true) , publicPost = this.post.get("public") - , userIsNotAuthor = this.post.get("author").diaspora_id != app.currentUser.get("diaspora_id") - , userIsNotRootAuthor = rootExists && (isReshare ? this.post.get("root").author.diaspora_id != app.currentUser.get("diaspora_id") : true) + , userIsNotAuthor = this.post.get("author").diaspora_id !== app.currentUser.get("diaspora_id") + , userIsNotRootAuthor = rootExists && (isReshare ? this.post.get("root").author.diaspora_id !== app.currentUser.get("diaspora_id") : true) , notReshared = !this.userReshare(); return publicPost && app.currentUser.authenticated() && userIsNotAuthor && userIsNotRootAuthor && notReshared; } }); // @license-end - diff --git a/app/assets/javascripts/app/models/profile.js b/app/assets/javascripts/app/models/profile.js index 0039e3518..59c543145 100644 --- a/app/assets/javascripts/app/models/profile.js +++ b/app/assets/javascripts/app/models/profile.js @@ -5,19 +5,19 @@ app.models.Profile = Backbone.Model.extend({ }, { preloadOrFetch : function(id){ - return app.hasPreload("person") ? this.preload() : this.findByGuid(id) + return app.hasPreload("person") ? this.preload() : this.findByGuid(id); }, preload : function(){ - var person = new app.models.Profile(app.parsePreload("person")) - person.deferred = $.when(true) - return person + var person = new app.models.Profile(app.parsePreload("person")); + person.deferred = $.when(true); + return person; }, findByGuid : function(personId){ - var person = new app.models.Profile({ id : personId}) - person.deferred = person.fetch() - return person + var person = new app.models.Profile({ id : personId}); + person.deferred = person.fetch(); + return person; } }); // @license-end diff --git a/app/assets/javascripts/app/models/reshare.js b/app/assets/javascripts/app/models/reshare.js index 9fd9de3df..a236f2384 100644 --- a/app/assets/javascripts/app/models/reshare.js +++ b/app/assets/javascripts/app/models/reshare.js @@ -5,15 +5,15 @@ app.models.Reshare = app.models.Post.extend({ rootPost : function(){ this._rootPost = this._rootPost || new app.models.Post(this.get("root")); - return this._rootPost + return this._rootPost; }, reshare : function(){ - return this.rootPost().reshare() + return this.rootPost().reshare(); }, reshareAuthor : function(){ - return this.rootPost().reshareAuthor() + return this.rootPost().reshareAuthor(); } }); // @license-end diff --git a/app/assets/javascripts/app/models/status_message.js b/app/assets/javascripts/app/models/status_message.js index 317b4adc6..f8469662a 100644 --- a/app/assets/javascripts/app/models/status_message.js +++ b/app/assets/javascripts/app/models/status_message.js @@ -17,7 +17,7 @@ app.models.StatusMessage = app.models.Post.extend({ photos : this.photos && this.photos.pluck("id"), services : this.get("services"), poll : this.get("poll") - } + }; } }); // @license-end diff --git a/app/assets/javascripts/app/models/stream.js b/app/assets/javascripts/app/models/stream.js index 2e0c1e799..8ac6c3ebf 100644 --- a/app/assets/javascripts/app/models/stream.js +++ b/app/assets/javascripts/app/models/stream.js @@ -4,7 +4,7 @@ //= require ../collections/photos app.models.Stream = Backbone.Collection.extend({ initialize : function(models, options){ - var collectionClass = app.collections.Posts + var collectionClass = app.collections.Posts; if( options ) { options.collection && (collectionClass = options.collection); options.basePath && (this.streamPath = options.basePath); @@ -14,11 +14,11 @@ app.models.Stream = Backbone.Collection.extend({ collectionOptions :function(){ var order = this.sortOrder(); - return { comparator : function(item) { return -item[order](); } } + return { comparator : function(item) { return -item[order](); } }; }, url : function(){ - return _.any(this.items.models) ? this.timeFilteredPath() : this.basePath() + return _.any(this.items.models) ? this.timeFilteredPath() : this.basePath(); }, _fetchOpts: function(opts) { @@ -35,14 +35,14 @@ app.models.Stream = Backbone.Collection.extend({ }, isFetching : function() { - return (this.deferred && this.deferred.state() == "pending"); + return (this.deferred && this.deferred.state() === "pending"); }, triggerFetchedEvents : function(resp){ this.trigger("fetched", this); // all loaded? var respItems = this.items.parse(resp); - if(respItems && (respItems.author || respItems.length == 0)) { + if(respItems && (respItems.author || respItems.length === 0)) { this.trigger("allItemsLoaded", this); } }, @@ -57,11 +57,11 @@ app.models.Stream = Backbone.Collection.extend({ maxTime: function(){ var lastPost = _.last(this.items.models); - return lastPost[this.sortOrder()]() + return lastPost[this.sortOrder()](); }, sortOrder : function() { - return this.basePath().match(/activity/) ? "interactedAt" : "createdAt" + return this.basePath().match(/activity/) ? "interactedAt" : "createdAt"; }, /* This function is for adding a large number of posts one by one. @@ -71,7 +71,7 @@ app.models.Stream = Backbone.Collection.extend({ * stream for the changes to take effect in the infinite stream view */ add : function(models){ - this.items.add(models) + this.items.add(models); }, /* This function is for adding a single post. It immediately triggers @@ -84,14 +84,13 @@ app.models.Stream = Backbone.Collection.extend({ }, preloadOrFetch : function(){ //hai, plz test me THNX - return $.when(app.hasPreload("stream") ? this.preload() : this.fetch()) + return $.when(app.hasPreload("stream") ? this.preload() : this.fetch()); }, preload : function(){ - this.items.reset(app.parsePreload("stream")) - this.deferred = $.when(true) - this.trigger("fetched") + this.items.reset(app.parsePreload("stream")); + this.deferred = $.when(true); + this.trigger("fetched"); } }); // @license-end - diff --git a/app/assets/javascripts/app/models/stream_aspects.js b/app/assets/javascripts/app/models/stream_aspects.js index a0115887d..e64d3ea5b 100644 --- a/app/assets/javascripts/app/models/stream_aspects.js +++ b/app/assets/javascripts/app/models/stream_aspects.js @@ -3,7 +3,7 @@ app.models.StreamAspects = app.models.Stream.extend({ url : function(){ - return _.any(this.items.models) ? this.timeFilteredPath() : this.basePath() + return _.any(this.items.models) ? this.timeFilteredPath() : this.basePath(); }, initialize : function(models, options){ diff --git a/app/assets/javascripts/app/models/user.js b/app/assets/javascripts/app/models/user.js index 98dc67c01..fabf5817d 100644 --- a/app/assets/javascripts/app/models/user.js +++ b/app/assets/javascripts/app/models/user.js @@ -12,15 +12,15 @@ app.models.User = Backbone.Model.extend({ }, expProfileUrl : function(){ - return "/people/" + app.currentUser.get("guid") + "?ex=true" + return "/people/" + app.currentUser.get("guid") + "?ex=true"; }, isServiceConfigured : function(providerName) { - return _.include(this.get("configured_services"), providerName) + return _.include(this.get("configured_services"), providerName); }, isAuthorOf: function(model) { - return this.authenticated() && model.get("author").id == this.id; + return this.authenticated() && model.get("author").id === this.id; } }); // @license-end diff --git a/app/assets/javascripts/app/pages/contacts.js b/app/assets/javascripts/app/pages/contacts.js index ac4478394..996a5898b 100644 --- a/app/assets/javascripts/app/pages/contacts.js +++ b/app/assets/javascripts/app/pages/contacts.js @@ -60,7 +60,7 @@ app.pages.Contacts = Backbone.View.extend({ $(".header > #aspect_name_form").show(); }, - updateAspectName: function(evt,data,status,xhr){ + updateAspectName: function(evt,data){ $(".header #aspect_name").text(data['name']); $("#aspect_nav [data-aspect-id='"+data['id']+"'] .name").text(data['name']); $(".header > #aspect_name_form").hide(); diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 55d163961..767c9f3a2 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -92,7 +92,7 @@ app.pages.Profile = app.views.Base.extend({ return new view({model: app.stream}); }, - blockPerson: function(evt) { + blockPerson: function() { if( !confirm(Diaspora.I18n.t('ignore_user')) ) return; var block = this.model.block(); @@ -106,7 +106,7 @@ app.pages.Profile = app.views.Base.extend({ return false; }, - unblockPerson: function(evt) { + unblockPerson: function() { var block = this.model.unblock(); block.fail(function() { Diaspora.page.flashMessages.render({ diff --git a/app/assets/javascripts/app/pages/single-post-viewer.js b/app/assets/javascripts/app/pages/single-post-viewer.js index b5af389b3..c0b5f6bf9 100644 --- a/app/assets/javascripts/app/pages/single-post-viewer.js +++ b/app/assets/javascripts/app/pages/single-post-viewer.js @@ -11,8 +11,8 @@ app.pages.SinglePostViewer = app.views.Base.extend({ initialize : function(options) { this.model = new app.models.Post({ id : options.id }); this.model.preloadOrFetch().done(_.bind(this.initViews, this)); - this.model.interactions.fetch() //async, yo, might want to throttle this later. - this.setupLightbox() + this.model.interactions.fetch(); //async, yo, might want to throttle this later. + this.setupLightbox(); }, setupLightbox : function(){ @@ -41,4 +41,3 @@ app.pages.SinglePostViewer = app.views.Base.extend({ }); // @license-end - diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index 76398707c..e700c9cfd 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -75,7 +75,7 @@ app.Router = Backbone.Router.extend({ //below here is oldness - stream : function(page) { + stream : function() { app.stream = new app.models.Stream(); app.stream.fetch(); app.page = new app.views.Stream({model : app.stream}); @@ -113,7 +113,7 @@ app.Router = Backbone.Router.extend({ var followedTagsAction = new app.views.TagFollowingAction( {tagText: decodeURIComponent(name).toLowerCase()} ); - $("#author_info").prepend(followedTagsAction.render().el) + $("#author_info").prepend(followedTagsAction.render().el); app.tags = new app.views.Tags({tagName: name}); } this._hideInactiveStreamLists(); @@ -143,15 +143,15 @@ app.Router = Backbone.Router.extend({ }, _hideInactiveStreamLists: function() { - if(this.aspects_list && Backbone.history.fragment != "aspects") + if(this.aspects_list && Backbone.history.fragment !== "aspects") this.aspects_list.hideAspectsList(); - if(this.followedTagsView && Backbone.history.fragment != "followed_tags") + if(this.followedTagsView && Backbone.history.fragment !== "followed_tags") this.followedTagsView.hideFollowedTags(); }, bookmarklet: function() { - var contents = (window.gon) ? gon.preloads.bookmarklet : {} + var contents = (window.gon) ? gon.preloads.bookmarklet : {}; app.bookmarklet = new app.views.Bookmarklet( _.extend({}, {el: $('#bookmarklet')}, contents) ).render(); @@ -164,4 +164,3 @@ app.Router = Backbone.Router.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views.js b/app/assets/javascripts/app/views.js index 9605dd966..55ec8fffc 100644 --- a/app/assets/javascripts/app/views.js +++ b/app/assets/javascripts/app/views.js @@ -2,12 +2,12 @@ app.views.Base = Backbone.View.extend({ - initialize : function(options) { + initialize : function() { this.setupRenderEvents(); }, presenter : function(){ - return this.defaultPresenter() + return this.defaultPresenter(); }, setupRenderEvents : function(){ @@ -18,7 +18,7 @@ app.views.Base = Backbone.View.extend({ }, defaultPresenter : function(){ - var modelJson = this.model && this.model.attributes ? _.clone(this.model.attributes) : {} + var modelJson = this.model && this.model.attributes ? _.clone(this.model.attributes) : {}; return _.extend(modelJson, { current_user : app.currentUser.attributes, @@ -27,19 +27,19 @@ app.views.Base = Backbone.View.extend({ }, render : function() { - this.renderTemplate() - this.renderSubviews() - this.renderPluginWidgets() - this.removeTooltips() + this.renderTemplate(); + this.renderSubviews(); + this.renderPluginWidgets(); + this.removeTooltips(); - return this + return this; }, renderTemplate : function(){ - var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter - this.template = HandlebarsTemplates[this.templateName+"_tpl"] + var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter; + this.template = HandlebarsTemplates[this.templateName+"_tpl"]; if(!this.template) { - console.log(this.templateName ? ("no template for " + this.templateName) : "no templateName specified") + console.log(this.templateName ? ("no template for " + this.templateName) : "no templateName specified"); return; } @@ -58,12 +58,12 @@ app.views.Base = Backbone.View.extend({ renderSubviews : function(){ var self = this; _.each(this.subviews, function(property, selector){ - var view = _.isFunction(self[property]) ? self[property]() : self[property] + var view = _.isFunction(self[property]) ? self[property]() : self[property]; if(view) { - self.$(selector).html(view.render().el) + self.$(selector).html(view.render().el); view.delegateEvents(); } - }) + }); }, renderPluginWidgets : function() { @@ -76,16 +76,16 @@ app.views.Base = Backbone.View.extend({ }, setFormAttrs : function(){ - this.model.set(_.inject(this.formAttrs, _.bind(setValueFromField, this), {})) - function setValueFromField(memo, attribute, selector){ if(attribute.slice("-2") === "[]") { - memo[attribute.slice(0, attribute.length - 2)] = _.pluck(this.$el.find(selector).serializeArray(), "value") + memo[attribute.slice(0, attribute.length - 2)] = _.pluck(this.$el.find(selector).serializeArray(), "value"); } else { memo[attribute] = this.$el.find(selector).val() || this.$el.find(selector).text(); } - return memo + return memo; } + + this.model.set(_.inject(this.formAttrs, _.bind(setValueFromField, this), {})); }, report: function(evt) { @@ -104,13 +104,13 @@ app.views.Base = Backbone.View.extend({ var report = new app.models.Report(); report.save(data, { - success: function(model, response) { + success: function() { Diaspora.page.flashMessages.render({ success: true, notice: Diaspora.I18n.t('report.status.created') }); }, - error: function(model, response) { + error: function() { Diaspora.page.flashMessages.render({ success: false, notice: Diaspora.I18n.t('report.status.exists') @@ -132,7 +132,7 @@ app.views.Base = Backbone.View.extend({ }) .fail(function() { self.$el.removeClass('deleting'); - var flash = new Diaspora.Widgets.FlashMessages; + var flash = new Diaspora.Widgets.FlashMessages(); flash.render({ success: false, notice: Diaspora.I18n.t('failed_to_remove') @@ -142,7 +142,7 @@ app.views.Base = Backbone.View.extend({ }, avatars: { - fallback: function(evt) { + fallback: function() { $(this).attr("src", ImagePaths.get("user/default.png")); }, selector: "img.avatar" @@ -163,4 +163,3 @@ app.views.StaticContentView = app.views.Base.extend({ }, }); // @license-end - diff --git a/app/assets/javascripts/app/views/aspect_membership_blueprint_view.js b/app/assets/javascripts/app/views/aspect_membership_blueprint_view.js index cf0f59e2c..d7e95bdac 100644 --- a/app/assets/javascripts/app/views/aspect_membership_blueprint_view.js +++ b/app/assets/javascripts/app/views/aspect_membership_blueprint_view.js @@ -75,7 +75,7 @@ app.views.AspectMembershipBlueprint = Backbone.View.extend({ // the user didn't have this person in any aspects before, congratulate them // on their newly found friendship ;) - if( this.dropdown.find('li.selected').length == 0 ) { + if( this.dropdown.find('li.selected').length === 0 ) { var msg = Diaspora.I18n.t('aspect_dropdown.started_sharing_with', { 'name': this._name() }); Diaspora.page.flashMessages.render({ 'success':true, 'notice':msg }); } @@ -121,7 +121,7 @@ app.views.AspectMembershipBlueprint = Backbone.View.extend({ // we just removed the last aspect, inform the user with a flash message // that he is no longer sharing with that person - if( this.dropdown.find('li.selected').length == 0 ) { + if( this.dropdown.find('li.selected').length === 0 ) { var msg = Diaspora.I18n.t('aspect_dropdown.stopped_sharing_with', { 'name': this._name() }); Diaspora.page.flashMessages.render({ 'success':true, 'notice':msg }); } @@ -143,7 +143,7 @@ app.views.AspectMembershipBlueprint = Backbone.View.extend({ var aspects_cnt = this.dropdown.find('li.selected').length; var txt; - if( aspects_cnt == 0 ) { + if( aspects_cnt === 0 ) { btn.removeClass('in_aspects'); txt = Diaspora.I18n.t('aspect_dropdown.toggle.zero'); } else { @@ -157,11 +157,11 @@ app.views.AspectMembershipBlueprint = Backbone.View.extend({ _pluralSummaryTxt: function(cnt) { var all_aspects_cnt = this.dropdown.find('li').length; - if( cnt == 1 ) { + if( cnt === 1 ) { return this.dropdown.find('li.selected').first().text(); } - if( cnt == all_aspects_cnt ) { + if( cnt === all_aspects_cnt ) { return Diaspora.I18n.t('aspect_dropdown.all_aspects'); } diff --git a/app/assets/javascripts/app/views/aspect_membership_view.js b/app/assets/javascripts/app/views/aspect_membership_view.js index 8348f26b6..d22452421 100644 --- a/app/assets/javascripts/app/views/aspect_membership_view.js +++ b/app/assets/javascripts/app/views/aspect_membership_view.js @@ -75,7 +75,7 @@ app.views.AspectMembership = app.views.AspectsDropdown.extend({ // the user didn't have this person in any aspects before, congratulate them // on their newly found friendship ;) - if( this.dropdown.find('li.selected').length == 0 ) { + if( this.dropdown.find('li.selected').length === 0 ) { var msg = Diaspora.I18n.t('aspect_dropdown.started_sharing_with', { 'name': this._name() }); Diaspora.page.flashMessages.render({ 'success':true, 'notice':msg }); } @@ -120,7 +120,7 @@ app.views.AspectMembership = app.views.AspectsDropdown.extend({ // we just removed the last aspect, inform the user with a flash message // that he is no longer sharing with that person - if( this.dropdown.find('li.selected').length == 0 ) { + if( this.dropdown.find('li.selected').length === 0 ) { var msg = Diaspora.I18n.t('aspect_dropdown.stopped_sharing_with', { 'name': this._name() }); Diaspora.page.flashMessages.render({ 'success':true, 'notice':msg }); } diff --git a/app/assets/javascripts/app/views/aspect_view.js b/app/assets/javascripts/app/views/aspect_view.js index 982301370..3fba4865c 100644 --- a/app/assets/javascripts/app/views/aspect_view.js +++ b/app/assets/javascripts/app/views/aspect_view.js @@ -12,7 +12,7 @@ app.views.Aspect = app.views.Base.extend({ }, toggleAspect: function(evt) { - if (evt) { evt.preventDefault(); }; + if (evt) { evt.preventDefault(); } this.model.toggleSelected(); app.router.aspects_stream(); @@ -21,8 +21,7 @@ app.views.Aspect = app.views.Base.extend({ presenter : function() { return _.extend(this.defaultPresenter(), { aspect : this.model - }) + }); } }); // @license-end - diff --git a/app/assets/javascripts/app/views/aspects_dropdown_view.js b/app/assets/javascripts/app/views/aspects_dropdown_view.js index 65c5c8e00..70e446704 100644 --- a/app/assets/javascripts/app/views/aspects_dropdown_view.js +++ b/app/assets/javascripts/app/views/aspects_dropdown_view.js @@ -32,12 +32,12 @@ app.views.AspectsDropdown = app.views.Base.extend({ selectedAspects = this.$(".dropdown-menu > li.selected").length, buttonText; - if (selectedAspects == 0) { + if (selectedAspects === 0) { button.removeClass(inAspectClass).addClass('btn-default'); buttonText = Diaspora.I18n.t("aspect_dropdown.select_aspects"); } else { button.removeClass('btn-default').addClass(inAspectClass); - if (selectedAspects == 1) { + if (selectedAspects === 1) { buttonText = this.$(".dropdown-menu > li.selected .text").first().text(); } else { buttonText = Diaspora.I18n.t("aspect_dropdown.toggle", { count: selectedAspects.toString() }); diff --git a/app/assets/javascripts/app/views/aspects_list_view.js b/app/assets/javascripts/app/views/aspects_list_view.js index 60416567c..6af4d41cc 100644 --- a/app/assets/javascripts/app/views/aspects_list_view.js +++ b/app/assets/javascripts/app/views/aspects_list_view.js @@ -29,7 +29,7 @@ app.views.AspectsList = app.views.Base.extend({ }, toggleAll: function(evt) { - if (evt) { evt.preventDefault(); }; + if (evt) { evt.preventDefault(); } if (this.collection.allSelected()) { this.collection.deselectAll(); @@ -68,6 +68,5 @@ app.views.AspectsList = app.views.Base.extend({ hideAspectsList: function() { this.$el.empty(); }, -}) +}); // @license-end - diff --git a/app/assets/javascripts/app/views/bookmarklet_view.js b/app/assets/javascripts/app/views/bookmarklet_view.js index e3757719a..c8e982fc3 100644 --- a/app/assets/javascripts/app/views/bookmarklet_view.js +++ b/app/assets/javascripts/app/views/bookmarklet_view.js @@ -30,18 +30,18 @@ app.views.Bookmarklet = Backbone.View.extend({ return contents; }, - _postSubmit: function(evt) { + _postSubmit: function() { this.$('h4').text(Diaspora.I18n.t('bookmarklet.post_submit')); }, - _postSuccess: function(evt) { + _postSuccess: function() { this.$('h4').text(Diaspora.I18n.t('bookmarklet.post_success')); app.publisher.close(); this.$("#publisher").addClass("hidden"); _.delay(window.close, 2000); }, - _postError: function(evt) { + _postError: function() { this.$('h4').text(Diaspora.I18n.t('bookmarklet.post_something')); } }); diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index 32c349e8b..73bc7feda 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -39,7 +39,7 @@ app.views.CommentStream = app.views.Base.extend({ moreCommentsCount : (this.model.interactions.commentsCount() - 3), showExpandCommentsLink : (this.model.interactions.commentsCount() > 3), commentsCount : this.model.interactions.commentsCount() - }) + }); }, createComment: function(evt) { @@ -57,8 +57,8 @@ app.views.CommentStream = app.views.Base.extend({ }, keyDownOnCommentBox: function(evt) { - if(evt.keyCode == 13 && evt.ctrlKey) { - this.$("form").submit() + if(evt.keyCode === 13 && evt.ctrlKey) { + this.$("form").submit(); return false; } }, @@ -66,14 +66,14 @@ app.views.CommentStream = app.views.Base.extend({ appendComment: function(comment) { // Set the post as the comment's parent, so we can check // on post ownership in the Comment view. - comment.set({parent : this.model.toJSON()}) + comment.set({parent : this.model.toJSON()}); this.$(".comments").append(new app.views.Comment({ model: comment }).render().el); }, - commentTextareaFocused: function(evt){ + commentTextareaFocused: function(){ this.$("form").removeClass('hidden').addClass("open"); }, @@ -83,20 +83,18 @@ app.views.CommentStream = app.views.Base.extend({ expandComments: function(evt){ if(evt){ evt.preventDefault(); } - - self = this; + var self = this; this.model.comments.fetch({ success : function(resp){ self.model.set({ comments : resp.models, all_comments_loaded : true - }) + }); - self.model.trigger("commentsExpanded", self) + self.model.trigger("commentsExpanded", self); } }); } }); // @license-end - diff --git a/app/assets/javascripts/app/views/comment_view.js b/app/assets/javascripts/app/views/comment_view.js index f99bd7f66..7f74d1146 100644 --- a/app/assets/javascripts/app/views/comment_view.js +++ b/app/assets/javascripts/app/views/comment_view.js @@ -13,27 +13,27 @@ app.views.Comment = app.views.Content.extend({ }, initialize : function(options){ - this.templateName = options.templateName || this.templateName - this.model.on("change", this.render, this) + this.templateName = options.templateName || this.templateName; + this.model.on("change", this.render, this); }, presenter : function() { return _.extend(this.defaultPresenter(), { canRemove: this.canRemove(), text : app.helpers.textFormatter(this.model.get("text")) - }) + }); }, ownComment : function() { - return app.currentUser.authenticated() && this.model.get("author").diaspora_id == app.currentUser.get("diaspora_id") + return app.currentUser.authenticated() && this.model.get("author").diaspora_id === app.currentUser.get("diaspora_id"); }, postOwner : function() { - return app.currentUser.authenticated() && this.model.get("parent").author.diaspora_id == app.currentUser.get("diaspora_id") + return app.currentUser.authenticated() && this.model.get("parent").author.diaspora_id === app.currentUser.get("diaspora_id"); }, canRemove : function() { - return app.currentUser.authenticated() && (this.ownComment() || this.postOwner()) + return app.currentUser.authenticated() && (this.ownComment() || this.postOwner()); } }); @@ -42,4 +42,3 @@ app.views.ExpandedComment = app.views.Comment.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views/contact_view.js b/app/assets/javascripts/app/views/contact_view.js index 4fd2d7efb..2ac8dc772 100644 --- a/app/assets/javascripts/app/views/contact_view.js +++ b/app/assets/javascripts/app/views/contact_view.js @@ -21,7 +21,7 @@ app.views.Contact = app.views.Base.extend({ postRenderTemplate: function() { var self = this; var dropdownEl = this.$('.aspect_membership_dropdown.placeholder'); - if( dropdownEl.length == 0 ) { + if( dropdownEl.length === 0 ) { return; } @@ -44,10 +44,10 @@ app.views.Contact = app.views.Base.extend({ 'person_id': this.model.get('person_id'), 'aspect_id': app.aspect.get('id') },{ - success: function(model,response){ + success: function(){ self.render(); }, - error: function(model,response){ + error: function(){ var msg = Diaspora.I18n.t('contacts.error_add', { 'name': self.model.get('person').name }); Diaspora.page.flashMessages.render({ 'success':false, 'notice':msg }); } @@ -57,12 +57,12 @@ app.views.Contact = app.views.Base.extend({ removeContactFromAspect: function(){ var self = this; this.model.aspect_memberships - .find(function(membership){ return membership.get('aspect').id == app.aspect.id; }) + .find(function(membership){ return membership.get('aspect').id === app.aspect.id; }) .destroy({ - success: function(model,response){ + success: function(){ self.render(); }, - error: function(model,response){ + error: function(){ var msg = Diaspora.I18n.t('contacts.error_remove', { 'name': self.model.get('person').name }); Diaspora.page.flashMessages.render({ 'success':false, 'notice':msg }); } diff --git a/app/assets/javascripts/app/views/content_view.js b/app/assets/javascripts/app/views/content_view.js index f5e7061e5..a7cbc8f63 100644 --- a/app/assets/javascripts/app/views/content_view.js +++ b/app/assets/javascripts/app/views/content_view.js @@ -16,13 +16,13 @@ app.views.Content = app.views.Base.extend({ largePhoto : function() { - var photos = this.model.get("photos") - if(!photos || photos.length == 0) { return } - return photos[0] + var photos = this.model.get("photos"); + if(!photos || photos.length === 0) { return } + return photos[0]; }, smallPhotos : function() { - var photos = this.model.get("photos") + var photos = this.model.get("photos"); if(!photos || photos.length < 2) { return } photos.splice(0, 1); // remove first photo as it is already shown as largePhoto return photos; @@ -49,10 +49,10 @@ app.views.Content = app.views.Base.extend({ , oembed = elem.find(".oembed") , opengraph = elem.find(".opengraph") , addHeight = 0; - if($.trim(oembed.html()) != "") { + if($.trim(oembed.html()) !== "") { addHeight += oembed.height(); } - if($.trim(opengraph.html()) != "") { + if($.trim(opengraph.html()) !== "") { addHeight += opengraph.height(); } @@ -71,7 +71,7 @@ app.views.Content = app.views.Base.extend({ }, postRenderTemplate : function(){ - _.defer(_.bind(this.collapseOversized, this)) + _.defer(_.bind(this.collapseOversized, this)); } }); @@ -95,15 +95,15 @@ app.views.OEmbed = app.views.Base.extend({ }, presenter:function () { - o_embed_cache = this.model.get("o_embed_cache") + var o_embed_cache = this.model.get("o_embed_cache"); if(o_embed_cache) { - typemodel = { rich: false, photo: false, video: false, link: false } - typemodel[o_embed_cache.data.type] = true - o_embed_cache.data.types = typemodel + var typemodel = { rich: false, photo: false, video: false, link: false }; + typemodel[o_embed_cache.data.type] = true; + o_embed_cache.data.types = typemodel; } return _.extend(this.defaultPresenter(), { o_embed_html : app.helpers.oEmbed.html(o_embed_cache) - }) + }); }, showOembedContent : function (evt) { @@ -137,4 +137,3 @@ app.views.SPVOpenGraph = app.views.OpenGraph.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views/faq_question_view.js b/app/assets/javascripts/app/views/faq_question_view.js index a4a2303b3..f32969e32 100644 --- a/app/assets/javascripts/app/views/faq_question_view.js +++ b/app/assets/javascripts/app/views/faq_question_view.js @@ -28,8 +28,8 @@ app.views.FaqQuestionView = app.views.Base.extend({ }, toggled: function(e) { - el = $(e.target); - parent = el.parents('.question'); + var el = $(e.target); + var parent = el.parents('.question'); parent.children('.answer').toggle(); parent.toggleClass('opened').toggleClass('collapsed'); diff --git a/app/assets/javascripts/app/views/feedback_view.js b/app/assets/javascripts/app/views/feedback_view.js index 200a11830..938469bbb 100644 --- a/app/assets/javascripts/app/views/feedback_view.js +++ b/app/assets/javascripts/app/views/feedback_view.js @@ -18,11 +18,11 @@ app.views.Feedback = app.views.Base.extend({ initialize : function() { this.model.interactions.on('change', this.render, this); - this.initViews && this.initViews() // I don't know why this was failing with $.noop... :( + this.initViews && this.initViews(); // I don't know why this was failing with $.noop... :( }, presenter : function() { - var interactions = this.model.interactions + var interactions = this.model.interactions; return _.extend(this.defaultPresenter(),{ commentsCount : interactions.commentsCount(), @@ -31,7 +31,7 @@ app.views.Feedback = app.views.Base.extend({ userCanReshare : interactions.userCanReshare(), userLike : interactions.userLike(), userReshare : interactions.userReshare() - }) + }); }, toggleLike: function(evt) { @@ -85,4 +85,3 @@ app.views.Feedback = app.views.Base.extend({ }, }); // @license-end - diff --git a/app/assets/javascripts/app/views/header_view.js b/app/assets/javascripts/app/views/header_view.js index a526c5fcd..eaf6e9275 100644 --- a/app/assets/javascripts/app/views/header_view.js +++ b/app/assets/javascripts/app/views/header_view.js @@ -12,7 +12,7 @@ app.views.Header = app.views.Base.extend({ "focusout #q": "toggleSearchActive" }, - initialize : function(options) { + initialize : function() { $(document.body).click($.proxy(this.hideDropdown, this)); return this; }, @@ -40,7 +40,7 @@ app.views.Header = app.views.Base.extend({ toggleSearchActive: function(ev) { // jQuery produces two events for focus/blur (for bubbling) // don't rely on which event arrives first, by allowing for both variants - var is_active = (_.indexOf(['focus','focusin'], ev.type) != -1); + var is_active = (_.indexOf(['focus','focusin'], ev.type) !== -1); $(ev.target).toggleClass('active', is_active); return false; } diff --git a/app/assets/javascripts/app/views/help_section_view.js b/app/assets/javascripts/app/views/help_section_view.js index 0d17b318f..432179461 100644 --- a/app/assets/javascripts/app/views/help_section_view.js +++ b/app/assets/javascripts/app/views/help_section_view.js @@ -26,8 +26,8 @@ app.views.HelpSectionView = app.views.StaticContentView.extend({ }, toggled: function(e) { - el = $(e.target); - parent = el.parents('.question'); + var el = $(e.target); + var parent = el.parents('.question'); parent.children('.answer.hideable').toggle(); parent.toggleClass('opened').toggleClass('collapsed'); diff --git a/app/assets/javascripts/app/views/help_view.js b/app/assets/javascripts/app/views/help_view.js index fa93966a0..4df60c68f 100644 --- a/app/assets/javascripts/app/views/help_view.js +++ b/app/assets/javascripts/app/views/help_view.js @@ -12,7 +12,7 @@ app.views.Help = app.views.StaticContentView.extend({ "click .faq-link-keyboard-shortcuts" : "keyboardShortcuts", }, - initialize : function(options) { + initialize : function() { this.GETTING_HELP_SUBS = { getting_started_a: { tutorial_series: this.linkHtml("http://diasporafoundation.org/getting_started/sign_up", Diaspora.I18n.t( 'getting_started_tutorial' )) }, get_support_a_website: { link: this.linkHtml("https://diasporafoundation.org/", Diaspora.I18n.t( 'foundation_website' ))}, @@ -52,7 +52,7 @@ app.views.Help = app.views.StaticContentView.extend({ title_tags: Diaspora.I18n.t( 'tags.title' ), title_keyboard_shortcuts: Diaspora.I18n.t( 'keyboard_shortcuts.title' ), title_miscellaneous: Diaspora.I18n.t( 'miscellaneous.title' ), - } + }; return this; }, @@ -124,8 +124,8 @@ app.views.Help = app.views.StaticContentView.extend({ renderStaticSection: function(section, template, subs) { this.clearItems(); - data = $.extend(Diaspora.I18n.resolve(section), { className: section }); - help_section = new app.views.HelpSectionView({ + var data = $.extend(Diaspora.I18n.resolve(section), { className: section }); + var help_section = new app.views.HelpSectionView({ template: template, data: data, subs: subs @@ -173,4 +173,3 @@ app.views.Help = app.views.StaticContentView.extend({ }, }); // @license-end - diff --git a/app/assets/javascripts/app/views/hovercard_view.js b/app/assets/javascripts/app/views/hovercard_view.js index 4cb5c6356..6e3ad43e8 100644 --- a/app/assets/javascripts/app/views/hovercard_view.js +++ b/app/assets/javascripts/app/views/hovercard_view.js @@ -29,7 +29,7 @@ app.views.Hovercard = app.views.Base.extend({ }, postRenderTemplate: function() { - this.$el.appendTo($('body')) + this.$el.appendTo($('body')); }, deactivate: function() { @@ -41,7 +41,7 @@ app.views.Hovercard = app.views.Base.extend({ }, _mouseenterHandler: function(event) { - if( this.active == false || + if( this.active === false || $.contains(this.el, event.target) ) { return false; } var el = $(event.target); @@ -49,7 +49,7 @@ app.views.Hovercard = app.views.Base.extend({ el = el.parents('a'); } - if( el.attr('href').indexOf('/people') == -1 ) { + if( el.attr('href').indexOf('/people') === -1 ) { // can't fetch data from that URL, aborting return false; } @@ -60,7 +60,7 @@ app.views.Hovercard = app.views.Base.extend({ }, _mouseleaveHandler: function(event) { - if( this.active == false || + if( this.active === false || $.contains(this.el, event.relatedTarget) ) { return false; } this.show_me = false; @@ -95,7 +95,7 @@ app.views.Hovercard = app.views.Base.extend({ var self = this; $.get(href, function(person){ - if( !person || person.length == 0 ) { + if( !person || person.length === 0 ) { throw new Error("received data is not a person object"); } @@ -123,13 +123,13 @@ app.views.Hovercard = app.views.Base.extend({ // TODO render me client side!!! var href = this.href(); href += "/aspect_membership_button"; - if(gon.bootstrap == true){ + if(gon.bootstrap === true){ href += "?bootstrap=true"; } $.get(href, function(response) { self.dropdown_container.html(response); }); - var aspect_membership = new app.views.AspectMembership({el: self.dropdown_container}); + new app.views.AspectMembership({el: self.dropdown_container}); }, _positionHovercard: function() { @@ -143,4 +143,3 @@ app.views.Hovercard = app.views.Base.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views/infinite_stream_view.js b/app/assets/javascripts/app/views/infinite_stream_view.js index 59e493ee6..bac823ccc 100644 --- a/app/assets/javascripts/app/views/infinite_stream_view.js +++ b/app/assets/javascripts/app/views/infinite_stream_view.js @@ -34,7 +34,7 @@ app.views.InfScroll = app.views.Base.extend({ createPostView : function(post){ var postView = new this.postClass({ model: post, stream: this.stream }); - if (this.collection.at(0).id == post.id) { + if (this.collection.at(0).id === post.id) { // post is first in collection - insert view at top of the list this.postViews.unshift(postView); } else { @@ -46,7 +46,7 @@ app.views.InfScroll = app.views.Base.extend({ // called for every item inserted in this.collection addPostView : function(post) { var el = this.createPostView(post).render().el; - if (this.collection.at(0).id == post.id) { + if (this.collection.at(0).id === post.id) { this.prependedPosts.insertBefore(el, this.prependedPosts.firstChild); } else { this.appendedPosts.appendChild(el); @@ -58,7 +58,7 @@ app.views.InfScroll = app.views.Base.extend({ }, renderTemplate : function(){ - this.renderInitialPosts() + this.renderInitialPosts(); }, renderInitialPosts : function(){ @@ -66,7 +66,7 @@ app.views.InfScroll = app.views.Base.extend({ var els = document.createDocumentFragment(); this.stream.items.each(_.bind(function(post){ els.appendChild(this.createPostView(post).render().el); - }, this)) + }, this)); this.$el.html(els); }, @@ -78,7 +78,7 @@ app.views.InfScroll = app.views.Base.extend({ }, showLoader: function(){ - $("#paginate .loader").removeClass("hidden") + $("#paginate .loader").removeClass("hidden"); }, finishedAdding: function() { @@ -108,4 +108,3 @@ app.views.InfScroll = app.views.Base.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views/likes_info_view.js b/app/assets/javascripts/app/views/likes_info_view.js index b85be03ed..a672645dd 100644 --- a/app/assets/javascripts/app/views/likes_info_view.js +++ b/app/assets/javascripts/app/views/likes_info_view.js @@ -19,13 +19,12 @@ app.views.LikesInfo = app.views.Base.extend({ likes : this.model.interactions.likes.toJSON(), likesCount : this.model.interactions.likesCount(), likes_fetched : this.model.interactions.get("fetched"), - }) + }); }, showAvatars : function(evt){ if(evt) { evt.preventDefault() } - this.model.interactions.fetch() + this.model.interactions.fetch(); } }); // @license-end - diff --git a/app/assets/javascripts/app/views/location_view.js b/app/assets/javascripts/app/views/location_view.js index dfb4a5cfe..bf7ff3811 100644 --- a/app/assets/javascripts/app/views/location_view.js +++ b/app/assets/javascripts/app/views/location_view.js @@ -13,10 +13,10 @@ app.views.Location = Backbone.View.extend({ $(this.el).append('delete location'); }, - getLocation: function(e){ - element = this.el; + getLocation: function(){ + var element = this.el; - locator = new OSM.Locator(); + var locator = new OSM.Locator(); locator.getAddress(function(address, latlng){ $(element).html(''); $('#location_coords').val(latlng.latitude + "," + latlng.longitude); diff --git a/app/assets/javascripts/app/views/notifications_view.js b/app/assets/javascripts/app/views/notifications_view.js index 0914440bf..bffd22c09 100644 --- a/app/assets/javascripts/app/views/notifications_view.js +++ b/app/assets/javascripts/app/views/notifications_view.js @@ -12,8 +12,8 @@ app.views.Notifications = Backbone.View.extend({ }, toggleUnread: function(evt) { - note = $(evt.target).closest(".stream_element"); - unread = note.hasClass("unread"); + var note = $(evt.target).closest(".stream_element"); + var unread = note.hasClass("unread"); if (unread) { this.setRead(note.data("guid")); @@ -44,17 +44,17 @@ app.views.Notifications = Backbone.View.extend({ }, clickSuccess: function(data) { - type = $('.stream_element[data-guid=' + data["guid"] + ']').data('type'); + var type = $('.stream_element[data-guid=' + data["guid"] + ']').data('type'); this.updateView(data["guid"], type, data["unread"]); }, updateView: function(guid, type, unread) { - change = unread ? 1 : -1; - all_notes = $('ul.nav > li:eq(0) .badge'); - type_notes = $('ul.nav > li[data-type=' + type + '] .badge'); - header_badge = $('#notification_badge .badge_count'); + var change = unread ? 1 : -1, + all_notes = $('ul.nav > li:eq(0) .badge'), + type_notes = $('ul.nav > li[data-type=' + type + '] .badge'), + header_badge = $('#notification_badge .badge_count'), + note = $('.stream_element[data-guid=' + guid + ']'); - note = $('.stream_element[data-guid=' + guid + ']'); if(unread) { note.removeClass("read").addClass("unread"); $(".unread-toggle .entypo", note) @@ -93,4 +93,3 @@ app.views.Notifications = Backbone.View.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views/photo_viewer.js b/app/assets/javascripts/app/views/photo_viewer.js index e2b8e939f..d9a587400 100644 --- a/app/assets/javascripts/app/views/photo_viewer.js +++ b/app/assets/javascripts/app/views/photo_viewer.js @@ -4,8 +4,7 @@ app.views.PhotoViewer = app.views.Base.extend({ templateName : "photo-viewer", presenter : function(){ - return { photos : this.model.get("photos") } //json array of attributes, not backbone models, yet. + return { photos : this.model.get("photos") }; //json array of attributes, not backbone models, yet. } }); // @license-end - diff --git a/app/assets/javascripts/app/views/photos_view.js b/app/assets/javascripts/app/views/photos_view.js index bbba5766e..5d5969ef1 100644 --- a/app/assets/javascripts/app/views/photos_view.js +++ b/app/assets/javascripts/app/views/photos_view.js @@ -1,15 +1,15 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later app.views.Photos = app.views.InfScroll.extend({ - initialize : function(options) { + initialize : function() { this.stream = this.model; this.collection = this.stream.items; // viable for extraction this.stream.fetch(); - this.setupLightbox() - this.setupInfiniteScroll() + this.setupLightbox(); + this.setupInfiniteScroll(); }, postClass : app.views.Photo, @@ -24,4 +24,3 @@ app.views.Photos = app.views.InfScroll.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views/poll_view.js b/app/assets/javascripts/app/views/poll_view.js index ae6406bef..1ec3d1869 100644 --- a/app/assets/javascripts/app/views/poll_view.js +++ b/app/assets/javascripts/app/views/poll_view.js @@ -8,7 +8,7 @@ app.views.Poll = app.views.Base.extend({ "click .toggle_result" : "toggleResult" }, - initialize: function(options) { + initialize: function() { this.model.bind('change', this.render, this); }, diff --git a/app/assets/javascripts/app/views/post_view.js b/app/assets/javascripts/app/views/post_view.js index 195b468e1..726055bb7 100644 --- a/app/assets/javascripts/app/views/post_view.js +++ b/app/assets/javascripts/app/views/post_view.js @@ -6,12 +6,11 @@ app.views.Post = app.views.Base.extend({ authorIsCurrentUser : app.currentUser.isAuthorOf(this.model), showPost : this.showPost(), text : app.helpers.textFormatter(this.model.get("text"), this.model.get("mentioned_people")) - }) + }); }, showPost : function() { - return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw") + return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw"); } }); // @license-end - diff --git a/app/assets/javascripts/app/views/profile_header_view.js b/app/assets/javascripts/app/views/profile_header_view.js index 35bcded56..e44300b29 100644 --- a/app/assets/javascripts/app/views/profile_header_view.js +++ b/app/assets/javascripts/app/views/profile_header_view.js @@ -43,7 +43,7 @@ app.views.ProfileHeader = app.views.Base.extend({ postRenderTemplate: function() { var self = this; var dropdownEl = this.$('.aspect_membership_dropdown.placeholder'); - if( dropdownEl.length == 0 ) { + if( dropdownEl.length === 0 ) { return; } diff --git a/app/assets/javascripts/app/views/publisher/aspect_selector_blueprint_view.js b/app/assets/javascripts/app/views/publisher/aspect_selector_blueprint_view.js index 9ae3a9785..03f15f93d 100644 --- a/app/assets/javascripts/app/views/publisher/aspect_selector_blueprint_view.js +++ b/app/assets/javascripts/app/views/publisher/aspect_selector_blueprint_view.js @@ -9,6 +9,7 @@ // Provides the ability to specify the visibility of posted content as public // or limited to selected aspects app.views.PublisherAspectSelectorBlueprint = Backbone.View.extend({ + /* global AspectsDropdown */ events: { "click .dropdown_list > li": "toggleAspect" @@ -21,7 +22,6 @@ app.views.PublisherAspectSelectorBlueprint = Backbone.View.extend({ // event handler for aspect selection toggleAspect: function(evt) { var el = $(evt.target); - var btn = el.parent('.dropdown').find('.button'); // visually toggle the aspect selection if( el.is('.radio') ) { diff --git a/app/assets/javascripts/app/views/publisher/aspect_selector_view.js b/app/assets/javascripts/app/views/publisher/aspect_selector_view.js index 1926f5b73..7145de4ad 100644 --- a/app/assets/javascripts/app/views/publisher/aspect_selector_view.js +++ b/app/assets/javascripts/app/views/publisher/aspect_selector_view.js @@ -35,7 +35,7 @@ app.views.PublisherAspectSelector = app.views.AspectsDropdown.extend({ // update the globe or lock icon var icon = this.$('#visibility-icon'); - if (target.find('.text').text().trim() == Diaspora.I18n.t('stream.public')) { + if (target.find('.text').text().trim() === Diaspora.I18n.t('stream.public')) { icon.removeClass('lock'); icon.addClass('globe'); } else { diff --git a/app/assets/javascripts/app/views/publisher/getting_started_view.js b/app/assets/javascripts/app/views/publisher/getting_started_view.js index a5896b8ad..6d36a83a7 100644 --- a/app/assets/javascripts/app/views/publisher/getting_started_view.js +++ b/app/assets/javascripts/app/views/publisher/getting_started_view.js @@ -65,7 +65,7 @@ app.views.PublisherGettingStarted = Backbone.View.extend({ var close = $(popup).find('.close'); close.click(function() { - if( $('.popover').length==1 ) { + if( $('.popover').length === 1 ) { $.get('/getting_started_completed', {success: function() { $("#welcome-to-diaspora, #welcome-to-diaspora~br").remove(); }}); diff --git a/app/assets/javascripts/app/views/publisher/poll_creator_view.js b/app/assets/javascripts/app/views/publisher/poll_creator_view.js index 3f49cbc17..e1c31fb2b 100644 --- a/app/assets/javascripts/app/views/publisher/poll_creator_view.js +++ b/app/assets/javascripts/app/views/publisher/poll_creator_view.js @@ -66,8 +66,7 @@ app.views.PublisherPollCreator = app.views.Base.extend({ this.$('input').val(''); }, - validate: function(evt){ - var input = $(evt.target); + validate: function(){ this.validatePoll(); this.trigger('change'); }, @@ -98,7 +97,7 @@ app.views.PublisherPollCreator = app.views.Base.extend({ // Validate the input unless it is the last one, or there are only the // question field and two options if( i !== inputs.length - 1 || inputs.length <= 3) { - if(_this.validateInput($(input)) == false) pollValid = false; + if(_this.validateInput($(input)) === false) pollValid = false; } }); diff --git a/app/assets/javascripts/app/views/publisher/uploader_view.js b/app/assets/javascripts/app/views/publisher/uploader_view.js index 39ef27433..00580f57a 100644 --- a/app/assets/javascripts/app/views/publisher/uploader_view.js +++ b/app/assets/javascripts/app/views/publisher/uploader_view.js @@ -47,7 +47,7 @@ app.views.PublisherUploader = Backbone.View.extend({ .width(progress + '%'); }, - submitHandler: function(id, fileName) { + submitHandler: function() { this.$el.addClass('loading'); this._addPhotoPlaceholder(); }, @@ -66,7 +66,7 @@ app.views.PublisherUploader = Backbone.View.extend({ ); }, - uploadCompleteHandler: function(id, fileName, response) { + uploadCompleteHandler: function(_id, fileName, response) { if (response.success){ this.el_info.text(Diaspora.I18n.t('photo_uploader.completed', {file: fileName})).fadeTo(2000, 0); @@ -110,7 +110,7 @@ app.views.PublisherUploader = Backbone.View.extend({ .find('div.progress').remove(); // no more placeholders? enable buttons - if( publisher.el_photozone.find('li.loading').length == 0 ) { + if( publisher.el_photozone.find('li.loading').length === 0 ) { this.$el.removeClass('loading'); publisher.setButtonsEnabled(true); } @@ -127,7 +127,7 @@ app.views.PublisherUploader = Backbone.View.extend({ // remove an already uploaded photo _removePhoto: function(evt) { var self = this; - var photo = $(evt.target).parents('.publisher_photo') + var photo = $(evt.target).parents('.publisher_photo'); var img = photo.find('img'); photo.addClass('dim'); @@ -139,7 +139,7 @@ app.views.PublisherUploader = Backbone.View.extend({ $.when(photo.fadeOut(400)).then(function(){ photo.remove(); - if( self.publisher.$('.publisher_photo').length == 0 ) { + if( self.publisher.$('.publisher_photo').length === 0 ) { // no more photos left... self.publisher.el_wrapper.removeClass('with_attachments'); } @@ -154,4 +154,3 @@ app.views.PublisherUploader = Backbone.View.extend({ }); // @license-end - diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index 99f9e926e..48574bfe4 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -53,10 +53,10 @@ app.views.Publisher = Backbone.View.extend({ $(window).on('beforeunload', _.bind(this._beforeUnload, this)); // sync textarea content - if( this.el_hiddenInput.val() == "" ) { + if( this.el_hiddenInput.val() === "" ) { this.el_hiddenInput.val( this.el_input.val() ); } - if( this.el_input.val() == "" ) { + if( this.el_input.val() === "" ) { this.el_input.val( this.el_hiddenInput.val() ); } @@ -71,11 +71,11 @@ app.views.Publisher = Backbone.View.extend({ // textchange event won't be called in Backbone... this.el_input.bind('textchange', $.noop); - var _this = this + var _this = this; $('body').on('click', function(event){ // if the click event is happened outside the publisher view, then try to close the box - if( _this.el && $(event.target).closest('#publisher').attr('id') != _this.el.id){ - _this.tryClose() + if( _this.el && $(event.target).closest('#publisher').attr('id') !== _this.el.id){ + _this.tryClose(); } }); @@ -210,7 +210,7 @@ app.views.Publisher = Backbone.View.extend({ // standalone means single-shot posting (until further notice) if( self.standalone ) self.setEnabled(false); }, - error: function(model, resp, options) { + error: function(model, resp) { if( app.publisher ) app.publisher.trigger('publisher:error'); self.setInputEnabled(true); Diaspora.page.flashMessages.render({ 'success':false, 'notice':resp.responseText }); @@ -222,7 +222,7 @@ app.views.Publisher = Backbone.View.extend({ // creates the location showLocation: function(){ - if($('#location').length == 0){ + if($('#location').length === 0){ $('#location_container').append('
'); this.el_wrapper.addClass('with_location'); this.view_locator = new app.views.Location(); @@ -245,7 +245,7 @@ app.views.Publisher = Backbone.View.extend({ // avoid submitting form when pressing Enter key avoidEnter: function(evt){ - if(evt.keyCode == 13) + if(evt.keyCode === 13) return false; }, @@ -257,7 +257,7 @@ app.views.Publisher = Backbone.View.extend({ var serializedForm = $(evt.target).closest("form").serializeObject(); - var photos = new Array(); + var photos = []; $('li.publisher_photo img').each(function(){ var file = $(this).attr('src').substring("/uploads/images/".length); photos.push( @@ -271,11 +271,19 @@ app.views.Publisher = Backbone.View.extend({ ); }); - var mentioned_people = new Array(); - var regexp = new RegExp("@{\(\[\^\;\]\+\); \(\[\^\}\]\+\)}", "g"); - while(user=regexp.exec(serializedForm["status_message[text]"])){ + var mentioned_people = [], + regexp = new RegExp("@{\(\[\^\;\]\+\); \(\[\^\}\]\+\)}", "g"), + user; + + var getMentionedUser = function(handle) { + return Mentions.contacts.filter(function(user) { + return user.handle === handle; + })[0]; + }; + + while( (user = regexp.exec(serializedForm["status_message[text]"])) ){ // user[1]: name, user[2]: handle - var mentioned_user = Mentions.contacts.filter(function(item) { return item.handle == user[2];})[0]; + var mentioned_user = getMentionedUser(user[2]); if(mentioned_user){ mentioned_people.push({ "id":mentioned_user["id"], @@ -289,7 +297,7 @@ app.views.Publisher = Backbone.View.extend({ var date = (new Date()).toISOString(); - var poll = undefined; + var poll; var poll_question = serializedForm["poll_question"]; var poll_answers_arry = _.flatten([serializedForm["poll_answers[]"]]); var poll_answers = _.map(poll_answers_arry, function(answer){ @@ -308,7 +316,7 @@ app.views.Publisher = Backbone.View.extend({ var previewMessage = { "id" : 0, "text" : serializedForm["status_message[text]"], - "public" : serializedForm["aspect_ids[]"]=="public", + "public" : serializedForm["aspect_ids[]"] === "public", "created_at" : date, "interacted_at" : date, "post_type" : "StatusMessage", @@ -349,7 +357,7 @@ app.views.Publisher = Backbone.View.extend({ }, keyDown : function(evt) { - if( evt.keyCode == 13 && evt.ctrlKey ) { + if( evt.keyCode === 13 && evt.ctrlKey ) { this.$("form").submit(); this.open(); return false; @@ -406,7 +414,7 @@ app.views.Publisher = Backbone.View.extend({ tryClose : function(){ // if it is not submittable, close it. if( !this._submittable() ){ - this.close() + this.close(); } }, @@ -483,7 +491,7 @@ app.views.Publisher = Backbone.View.extend({ }, _beforeUnload: function(e) { - if(this._submittable() && this.el_input.val() != this.prefillText){ + if(this._submittable() && this.el_input.val() !== this.prefillText){ var confirmationMessage = Diaspora.I18n.t("confirm_unload"); (e || window.event).returnValue = confirmationMessage; //Gecko + IE return confirmationMessage; //Webkit, Safari, Chrome, etc. @@ -509,4 +517,3 @@ $.fn.serializeObject = function() return o; }; // @license-end - diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_actions.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_actions.js index eee0097ec..65ea3df45 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_actions.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_actions.js @@ -10,14 +10,14 @@ app.views.SinglePostActions = app.views.Feedback.extend({ }, presenter: function() { - var interactions = this.model.interactions + var interactions = this.model.interactions; return _.extend(this.defaultPresenter(), { authorIsNotCurrentUser : this.authorIsNotCurrentUser(), userCanReshare : interactions.userCanReshare(), userLike : interactions.userLike(), userReshare : interactions.userReshare() - }) + }); }, renderPluginWidgets : function() { @@ -32,9 +32,7 @@ app.views.SinglePostActions = app.views.Feedback.extend({ }, authorIsNotCurrentUser: function() { - return app.currentUser.authenticated() && this.model.get("author").id != app.user().id + return app.currentUser.authenticated() && this.model.get("author").id !== app.user().id; } - }); // @license-end - diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_comment_stream.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_comment_stream.js index 07f4d431d..e6c0d3857 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_comment_stream.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_comment_stream.js @@ -9,25 +9,25 @@ app.views.SinglePostCommentStream = app.views.CommentStream.extend({ highlightPermalinkComment: function() { if(document.location.hash){ - element=$(document.location.hash); - headerSize=50; + var element = $(document.location.hash); + var headerSize = 50; $(".highlighted").removeClass("highlighted"); element.addClass("highlighted"); - pos=element.offset().top-headerSize; + var pos = element.offset().top - headerSize; $("html").animate({scrollTop:pos}); } }, postRenderTemplate: function() { - app.views.CommentStream.prototype.postRenderTemplate.apply(this) - this.$(".new_comment_form_wrapper").removeClass('hidden') - _.defer(this.highlightPermalinkComment) + app.views.CommentStream.prototype.postRenderTemplate.apply(this); + this.$(".new_comment_form_wrapper").removeClass('hidden'); + _.defer(this.highlightPermalinkComment); }, appendComment: function(comment) { // Set the post as the comment's parent, so we can check // on post ownership in the Comment view. - comment.set({parent : this.model.toJSON()}) + comment.set({parent : this.model.toJSON()}); this.$(".comments").append(new app.views.ExpandedComment({ model: comment @@ -39,8 +39,7 @@ app.views.SinglePostCommentStream = app.views.CommentStream.extend({ moreCommentsCount : 0, showExpandCommentsLink : false, commentsCount : this.model.interactions.commentsCount() - }) + }); }, -}) +}); // @license-end - diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js index 67f83f3b5..967b72f9f 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js @@ -32,12 +32,11 @@ app.views.SinglePostContent = app.views.Base.extend({ authorIsCurrentUser :app.currentUser.isAuthorOf(this.model), showPost : this.showPost(), text : app.helpers.textFormatter(this.model.get("text"), this.model.get("mentioned_people")) - }) + }); }, showPost : function() { - return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw") + return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw"); } }); // @license-end - diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_interactions.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_interactions.js index 19fa85435..b8c4a8661 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_interactions.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_interactions.js @@ -10,11 +10,11 @@ app.views.SinglePostInteractions = app.views.Base.extend({ initialize : function() { this.model.interactions.on('change', this.render, this); - this.commentStreamView = new app.views.SinglePostCommentStream({model: this.model}) + this.commentStreamView = new app.views.SinglePostCommentStream({model: this.model}); }, presenter : function(){ - var interactions = this.model.interactions + var interactions = this.model.interactions; return { likes : interactions.likes.toJSON(), comments : interactions.comments.toJSON(), @@ -22,8 +22,7 @@ app.views.SinglePostInteractions = app.views.Base.extend({ commentsCount : interactions.commentsCount(), likesCount : interactions.likesCount(), resharesCount : interactions.resharesCount(), - } + }; }, }); // @license-end - diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js index 4bece481a..a47f42d0a 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js @@ -8,8 +8,6 @@ app.views.SinglePostModeration = app.views.Feedback.extend({ }, presenter: function() { - var interactions = this.model.interactions; - return _.extend(this.defaultPresenter(), { authorIsCurrentUser : this.authorIsCurrentUser(), }); @@ -21,7 +19,7 @@ app.views.SinglePostModeration = app.views.Feedback.extend({ }, authorIsCurrentUser: function() { - return app.currentUser.authenticated() && this.model.get("author").id == app.user().id; + return app.currentUser.authenticated() && this.model.get("author").id === app.user().id; }, destroyModel: function(evt) { @@ -35,7 +33,7 @@ app.views.SinglePostModeration = app.views.Feedback.extend({ document.location.href = "/stream"; }) .fail(function() { - var flash = new Diaspora.Widgets.FlashMessages; + var flash = new Diaspora.Widgets.FlashMessages(); flash.render({ success: false, notice: Diaspora.I18n.t('failed_to_remove') diff --git a/app/assets/javascripts/app/views/stream_faces_view.js b/app/assets/javascripts/app/views/stream_faces_view.js index 9091c8bbe..0586f6df5 100644 --- a/app/assets/javascripts/app/views/stream_faces_view.js +++ b/app/assets/javascripts/app/views/stream_faces_view.js @@ -9,12 +9,12 @@ app.views.StreamFaces = app.views.Base.extend({ tooltipSelector : ".avatar", initialize : function(){ - this.updatePeople() - app.stream.items.bind("add", this.updatePeople, this) + this.updatePeople(); + app.stream.items.bind("add", this.updatePeople, this); }, presenter : function() { - return {people : this.people} + return {people : this.people}; }, updatePeople : function(){ @@ -30,4 +30,3 @@ app.views.StreamFaces = app.views.Base.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views/stream_post_views.js b/app/assets/javascripts/app/views/stream_post_views.js index 3fe47f3e8..da34f8bd8 100644 --- a/app/assets/javascripts/app/views/stream_post_views.js +++ b/app/assets/javascripts/app/views/stream_post_views.js @@ -54,7 +54,7 @@ app.views.StreamPost = app.views.Post.extend({ var normalizedClass = this.model.get("post_type").replace(/::/, "__") , postClass = app.views[normalizedClass] || app.views.StatusMessage; - return new postClass({ model : this.model }) + return new postClass({ model : this.model }); }, postLocationStreamView : function(){ @@ -63,7 +63,7 @@ app.views.StreamPost = app.views.Post.extend({ removeNsfwShield: function(evt){ if(evt){ evt.preventDefault(); } - this.model.set({nsfw : false}) + this.model.set({nsfw : false}); this.render(); }, @@ -88,7 +88,7 @@ app.views.StreamPost = app.views.Post.extend({ remove : function() { $(this.el).slideUp(400, _.bind(function(){this.$el.remove()}, this)); - return this + return this; }, hidePost : function(evt) { @@ -121,6 +121,5 @@ app.views.StreamPost = app.views.Post.extend({ return this; } -}) +}); // @license-end - diff --git a/app/assets/javascripts/app/views/stream_view.js b/app/assets/javascripts/app/views/stream_view.js index ca3058279..9d5d036ca 100644 --- a/app/assets/javascripts/app/views/stream_view.js +++ b/app/assets/javascripts/app/views/stream_view.js @@ -5,17 +5,17 @@ app.views.Stream = app.views.InfScroll.extend(_.extend( app.views.StreamShortcuts, { - initialize: function(options) { - this.stream = this.model - this.collection = this.stream.items + initialize: function() { + this.stream = this.model; + this.collection = this.stream.items; - this.postViews = [] + this.postViews = []; - this.setupNSFW() - this.setupLightbox() - this.setupInfiniteScroll() - this.setupShortcuts() - this.markNavSelected() + this.setupNSFW(); + this.setupLightbox(); + this.setupInfiniteScroll(); + this.setupShortcuts(); + this.markNavSelected(); }, postClass : app.views.StreamPost, @@ -26,11 +26,10 @@ app.views.Stream = app.views.InfScroll.extend(_.extend( }, setupNSFW : function(){ - app.currentUser.bind("nsfwChanged", reRenderPostViews, this) - function reRenderPostViews() { - _.map(this.postViews, function(view){ view.render() }) + _.map(this.postViews, function(view){ view.render() }); } + app.currentUser.bind("nsfwChanged", reRenderPostViews, this); }, markNavSelected : function() { @@ -41,4 +40,3 @@ app.views.Stream = app.views.InfScroll.extend(_.extend( } })); // @license-end - diff --git a/app/assets/javascripts/app/views/tag_following_action_view.js b/app/assets/javascripts/app/views/tag_following_action_view.js index 2f770c1b9..37d95ff2a 100644 --- a/app/assets/javascripts/app/views/tag_following_action_view.js +++ b/app/assets/javascripts/app/views/tag_following_action_view.js @@ -20,7 +20,7 @@ app.views.TagFollowingAction = app.views.Base.extend({ return _.extend(this.defaultPresenter(), { tag_is_followed : this.tag_is_followed(), followString : this.followString() - }) + }); }, followString : function() { @@ -35,7 +35,7 @@ app.views.TagFollowingAction = app.views.Base.extend({ return !this.model.isNew(); }, - getTagFollowing : function(tagFollowing) { + getTagFollowing : function() { this.model = app.tagFollowings.where({"name":this.tagText})[0] || new app.models.TagFollowing({"name":this.tagText}); this.model.bind("change", this.render, this); @@ -63,4 +63,3 @@ app.views.TagFollowingAction = app.views.Base.extend({ } }); // @license-end - diff --git a/app/assets/javascripts/app/views/tag_following_list_view.js b/app/assets/javascripts/app/views/tag_following_list_view.js index d067b21df..dd05875e4 100644 --- a/app/assets/javascripts/app/views/tag_following_list_view.js +++ b/app/assets/javascripts/app/views/tag_following_list_view.js @@ -41,9 +41,9 @@ app.views.TagFollowingList = app.views.Base.extend({ }); this.$("input").bind('keydown', function(evt){ - if(evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 32){ + if(evt.keyCode === 13 || evt.keyCode === 9 || evt.keyCode === 32){ evt.preventDefault(); - if( $('li.as-result-item.active').length == 0 ){ + if( $('li.as-result-item.active').length === 0 ){ $('li.as-result-item').first().click(); } } @@ -62,7 +62,6 @@ app.views.TagFollowingList = app.views.Base.extend({ createTagFollowing: function(evt) { if(evt){ evt.preventDefault(); } - var name = this.$(".tag_input").val(); this.collection.create({"name":this.$(".tag_input").val()}); this.$(".tag_input").val(""); @@ -80,4 +79,3 @@ app.views.TagFollowingList = app.views.Base.extend({ }, }); // @license-end - diff --git a/app/assets/javascripts/app/views/tag_following_view.js b/app/assets/javascripts/app/views/tag_following_view.js index 611b74f14..838fd896d 100644 --- a/app/assets/javascripts/app/views/tag_following_view.js +++ b/app/assets/javascripts/app/views/tag_following_view.js @@ -29,9 +29,8 @@ app.views.TagFollowing = app.views.Base.extend({ presenter : function() { return _.extend(this.defaultPresenter(), { tag : this.model - }) + }); } }); // @license-end - diff --git a/app/assets/javascripts/app/views/tags_view.js b/app/assets/javascripts/app/views/tags_view.js index 2f736a206..cf13dbb49 100644 --- a/app/assets/javascripts/app/views/tags_view.js +++ b/app/assets/javascripts/app/views/tags_view.js @@ -2,9 +2,8 @@ app.views.Tags = Backbone.View.extend({ - initialize: function(opts) { + initialize: function() { app.publisher.setText("#"+ this.tagName + " "); } }); // @license-end - diff --git a/app/assets/javascripts/aspects-dropdown.js b/app/assets/javascripts/aspects-dropdown.js index 99ce1fac0..6c1ea03bc 100644 --- a/app/assets/javascripts/aspects-dropdown.js +++ b/app/assets/javascripts/aspects-dropdown.js @@ -10,36 +10,37 @@ var AspectsDropdown = { selectedAspects = dropdown.children(".selected").length, allAspects = dropdown.children().length, replacement, + message, isInPublisher = dropdown.closest('#publisher').length; - if (number == 0) { + if (number === 0) { button.removeClass(inAspectClass); if (isInPublisher) { replacement = Diaspora.I18n.t("aspect_dropdown.select_aspects"); } else { replacement = Diaspora.I18n.t("aspect_dropdown.add_to_aspect"); /* flash message prompt */ - var message = Diaspora.I18n.t("aspect_dropdown.stopped_sharing_with", {name: dropdown.data('person-short-name')}); + message = Diaspora.I18n.t("aspect_dropdown.stopped_sharing_with", {name: dropdown.data('person-short-name')}); Diaspora.page.flashMessages.render({success: true, notice: message}); } - } else if (selectedAspects == allAspects) { + } else if (selectedAspects === allAspects) { replacement = Diaspora.I18n.t('aspect_dropdown.all_aspects'); - } else if (number == 1) { + } else if (number === 1) { button.addClass(inAspectClass); replacement = dropdown.find(".selected").first().text(); /* flash message prompt */ if (!isInPublisher) { - var message = Diaspora.I18n.t("aspect_dropdown.started_sharing_with", {name: dropdown.data('person-short-name')}); + message = Diaspora.I18n.t("aspect_dropdown.started_sharing_with", {name: dropdown.data('person-short-name')}); Diaspora.page.flashMessages.render({success: true, notice: message}); } } else { - replacement = Diaspora.I18n.t('aspect_dropdown.toggle', { count: number.toString()}) + replacement = Diaspora.I18n.t('aspect_dropdown.toggle', { count: number.toString()}); } // if we are in the publisher, we add the visibility icon if (isInPublisher) { var icon = $('#visibility-icon'); - if (replacement.trim() == Diaspora.I18n.t('stream.public')) { + if (replacement.trim() === Diaspora.I18n.t('stream.public')) { icon.removeClass('lock'); icon.addClass('globe'); } else { @@ -74,6 +75,4 @@ var AspectsDropdown = { }); } }; - // @license-end - diff --git a/app/assets/javascripts/clear-form.js b/app/assets/javascripts/clear-form.js index db97fee95..0d361f3ac 100644 --- a/app/assets/javascripts/clear-form.js +++ b/app/assets/javascripts/clear-form.js @@ -10,7 +10,7 @@ $.fn.clearForm = function() { $(this).attr('checked', false); } else if ($(this).is('select')) { this.selectedIndex = -1; - } else if ($(this).attr('name') == 'photos[]') { + } else if ($(this).attr('name') === 'photos[]') { $(this).val(''); } $(this).blur(); diff --git a/app/assets/javascripts/diaspora.js b/app/assets/javascripts/diaspora.js index df60703f3..054905786 100644 --- a/app/assets/javascripts/diaspora.js +++ b/app/assets/javascripts/diaspora.js @@ -21,14 +21,18 @@ var eventNames = eventName.split(" "); for(eventName in eventNames) { - this.eventsContainer.trigger(eventNames[eventName], args); + if(eventNames.hasOwnProperty(eventName)) { + this.eventsContainer.trigger(eventNames[eventName], args); + } } }, subscribe: function(eventName, callback, context) { var eventNames = eventName.split(" "); for(eventName in eventNames) { - this.eventsContainer.bind(eventNames[eventName], $.proxy(callback, context)); + if(eventNames.hasOwnProperty(eventName)) { + this.eventsContainer.bind(eventNames[eventName], $.proxy(callback, context)); + } } } }); @@ -38,7 +42,7 @@ }; Diaspora.BaseWidget = { - instantiate: function(Widget, element) { + instantiate: function(Widget) { // Mobile version loads only some widgets if (typeof Diaspora.Widgets[Widget] === 'undefined') return; @@ -85,18 +89,16 @@ if(!$.mobile)//why does this need this? $.extend(Diaspora.page, new Diaspora.BasePage($(document.body))); - Diaspora.page.publish("page/ready", [$(document.body)]) + Diaspora.page.publish("page/ready", [$(document.body)]); }; // temp hack to check if backbone is enabled for the page Diaspora.backboneEnabled = function(){ return window.app && window.app.stream !== undefined; - } + }; window.Diaspora = Diaspora; })(); - $(Diaspora.instantiatePage); // @license-end - diff --git a/app/assets/javascripts/helpers/i18n.js b/app/assets/javascripts/helpers/i18n.js index 3e4a01fe0..9be574c45 100644 --- a/app/assets/javascripts/helpers/i18n.js +++ b/app/assets/javascripts/helpers/i18n.js @@ -6,7 +6,7 @@ Diaspora.I18n = { pluralizationKey: function(n) { return this.fallback.pluralizationKey(n); }, data: {}, fallback: { - pluralizationKey: function(n) { return n == 1 ? "one" : "other"; }, + pluralizationKey: function(n) { return n === 1 ? "one" : "other"; }, data: {} } }, @@ -20,9 +20,12 @@ Diaspora.I18n = { updateLocale: function(locale, data) { locale.data = $.extend(locale.data, data); - rule = this._resolve(locale, ['pluralization_rule']); + var rule = this._resolve(locale, ['pluralization_rule']); if (rule !== "") { + /* jshint evil:true */ + // TODO change this to `locale.pluralizationKey = rule`? eval("locale.pluralizationKey = "+rule); + /* jshint evil:false */ } }, @@ -37,7 +40,7 @@ Diaspora.I18n = { _resolve: function(locale, items) { var translatedMessage, nextNamespace, originalItems = items.slice(); - while(nextNamespace = items.shift()) { + while( (nextNamespace = items.shift()) ) { translatedMessage = (translatedMessage) ? translatedMessage[nextNamespace] : locale.data[nextNamespace]; diff --git a/app/assets/javascripts/inbox.js b/app/assets/javascripts/inbox.js index 758ff5e68..6ec1d03dc 100644 --- a/app/assets/javascripts/inbox.js +++ b/app/assets/javascripts/inbox.js @@ -24,7 +24,7 @@ $(document).ready(function(){ cBadge.html().replace(/\d+/, function(num){ num = parseInt(num); cBadge.html(parseInt(num)-1); - if(num == 1) { + if(num === 1) { cBadge.addClass("hidden"); } }); diff --git a/app/assets/javascripts/jsxc.js b/app/assets/javascripts/jsxc.js index 456813851..e297ae0f6 100644 --- a/app/assets/javascripts/jsxc.js +++ b/app/assets/javascripts/jsxc.js @@ -39,7 +39,7 @@ $(document).ready(function() { overwrite: true, onlogin: true } - } + }; } }); } else { diff --git a/app/assets/javascripts/mobile/mobile.js b/app/assets/javascripts/mobile/mobile.js index af1a3c336..a687c47c5 100644 --- a/app/assets/javascripts/mobile/mobile.js +++ b/app/assets/javascripts/mobile/mobile.js @@ -81,7 +81,7 @@ $(document).ready(function(){ dataType: 'json', type: 'DELETE', beforeSend: showLoader(link), - complete: function(data){ + complete: function(){ removeLoader(link); link.attr("href", href.replace(/\/\d+$/, '')); @@ -110,10 +110,10 @@ $(document).ready(function(){ dataType: 'json', type: 'POST', beforeSend: showLoader(link), - success: function(data){ + success: function(){ removeLoader(link); }, - error: function(data){ + error: function(){ removeLoader(link); alert("Failed to reshare!"); } @@ -128,7 +128,7 @@ $(document).ready(function(){ evt.preventDefault(); var link = $(this), parent = link.closest(".bottom_bar").first(), - commentsContainer = function(){ return parent.find(".comment_container").first(); } + commentsContainer = function(){ return parent.find(".comment_container").first(); }, existingCommentsContainer = commentsContainer(); if( link.hasClass('active') ) { @@ -200,7 +200,7 @@ $(document).ready(function(){ context: link, success: function(data){ var textarea = function(target) { return target.closest(".stream_element").find('textarea.comment_box').first()[0] }; - link.removeClass('loading') + link.removeClass('loading'); if(!link.hasClass("add_comment_bottom_link")){ link.removeClass('inactive'); @@ -217,9 +217,9 @@ $(document).ready(function(){ $(".stream").delegate("a.cancel_new_comment", "tap click", function(evt){ evt.preventDefault(); - var link = $(this); + var link = $(this), form = link.closest("form"), - commentActionLink = link.closest(".bottom_bar").find("a.comment_action").first(); + commentActionLink = link.closest(".bottom_bar").find("a.comment_action").first(), container = link.closest('.bottom_bar').find('.add_comment_bottom_link_container'); if(container.length > 0 ){ @@ -237,7 +237,7 @@ $(document).ready(function(){ $.post(form.attr('action')+"?format=mobile", form.serialize(), function(data){ var bottomBar = form.closest('.bottom_bar').first(), container = bottomBar.find('.add_comment_bottom_link_container'), - commentActionLink = bottomBar.find("a.comment_action").first(); + commentActionLink = bottomBar.find("a.comment_action").first(), reactionLink = bottomBar.find(".show_comments").first(), commentCount = bottomBar.find(".comment_count"); @@ -247,13 +247,13 @@ $(document).ready(function(){ container.show(); } else { - var container = $("
"), - comments = $(""); + var comments = $(""); + container = $("
"); comments.html(data); container.append(comments); form.remove(); - container.appendTo(bottomBar) + container.appendTo(bottomBar); } reactionLink.text(reactionLink.text().replace(/(\d+)/, function(match){ return parseInt(match) + 1; })); @@ -264,7 +264,7 @@ $(document).ready(function(){ }); - $(".service_icon").bind("tap click", function(evt) { + $(".service_icon").bind("tap click", function() { var service = $(this).toggleClass("dim"), selectedServices = $("#new_status_message .service_icon:not(.dim)"), provider = service.attr("id"), @@ -302,6 +302,4 @@ $(document).ready(function(){ }); }); - // @license-end - diff --git a/app/assets/javascripts/mobile/mobile_file_uploader.js b/app/assets/javascripts/mobile/mobile_file_uploader.js index ac17956c2..1084821e9 100644 --- a/app/assets/javascripts/mobile/mobile_file_uploader.js +++ b/app/assets/javascripts/mobile/mobile_file_uploader.js @@ -5,7 +5,7 @@ function createUploader(){ var aspectIds = gon.preloads.aspect_ids; - var uploader = new qq.FileUploaderBasic({ + new qq.FileUploaderBasic({ element: document.getElementById('file-upload-publisher'), params: {'photo' : {'pending' : 'true', 'aspect_ids' : aspectIds},}, allowedExtensions: ['jpg', 'jpeg', 'png', 'gif', 'tiff'], @@ -25,7 +25,7 @@ function createUploader(){ emptyError: Diaspora.I18n.t("photo_uploader.new_photo.empty") }, - onSubmit: function(id, fileName){ + onSubmit: function(){ $('#file-upload-publisher').addClass("loading"); $('#publisher_textarea_wrapper').addClass("with_attachments"); $('#photodropzone').append( @@ -35,7 +35,7 @@ function createUploader(){ ); }, - onComplete: function(id, fileName, responseJSON) { + onComplete: function(_id, fileName, responseJSON) { $('#fileInfo-publisher').text(Diaspora.I18n.t("photo_uploader.completed", {'file': fileName})); var id = responseJSON.data.photo.id, url = responseJSON.data.photo.unprocessed_image.url, @@ -53,8 +53,7 @@ function createUploader(){ "
"); //// - var publisher = $('#publisher'), - textarea = publisher.find('textarea'); + var publisher = $('#publisher'); publisher.find("input[type='submit']").removeAttr('disabled'); @@ -67,7 +66,7 @@ function createUploader(){ success: function() { photo.fadeOut(400, function(){ photo.remove(); - if ( $('.publisher_photo').length == 0){ + if ( $('.publisher_photo').length === 0){ $('#publisher_textarea_wrapper').removeClass("with_attachments"); } }); @@ -76,7 +75,7 @@ function createUploader(){ }); }, - onAllComplete: function(completed_files){ + onAllComplete: function(){ } }); diff --git a/app/assets/javascripts/osmlocator.js b/app/assets/javascripts/osmlocator.js index 8a36dedb3..157230456 100644 --- a/app/assets/javascripts/osmlocator.js +++ b/app/assets/javascripts/osmlocator.js @@ -6,22 +6,20 @@ OSM.Locator = function(){ var geolocalize = function(callback){ navigator.geolocation.getCurrentPosition(function(position) { - lat=position.coords.latitude; - lon=position.coords.longitude; - var display_name =$.getJSON("https://nominatim.openstreetmap.org/reverse?format=json&lat="+lat+"&lon="+lon+"&addressdetails=3", function(data){ + var lat=position.coords.latitude, + lon=position.coords.longitude; + $.getJSON("https://nominatim.openstreetmap.org/reverse?format=json&lat="+lat+"&lon="+lon+"&addressdetails=3", function(data){ return callback(data.display_name, position.coords); }); },errorGettingPosition); }; - function errorGettingPosition(err) { + function errorGettingPosition() { $("#location").remove(); - }; + } return { getAddress: geolocalize - } - -} + }; +}; // @license-end - diff --git a/app/assets/javascripts/pages/users-getting-started.js b/app/assets/javascripts/pages/users-getting-started.js index fe4d0aa8a..2fed55655 100644 --- a/app/assets/javascripts/pages/users-getting-started.js +++ b/app/assets/javascripts/pages/users-getting-started.js @@ -7,12 +7,12 @@ Diaspora.Pages.UsersGettingStarted = function() { self.peopleSearch = self.instantiate("Search", body.find("form.people.search_form")); self.tagSearch = self.instantiate("Search", body.find("form.tag_input.search_form")); - $('#edit_profile').bind('ajax:success', function(evt, data, status, xhr){ + $('#edit_profile').bind('ajax:success', function(){ $('#gs-name-form-spinner').addClass("hidden"); }); // It seems that the default behavior of rails ujs is to clear the remote form - $('#edit_profile').bind('ajax:complete', function(evt, xhr, status){ + $('#edit_profile').bind('ajax:complete', function(){ var firstNameField = $("#profile_first_name"); firstNameField.val(firstNameField.data("cachedValue")); @@ -35,7 +35,7 @@ Diaspora.Pages.UsersGettingStarted = function() { $(this).addClass("active_input"); }); - $("#awesome_button").bind("click", function(evt){ + $("#awesome_button").bind("click", function(){ var confirmMessage = Diaspora.I18n.t("getting_started.no_tags"); var message = Diaspora.I18n.t("getting_started.preparing_your_stream"); var confirmation = true; @@ -73,9 +73,9 @@ Diaspora.Pages.UsersGettingStarted = function() { }); autocompleteInput.bind('keydown', function(evt){ - if(evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 32){ + if(evt.keyCode === 13 || evt.keyCode === 9 || evt.keyCode === 32){ evt.preventDefault(); - if( $('li.as-result-item.active').length == 0 ){ + if( $('li.as-result-item.active').length === 0 ){ $('li.as-result-item').first().click(); } } diff --git a/app/assets/javascripts/view.js b/app/assets/javascripts/view.js index a833bd035..991b7d489 100644 --- a/app/assets/javascripts/view.js +++ b/app/assets/javascripts/view.js @@ -38,20 +38,20 @@ var View = { $(this).attr('checked', false); } else if ($(this).is('select')) { this.selectedIndex = -1; - } else if ($(this).attr('name') == 'photos[]') { + } else if ($(this).attr('name') === 'photos[]') { $(this).val(''); } $(this).blur(); }); }; - $(document).on('ajax:success', 'form[data-remote]', function (e) { + $(document).on('ajax:success', 'form[data-remote]', function () { $(this).clearForm(); $(this).focusout(); }); /* tag following */ - $("#new_tag_following .tag_input").bind('focus', function(evt){ + $("#new_tag_following .tag_input").bind('focus', function(){ $(this).siblings("#tag_following_submit").removeClass('hidden'); }); @@ -62,8 +62,8 @@ var View = { Diaspora.page.directionDetector.updateBinds(); }); - $("a.new_aspect").click(function(e){ - $("input#aspect_name").focus() + $("a.new_aspect").click(function(){ + $("input#aspect_name").focus(); }); /* facebox 'done' buttons */ @@ -111,4 +111,3 @@ $(function() { View.initialize(); }); // @license-end - diff --git a/app/assets/javascripts/widgets/back-to-top.js b/app/assets/javascripts/widgets/back-to-top.js index dd569728e..bde326774 100644 --- a/app/assets/javascripts/widgets/back-to-top.js +++ b/app/assets/javascripts/widgets/back-to-top.js @@ -27,11 +27,10 @@ (self.body.scrollTop() > 1000) ? 'addClass' : 'removeClass' - ]('visible') + ]('visible'); }; }; Diaspora.Widgets.BackToTop = BackToTop; })(); // @license-end - diff --git a/app/assets/javascripts/widgets/lightbox.js b/app/assets/javascripts/widgets/lightbox.js index df5bcb628..461be1d0e 100644 --- a/app/assets/javascripts/widgets/lightbox.js +++ b/app/assets/javascripts/widgets/lightbox.js @@ -27,7 +27,7 @@ jQuery.fn.center = (function() { imageSelector: 'img.stream-photo' }; - this.subscribe("widget/ready", function(evt) { + this.subscribe("widget/ready", function() { $.extend(self, { lightbox: $("#lightbox"), navigation: $("#lightbox-navigation"), @@ -94,7 +94,7 @@ jQuery.fn.center = (function() { this.nextImage = function(thumb){ var next = thumb.next(); - if (next.length == 0) { + if (next.length === 0) { next = self.imageset.find("img").first(); } return(next); @@ -102,7 +102,7 @@ jQuery.fn.center = (function() { this.prevImage = function(thumb){ var prev = thumb.prev(); - if (prev.length == 0) { + if (prev.length === 0) { prev = self.imageset.find("img").last(); } return(prev); @@ -130,9 +130,9 @@ jQuery.fn.center = (function() { "data-full-photo": image.attr("data-full-photo") }); - if(image.attr("data-full-photo") == imageUrl) { + if(image.attr("data-full-photo") === imageUrl) { imageThumb = thumb; - }; + } self.imageset.append(thumb); }); @@ -154,7 +154,7 @@ jQuery.fn.center = (function() { this.scrollToThumbnail = function(imageThumb) { self.navigation.animate({scrollLeft: (self.navigation.scrollLeft() + imageThumb.offset().left +35 - (self.window.width() / 2))}, 200, 'swing'); - } + }; this.selectImage = function(imageThumb) { $(".selected", self.imageset).removeClass("selected"); diff --git a/app/assets/javascripts/widgets/notifications-badge.js b/app/assets/javascripts/widgets/notifications-badge.js index c24cd80f1..fc1b3d30b 100644 --- a/app/assets/javascripts/widgets/notifications-badge.js +++ b/app/assets/javascripts/widgets/notifications-badge.js @@ -85,10 +85,10 @@ }); self.dropdownNotifications.find("time.timeago").timeago(); - self.dropdownNotifications.find('.unread').each(function(index) { + self.dropdownNotifications.find('.unread').each(function() { Diaspora.page.header.notifications.setUpUnread( $(this) ); }); - self.dropdownNotifications.find('.read').each(function(index) { + self.dropdownNotifications.find('.read').each(function() { Diaspora.page.header.notifications.setUpRead( $(this) ); }); $('.notifications').perfectScrollbar('destroy'); @@ -97,10 +97,10 @@ isLoading = false; $('.notifications').removeClass("loading"); //Infinite Scrolling - $('.notifications').scroll(function(e) { + $('.notifications').scroll(function() { var bottom = $('.notifications').prop('scrollHeight') - $('.notifications').height(); var currentPosition = $('.notifications').scrollTop(); - isLoading = ($('.loading').length == 1); + isLoading = ($('.loading').length === 1); if (currentPosition + 50 >= bottom && notificationsLoaded <= self.notifications.length && !isLoading) { $('.notifications').addClass("loading"); ++currentPage; @@ -113,4 +113,3 @@ Diaspora.Widgets.NotificationsDropdown = NotificationDropdown; })(); // @license-end - diff --git a/app/assets/javascripts/widgets/notifications.js b/app/assets/javascripts/widgets/notifications.js index 46108f8de..3a0b5a099 100644 --- a/app/assets/javascripts/widgets/notifications.js +++ b/app/assets/javascripts/widgets/notifications.js @@ -29,7 +29,7 @@ type: "GET", dataType:'json', success: function(){ - self.notificationMenu.find('.unread').each(function(index) { + self.notificationMenu.find('.unread').each(function() { self.setUpRead( $(this) ); }); self.resetCount(); @@ -41,7 +41,7 @@ }); this.setUpNotificationPage = function( page ) { self.notificationPage = page; - } + }; this.unreadClick = function() { $.ajax({ url: "/notifications/" + $(this).closest(".stream_element,.notification_element").data("guid"), @@ -68,7 +68,7 @@ .removeAttr('data-original-title') .attr('title', Diaspora.I18n.t('notifications.mark_read')) .tooltip(); - } + }; this.setUpRead = function( an_obj ) { an_obj.removeClass("unread").addClass( "read" ); an_obj.find('.unread-toggle') @@ -79,17 +79,17 @@ .removeAttr('data-original-title') .attr('title', Diaspora.I18n.t('notifications.mark_unread')) .tooltip(); - } + }; this.clickSuccess = function( data ) { - var itemID = data["guid"] - var isUnread = data["unread"] - self.notificationMenu.find('.read,.unread').each(function(index) { - if ( $(this).data("guid") == itemID ) { + var itemID = data["guid"]; + var isUnread = data["unread"]; + self.notificationMenu.find('.read,.unread').each(function() { + if ( $(this).data("guid") === itemID ) { if ( isUnread ) { - self.notificationMenu.find('a#mark_all_read_link').removeClass('disabled') - self.setUpUnread( $(this) ) + self.notificationMenu.find('a#mark_all_read_link').removeClass('disabled'); + self.setUpUnread( $(this) ); } else { - self.setUpRead( $(this) ) + self.setUpRead( $(this) ); } } }); @@ -118,7 +118,7 @@ }; this.changeNotificationCount = function(change) { - self.count = Math.max( self.count + change, 0 ) + self.count = Math.max( self.count + change, 0 ); self.badge.text(self.count); if(self.count === 0) { @@ -128,7 +128,7 @@ self.badge.removeClass("hidden"); } }; - this.resetCount = function(change) { + this.resetCount = function() { self.count = 0; this.changeNotificationCount(0); }; @@ -145,4 +145,3 @@ Diaspora.Widgets.Notifications = Notifications; })(); // @license-end - diff --git a/app/assets/javascripts/widgets/search.js b/app/assets/javascripts/widgets/search.js index ee21be3a6..554075194 100644 --- a/app/assets/javascripts/widgets/search.js +++ b/app/assets/javascripts/widgets/search.js @@ -53,7 +53,7 @@ this.parse = function(data) { var results = data.map(function(person){ person['name'] = Handlebars.Utils.escapeExpression(person['name']); - return {data : person, value : person['name']} + return {data : person, value : person['name']}; }); results.push({ @@ -81,4 +81,3 @@ Diaspora.Widgets.Search = Search; })(); // @license-end - diff --git a/app/assets/javascripts/widgets/timeago.js b/app/assets/javascripts/widgets/timeago.js index 0e33217f0..dcb680864 100644 --- a/app/assets/javascripts/widgets/timeago.js +++ b/app/assets/javascripts/widgets/timeago.js @@ -6,14 +6,12 @@ */ (function() { Diaspora.Widgets.TimeAgo = function() { - var self = this; - this.subscribe("widget/ready", function() { if(Diaspora.I18n.language !== "en") { $.timeago.settings.lang = Diaspora.I18n.language; - $.timeago.settings.strings[Diaspora.I18n.language] = {} + $.timeago.settings.strings[Diaspora.I18n.language] = {}; $.each($.timeago.settings.strings["en"], function(index) { - if(index == "numbers") { + if(index === "numbers") { $.timeago.settings.strings[Diaspora.I18n.language][index] = []; } else { @@ -25,4 +23,3 @@ }; })(); // @license-end - diff --git a/config/.jshint.json b/config/.jshint.json new file mode 100644 index 000000000..0232d5b13 --- /dev/null +++ b/config/.jshint.json @@ -0,0 +1,65 @@ +{ + "bitwise": false, + "camelcase": false, + "curly": true, + "eqeqeq": true, + "forin": true, + "freeze": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonbsp": true, + "nonew": false, + "notypeof": true, + "undef": true, + "unused": true, + + "asi": false, + "boss": false, + "browser": true, + "devel": true, + "eqnull": true, + "evil": false, + "expr": false, + "jasmine": true, + "jquery": true, + "lastsemic": true, + "laxbreak": false, + "laxcomma": false, + "loopfunc": false, + "scripturl": false, + "sub": false, + "supernew": true, + + "predef": [ + "_", + "Backbone", + "gon", + "Handlebars", + "HandlebarsTemplates", + "ImagePaths", + "jsxc", + "MBP", + "Routes", + "OSM", + "parse_url", + "punycode", + "qq", + + "loginAs", + "logout", + "spec", + "context", + "factory", + "stubView", + "exports", + + "app", + "Diaspora", + "Mentions", + "PosixBracketExpressions" + ] +} diff --git a/config/.jshint_ignore b/config/.jshint_ignore new file mode 100644 index 000000000..9ff1b5926 --- /dev/null +++ b/config/.jshint_ignore @@ -0,0 +1,5 @@ +vendor/assets/javascripts/**.js +lib/assets/javascripts/fileuploader-custom.js +lib/assets/javascripts/jquery.autoresize.js +lib/assets/javascripts/jquery.mentionsInput.js +lib/assets/javascripts/markdown-it-diaspora-linkify.js diff --git a/config/jshint.yml b/config/jshint.yml new file mode 100644 index 000000000..b99a1ba48 --- /dev/null +++ b/config/jshint.yml @@ -0,0 +1,72 @@ +files: ['**/*.js'] + +exclude_paths: [ + 'vendor/assets/javascripts', + 'lib/assets/javascripts' +] + +options: + # enforcing options + bitwise: false + camelcase: false + curly: true + eqeqeq: true + forin: true + freeze: true + immed: true + indent: 2 + latedef: true + newcap: true + noarg: true + noempty: true + nonbsp: true + nonew: false + notypeof: true + undef: true + unused: true + + # relaxing options + asi: false + boss: false + browser: true + devel: true + eqnull: true + evil: false + expr: false + jasmine: true + jquery: true + lastsemic: true + laxbreak: false + laxcomma: false + loopfunc: false + scripturl: false + sub: false + supernew: true + + globals: + "_": true + "Backbone": true + "gon": true + "Handlebars": true + "HandlebarsTemplates": true + "ImagePaths": true + "jsxc": true + "MBP": true + "Routes": true + "OSM": true + "parse_url": true + "punycode": true + "qq": true + + "loginAs": true + "logout": true + "spec": true + "context": true + "factory": true + "stubView": true + "exports": true + + "app": true + "Diaspora": true + "Mentions": true + "PosixBracketExpressions": true diff --git a/lib/assets/javascripts/posix-bracket-expressions.js b/lib/assets/javascripts/posix-bracket-expressions.js index b071fdcd6..4f573e5b6 100644 --- a/lib/assets/javascripts/posix-bracket-expressions.js +++ b/lib/assets/javascripts/posix-bracket-expressions.js @@ -1,5 +1,8 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later +// information for jshint +/* exported PosixBracketExpressions */ + var PosixBracketExpressions = { alnum : '\\u0030-\\u0039' + '\\u0041-\\u005a' diff --git a/spec/javascripts/app/app_spec.js b/spec/javascripts/app/app_spec.js index e5f396fd1..2840c1d31 100644 --- a/spec/javascripts/app/app_spec.js +++ b/spec/javascripts/app/app_spec.js @@ -6,7 +6,7 @@ describe("app", function() { }); it("sets the user if given one and returns the current user", function() { - expect(app.user()).toBeFalsy() + expect(app.user()).toBeFalsy(); app.user({name: "alice"}); expect(app.user().get("name")).toEqual("alice"); }); diff --git a/spec/javascripts/app/collections/comments_collection_spec.js b/spec/javascripts/app/collections/comments_collection_spec.js index 76f6498e9..0e8c3ddf5 100644 --- a/spec/javascripts/app/collections/comments_collection_spec.js +++ b/spec/javascripts/app/collections/comments_collection_spec.js @@ -1,10 +1,9 @@ describe("app.collections.comments", function(){ describe("url", function(){ it("should user the post id", function(){ - var post =new app.models.Post({id : 5}) - var collection = new app.collections.Comments([], {post : post}) - expect(collection.url()).toBe("/posts/5/comments") - }) - }) -}) - + var post =new app.models.Post({id : 5}); + var collection = new app.collections.Comments([], {post : post}); + expect(collection.url()).toBe("/posts/5/comments"); + }); + }); +}); diff --git a/spec/javascripts/app/collections/likes_collections_spec.js b/spec/javascripts/app/collections/likes_collections_spec.js index 292888403..b23f5ae7a 100644 --- a/spec/javascripts/app/collections/likes_collections_spec.js +++ b/spec/javascripts/app/collections/likes_collections_spec.js @@ -1,10 +1,9 @@ describe("app.collections.Likes", function(){ describe("url", function(){ it("should user the post id", function(){ - var post =new app.models.Post({id : 5}) - var collection = new app.collections.Likes([], {post : post}) - expect(collection.url).toBe("/posts/5/likes") - }) - }) -}) - + var post =new app.models.Post({id : 5}); + var collection = new app.collections.Likes([], {post : post}); + expect(collection.url).toBe("/posts/5/likes"); + }); + }); +}); diff --git a/spec/javascripts/app/collections/tag_following_collection_spec.js b/spec/javascripts/app/collections/tag_following_collection_spec.js index b3b4c646c..d776d35e6 100644 --- a/spec/javascripts/app/collections/tag_following_collection_spec.js +++ b/spec/javascripts/app/collections/tag_following_collection_spec.js @@ -1,21 +1,21 @@ describe("app.collections.TagFollowings", function(){ beforeEach(function(){ this.collection = new app.collections.TagFollowings(); - }) + }); describe("comparator", function() { it("should compare in reverse order", function() { var a = new app.models.TagFollowing({name: "aaa"}), - b = new app.models.TagFollowing({name: "zzz"}) - expect(this.collection.comparator(a, b)).toBeGreaterThan(0) - }) - }) + b = new app.models.TagFollowing({name: "zzz"}); + expect(this.collection.comparator(a, b)).toBeGreaterThan(0); + }); + }); describe("create", function(){ it("should not allow duplicates", function(){ - this.collection.create({"name":"name"}) - this.collection.create({"name":"name"}) - expect(this.collection.length).toBe(1) - }) - }) -}) + this.collection.create({"name":"name"}); + this.collection.create({"name":"name"}); + expect(this.collection.length).toBe(1); + }); + }); +}); diff --git a/spec/javascripts/app/helpers/date_formatter_spec.js b/spec/javascripts/app/helpers/date_formatter_spec.js index 9d317a108..141cdbd6e 100644 --- a/spec/javascripts/app/helpers/date_formatter_spec.js +++ b/spec/javascripts/app/helpers/date_formatter_spec.js @@ -3,31 +3,30 @@ describe("app.helpers.dateFormatter", function(){ beforeEach(function(){ this.statusMessage = factory.post(); this.formatter = app.helpers.dateFormatter; - }) + }); describe("parse", function(){ context("modern web browsers", function(){ it ("supports ISO 8601 UTC dates", function(){ var timestamp = new Date(this.statusMessage.get("created_at")).getTime(); expect(this.formatter.parse(this.statusMessage.get("created_at"))).toEqual(timestamp); - }) - }) + }); + }); context("legacy web browsers", function(){ it("supports ISO 8601 UTC dates", function(){ var timestamp = new Date(this.statusMessage.get("created_at")).getTime(); expect(this.formatter.parseISO8601UTC(this.statusMessage.get("created_at"))).toEqual(timestamp); - }) - }) + }); + }); context("status messages", function(){ it("uses ISO 8601 UTC dates", function(){ var iso8601_utc_pattern = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.(\d{3}))?Z$/; expect(iso8601_utc_pattern.test(this.statusMessage.get("created_at"))).toBe(true); - }) - }) - }) - -}) + }); + }); + }); +}); diff --git a/spec/javascripts/app/helpers/text_formatter_spec.js b/spec/javascripts/app/helpers/text_formatter_spec.js index c9f5750be..b00ee3155 100644 --- a/spec/javascripts/app/helpers/text_formatter_spec.js +++ b/spec/javascripts/app/helpers/text_formatter_spec.js @@ -3,7 +3,7 @@ describe("app.helpers.textFormatter", function(){ beforeEach(function(){ this.statusMessage = factory.post(); this.formatter = app.helpers.textFormatter; - }) + }); // Some basic specs. For more detailed specs see // https://github.com/svbergerem/markdown-it-hashtag/tree/master/test @@ -34,25 +34,25 @@ describe("app.helpers.textFormatter", function(){ name : "Alice Smith", diaspora_id : "alice@example.com", id : "555" - }) + }); this.bob = factory.author({ name : "Bob Grimm", diaspora_id : "bob@example.com", id : "666" - }) + }); - this.statusMessage.set({text: "hey there @{Alice Smith; alice@example.com} and @{Bob Grimm; bob@example.com}"}) - this.statusMessage.set({mentioned_people : [this.alice, this.bob]}) - }) + this.statusMessage.set({text: "hey there @{Alice Smith; alice@example.com} and @{Bob Grimm; bob@example.com}"}); + this.statusMessage.set({mentioned_people : [this.alice, this.bob]}); + }); it("matches mentions", function(){ - var formattedText = this.formatter(this.statusMessage.get("text"), this.statusMessage.get("mentioned_people")) + var formattedText = this.formatter(this.statusMessage.get("text"), this.statusMessage.get("mentioned_people")); var wrapper = $("
").html(formattedText); _.each([this.alice, this.bob], function(person) { - expect(wrapper.find("a[href='/people/" + person.guid + "']").text()).toContain(person.name) - }) + expect(wrapper.find("a[href='/people/" + person.guid + "']").text()).toContain(person.name); + }); }); it("returns mentions for on posts that haven't been saved yet (framer posts)", function(){ @@ -61,19 +61,19 @@ describe("app.helpers.textFormatter", function(){ handle : "bob@example.com", url : 'googlebot.com', id : "666" - }) + }); - this.statusMessage.set({'mentioned_people' : [freshBob] }) + this.statusMessage.set({'mentioned_people' : [freshBob] }); - var formattedText = this.formatter(this.statusMessage.get("text"), this.statusMessage.get("mentioned_people")) + var formattedText = this.formatter(this.statusMessage.get("text"), this.statusMessage.get("mentioned_people")); var wrapper = $("
").html(formattedText); - expect(wrapper.find("a[href='googlebot.com']").text()).toContain(freshBob.name) - }) + expect(wrapper.find("a[href='googlebot.com']").text()).toContain(freshBob.name); + }); it('returns the name of the mention if the mention does not exist in the array', function(){ - var text = "hey there @{Chris Smith; chris@example.com}" - var formattedText = this.formatter(text, []) - expect(formattedText.match(/\ Pins", one : "<%= count %> Pin"} } - }) + }); var posts = $.parseJSON(spec.readFixture("stream_json")); this.post = new app.models.Post(posts[0]); // post with a like @@ -18,39 +18,38 @@ describe("app.views.LikesInfo", function(){ it("displays a the like count if it is above zero", function() { spyOn(this.view.model.interactions, "likesCount").and.returnValue(3); this.view.render(); - expect($(this.view.el).find(".expand_likes").length).toBe(1) - }) + expect($(this.view.el).find(".expand_likes").length).toBe(1); + }); it("does not display the like count if it is zero", function() { spyOn(this.view.model.interactions, "likesCount").and.returnValue(0); this.view.render(); expect($(this.view.el).html().trim()).toBe(""); - }) + }); it("fires on a model change", function(){ - spyOn(this.view, "postRenderTemplate") - this.view.model.interactions.trigger('change') - expect(this.view.postRenderTemplate).toHaveBeenCalled() - }) - }) + spyOn(this.view, "postRenderTemplate"); + this.view.model.interactions.trigger('change'); + expect(this.view.postRenderTemplate).toHaveBeenCalled(); + }); + }); describe("showAvatars", function(){ beforeEach(function(){ - spyOn(this.post.interactions, "fetch").and.callThrough() - }) + spyOn(this.post.interactions, "fetch").and.callThrough(); + }); it("calls fetch on the model's like collection", function(){ this.view.showAvatars(); expect(this.post.interactions.fetch).toHaveBeenCalled(); - }) + }); it("sets the fetched response to the model's likes", function(){ //placeholder... not sure how to test done functionalty here - }) + }); it("re-renders the view", function(){ //placeholder... not sure how to test done functionalty here - }) - }) -}) - + }); + }); +}); diff --git a/spec/javascripts/app/views/location_view_spec.js b/spec/javascripts/app/views/location_view_spec.js index 68e5ac59b..42e04741c 100644 --- a/spec/javascripts/app/views/location_view_spec.js +++ b/spec/javascripts/app/views/location_view_spec.js @@ -12,6 +12,6 @@ describe("app.views.Location", function(){ expect($("#location_address")).toBeTruthy(); expect($("#location_coords")).toBeTruthy(); expect($("#hide_location")).toBeTruthy(); - }) + }); }); }); diff --git a/spec/javascripts/app/views/notifications_view_spec.js b/spec/javascripts/app/views/notifications_view_spec.js index 12034e4a6..34312118a 100644 --- a/spec/javascripts/app/views/notifications_view_spec.js +++ b/spec/javascripts/app/views/notifications_view_spec.js @@ -40,8 +40,8 @@ describe("app.views.Notifications", function(){ }); it('changes the "all notifications" count', function() { - badge = $('ul.nav > li:eq(0) .badge'); - count = parseInt(badge.text()); + var badge = $('ul.nav > li:eq(0) .badge'); + var count = parseInt(badge.text()); this.view.updateView(this.guid, this.type, true); expect(parseInt(badge.text())).toBe(count + 1); @@ -51,8 +51,8 @@ describe("app.views.Notifications", function(){ }); it('changes the notification type count', function() { - badge = $('ul.nav > li[data-type=' + this.type + '] .badge'); - count = parseInt(badge.text()); + var badge = $('ul.nav > li[data-type=' + this.type + '] .badge'); + var count = parseInt(badge.text()); this.view.updateView(this.guid, this.type, true); expect(parseInt(badge.text())).toBe(count + 1); diff --git a/spec/javascripts/app/views/oembed_view_spec.js b/spec/javascripts/app/views/oembed_view_spec.js index 7af824d20..f46f8c91c 100644 --- a/spec/javascripts/app/views/oembed_view_spec.js +++ b/spec/javascripts/app/views/oembed_view_spec.js @@ -9,7 +9,7 @@ describe("app.views.OEmbed", function(){ } }); - this.view = new app.views.OEmbed({model : this.statusMessage}) + this.view = new app.views.OEmbed({model : this.statusMessage}); }); describe("rendering", function(){ @@ -27,7 +27,7 @@ describe("app.views.OEmbed", function(){ it("should set types.video on the data", function() { this.view.render(); - expect(this.view.model.get("o_embed_cache").data.types.video).toBe(true) + expect(this.view.model.get("o_embed_cache").data.types.video).toBe(true); }); it("shows the thumb with overlay", function(){ @@ -53,20 +53,20 @@ describe("app.views.OEmbed", function(){ }); it("provides oembed html from the model response", function(){ - this.view.render() - expect(this.view.$el.html()).toContain("some html") + this.view.render(); + expect(this.view.$el.html()).toContain("some html"); }); }); }); describe("presenter", function(){ it("provides oembed html from the model", function(){ - expect(this.view.presenter().o_embed_html).toContain("some html") + expect(this.view.presenter().o_embed_html).toContain("some html"); }); it("does not provide oembed html from the model response if none is present", function(){ - this.statusMessage.set({"o_embed_cache" : null}) + this.statusMessage.set({"o_embed_cache" : null}); expect(this.view.presenter().o_embed_html).toBe(""); }); }); -}); \ No newline at end of file +}); diff --git a/spec/javascripts/app/views/open_graph_view_spec.js b/spec/javascripts/app/views/open_graph_view_spec.js index d17c345ba..77bba41a1 100644 --- a/spec/javascripts/app/views/open_graph_view_spec.js +++ b/spec/javascripts/app/views/open_graph_view_spec.js @@ -12,7 +12,7 @@ describe("app.views.OpenGraph", function() { "open_graph_cache": open_graph_cache }); - this.view = new app.views.OpenGraph({model : this.statusMessage}) + this.view = new app.views.OpenGraph({model : this.statusMessage}); }); describe("rendering", function(){ diff --git a/spec/javascripts/app/views/photo_viewer_spec.js b/spec/javascripts/app/views/photo_viewer_spec.js index 6f25d580b..645f50d21 100644 --- a/spec/javascripts/app/views/photo_viewer_spec.js +++ b/spec/javascripts/app/views/photo_viewer_spec.js @@ -5,15 +5,15 @@ describe("app.views.PhotoViewer", function(){ factory.photoAttrs({sizes : {large : "http://tieguy.org/me.jpg"}}), factory.photoAttrs({sizes : {large : "http://whatthefuckiselizabethstarkupto.com/none_knows.gif"}}) //SIC ] - }) - this.view = new app.views.PhotoViewer({model : this.model}) - }) + }); + this.view = new app.views.PhotoViewer({model : this.model}); + }); describe("rendering", function(){ it("should have an image for each photoAttr on the model", function(){ - this.view.render() - expect(this.view.$("img").length).toBe(2) - expect(this.view.$("img[src='http://tieguy.org/me.jpg']")).toExist() - }) - }) -}) \ No newline at end of file + this.view.render(); + expect(this.view.$("img").length).toBe(2); + expect(this.view.$("img[src='http://tieguy.org/me.jpg']")).toExist(); + }); + }); +}); diff --git a/spec/javascripts/app/views/poll_view_spec.js b/spec/javascripts/app/views/poll_view_spec.js index 04124467c..8f86d6eb3 100644 --- a/spec/javascripts/app/views/poll_view_spec.js +++ b/spec/javascripts/app/views/poll_view_spec.js @@ -10,7 +10,7 @@ describe("app.views.Poll", function(){ var percentage = (this.view.poll.poll_answers[0].vote_count / this.view.poll.participation_count)*100; expect(this.view.$('.poll_progress_bar:first').css('width')).toBe(percentage+"%"); expect(this.view.$(".percentage:first").text()).toBe(percentage + "%"); - }) + }); }); describe("toggleResult", function(){ @@ -18,7 +18,7 @@ describe("app.views.Poll", function(){ expect(this.view.$('.poll_progress_bar_wrapper:first').css('display')).toBe("none"); this.view.toggleResult(null); expect(this.view.$('.poll_progress_bar_wrapper:first').css('display')).toBe("block"); - }) + }); }); describe("vote", function(){ @@ -32,7 +32,7 @@ describe("app.views.Poll", function(){ var obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params); expect(obj.poll_id).toBe(poll.poll_id); expect(obj.poll_answer_id).toBe(answer.id); - }) + }); }); describe("render", function() { diff --git a/spec/javascripts/app/views/publisher_view_spec.js b/spec/javascripts/app/views/publisher_view_spec.js index 95f9db4ad..b52e9d678 100644 --- a/spec/javascripts/app/views/publisher_view_spec.js +++ b/spec/javascripts/app/views/publisher_view_spec.js @@ -55,7 +55,7 @@ describe("app.views.Publisher", function() { it("removes the 'active' class from the publisher element", function(){ this.view.close($.Event()); expect($(this.view.el)).toHaveClass("closed"); - }) + }); it("resets the element's height", function() { $(this.view.el).find("#status_message_fake_text").height(100); @@ -70,14 +70,14 @@ describe("app.views.Publisher", function() { this.view.clear($.Event()); expect(this.view.close).toHaveBeenCalled(); - }) + }); it("calls removePostPreview", function(){ spyOn(this.view, "removePostPreview"); this.view.clear($.Event()); expect(this.view.removePostPreview).toHaveBeenCalled(); - }) + }); it("clears all textareas", function(){ _.each(this.view.$("textarea"), function(element){ @@ -90,27 +90,27 @@ describe("app.views.Publisher", function() { _.each(this.view.$("textarea"), function(element){ expect($(element).val()).toBe(""); }); - }) + }); it("removes all photos from the dropzone area", function(){ var self = this; _.times(3, function(){ - self.view.el_photozone.append($("
  • ")) + self.view.el_photozone.append($("
  • ")); }); expect(this.view.el_photozone.html()).not.toBe(""); this.view.clear($.Event()); expect(this.view.el_photozone.html()).toBe(""); - }) + }); it("removes all photo values appended by the photo uploader", function(){ - $(this.view.el).prepend("") + $(this.view.el).prepend(""); var photoValuesInput = this.view.$("input[name='photos[]']"); - photoValuesInput.val("3") + photoValuesInput.val("3"); this.view.clear($.Event()); expect(this.view.$("input[name='photos[]']").length).toBe(0); - }) + }); it("destroy location if exists", function(){ setFixtures('
    '); @@ -119,7 +119,7 @@ describe("app.views.Publisher", function() { expect($("#location").length).toBe(1); this.view.clear($.Event()); expect($("#location").length).toBe(0); - }) + }); }); describe("createStatusMessage", function(){ @@ -127,7 +127,7 @@ describe("app.views.Publisher", function() { spyOn(this.view, "handleTextchange"); this.view.createStatusMessage($.Event()); expect(this.view.handleTextchange).toHaveBeenCalled(); - }) + }); }); describe('#setText', function() { @@ -165,7 +165,7 @@ describe("app.views.Publisher", function() { describe("publishing a post with keyboard", function(){ it("should submit the form when ctrl+enter is pressed", function(){ this.view.render(); - var form = this.view.$("form") + var form = this.view.$("form"); var submitCallback = jasmine.createSpy().and.returnValue(false); form.submit(submitCallback); @@ -175,7 +175,7 @@ describe("app.views.Publisher", function() { expect(submitCallback).toHaveBeenCalled(); expect($(this.view.el)).not.toHaveClass("closed"); - }) + }); }); describe("_beforeUnload", function(){ @@ -202,7 +202,7 @@ describe("app.views.Publisher", function() { expect(this.view._beforeUnload(e)).toBe(undefined); expect(e.returnValue).toBe(undefined); }); - }) + }); }); context("services", function(){ @@ -356,7 +356,7 @@ describe("app.views.Publisher", function() { this.view.view_aspect_selector.toggleAspect(evt); expect($('input[name="aspect_ids[]"][value="42"]').length).toBe(1); - var evt = $.Event("click", { target: $('.aspect_dropdown li.aspect_selector:last') }); + evt = $.Event("click", { target: $('.aspect_dropdown li.aspect_selector:last') }); this.view.view_aspect_selector.toggleAspect(evt); expect($('input[name="aspect_ids[]"][value="42"]').length).toBe(0); }); @@ -401,7 +401,7 @@ describe("app.views.Publisher", function() { // validates there is one location created expect($("#location").length).toBe(1); - }) + }); }); describe('#destroyLocation', function(){ @@ -411,18 +411,18 @@ describe("app.views.Publisher", function() { this.view.destroyLocation(); expect($("#location").length).toBe(0); - }) + }); }); describe('#avoidEnter', function(){ it("Avoid submitting the form when pressing enter", function(){ // simulates the event object - evt = {}; + var evt = {}; evt.keyCode = 13; // should return false in order to avoid the form submition expect(this.view.avoidEnter(evt)).toBeFalsy(); - }) + }); }); }); @@ -443,7 +443,7 @@ describe("app.views.Publisher", function() { it('initializes the file uploader plugin', function() { spyOn(qq, 'FileUploaderBasic'); - var publisher = new app.views.Publisher(); + new app.views.Publisher(); expect(qq.FileUploaderBasic).toHaveBeenCalled(); }); @@ -503,7 +503,7 @@ describe("app.views.Publisher", function() { it('shows it in text form', function() { var info = this.view.view_uploader.el_info; - expect(info.text()).toBe(Diaspora.I18n.t('photo_uploader.completed', {file: 'test.jpg'})) + expect(info.text()).toBe(Diaspora.I18n.t('photo_uploader.completed', {file: 'test.jpg'})); }); it('adds a hidden input to the publisher', function() { @@ -541,7 +541,7 @@ describe("app.views.Publisher", function() { it('shows error message', function() { var info = this.view.view_uploader.el_info; - expect(info.text()).toBe(Diaspora.I18n.t('photo_uploader.error', {file: 'test.jpg'})) + expect(info.text()).toBe(Diaspora.I18n.t('photo_uploader.error', {file: 'test.jpg'})); }); }); }); diff --git a/spec/javascripts/app/views/stream_faces_view_spec.js b/spec/javascripts/app/views/stream_faces_view_spec.js index 259dcd074..98d24897a 100644 --- a/spec/javascripts/app/views/stream_faces_view_spec.js +++ b/spec/javascripts/app/views/stream_faces_view_spec.js @@ -1,50 +1,50 @@ describe("app.views.StreamFaces", function(){ beforeEach(function(){ - var rebeccaBlack = factory.author({name : "Rebecca Black", id : 1492}) - this.post1 = factory.post({author : rebeccaBlack}) - this.post2 = factory.post({author : factory.author({name : "John Stamos", id : 1987})}) - this.post3 = factory.post({author : factory.author({name : "Michelle Tanner", id : 1986})}) - this.post4 = factory.post({author : factory.author({name : "Barack Obama", id : 2000})}) - this.post5 = factory.post({author : factory.author({name : "Obi-wan Kenobi", id : 2020})}) - this.post6 = factory.post({author : rebeccaBlack}) - this.post7 = factory.post({author : rebeccaBlack}) + var rebeccaBlack = factory.author({name : "Rebecca Black", id : 1492}); + this.post1 = factory.post({author : rebeccaBlack}); + this.post2 = factory.post({author : factory.author({name : "John Stamos", id : 1987})}); + this.post3 = factory.post({author : factory.author({name : "Michelle Tanner", id : 1986})}); + this.post4 = factory.post({author : factory.author({name : "Barack Obama", id : 2000})}); + this.post5 = factory.post({author : factory.author({name : "Obi-wan Kenobi", id : 2020})}); + this.post6 = factory.post({author : rebeccaBlack}); + this.post7 = factory.post({author : rebeccaBlack}); - app.stream = new app.models.Stream() + app.stream = new app.models.Stream(); app.stream.add([this.post1, this.post2, this.post3, this.post4, this.post5, this.post6, this.post7]); - this.posts = app.stream.items + this.posts = app.stream.items; - this.view = new app.views.StreamFaces({collection : this.posts}) - }) + this.view = new app.views.StreamFaces({collection : this.posts}); + }); it("should take them unique", function(){ - this.view.render() - expect(this.view.people.length).toBe(5) - }) + this.view.render(); + expect(this.view.people.length).toBe(5); + }); it("findsPeople when the collection changes", function(){ - this.posts.add(factory.post({author : factory.author({name : "Harriet Tubman"})})) - expect(this.view.people.length).toBe(6) - }) + this.posts.add(factory.post({author : factory.author({name : "Harriet Tubman"})})); + expect(this.view.people.length).toBe(6); + }); describe(".render", function(){ beforeEach(function(){ - this.view.render() - }) + this.view.render(); + }); it("appends the people's avatars", function(){ - expect(this.view.$("img").length).toBe(5) - }) + expect(this.view.$("img").length).toBe(5); + }); it("links to the people", function(){ - expect(this.view.$("a").length).toBe(5) - }) + expect(this.view.$("a").length).toBe(5); + }); it("rerenders when people are added, but caps to 15 people", function(){ - var posts = _.map(_.range(20), function(){ return factory.post()}) - this.posts.reset(posts) //add 20 posts silently to the collection - this.posts.add(factory.post()) //trigger an update - expect(this.view.$("img").length).toBe(15) - }) - }) -}) + var posts = _.map(_.range(20), function(){ return factory.post()}); + this.posts.reset(posts); //add 20 posts silently to the collection + this.posts.add(factory.post()); //trigger an update + expect(this.view.$("img").length).toBe(15); + }); + }); +}); diff --git a/spec/javascripts/app/views/stream_post_spec.js b/spec/javascripts/app/views/stream_post_spec.js index b997902fe..e660db727 100644 --- a/spec/javascripts/app/views/stream_post_spec.js +++ b/spec/javascripts/app/views/stream_post_spec.js @@ -1,16 +1,16 @@ describe("app.views.StreamPost", function(){ beforeEach(function(){ - this.PostViewClass = app.views.StreamPost + this.PostViewClass = app.views.StreamPost; var posts = $.parseJSON(spec.readFixture("stream_json")); this.collection = new app.collections.Posts(posts); this.statusMessage = this.collection.models[0]; this.reshare = this.collection.models[1]; - }) + }); describe("events", function(){ - var _PostViewClass = undefined; - var author_id = undefined; + var _PostViewClass, + authorId; beforeEach(function(){ _PostViewClass = this.PostViewClass; @@ -20,7 +20,7 @@ describe("app.views.StreamPost", function(){ describe("remove posts for blocked person", function(){ it("setup remove:author:posts:#{id} to #remove", function(){ spyOn(_PostViewClass.prototype, 'remove'); - view = new _PostViewClass({model : this.statusMessage}); + new _PostViewClass({model : this.statusMessage}); app.events.trigger('person:block:'+authorId); expect(_PostViewClass.prototype.remove).toHaveBeenCalled(); }); @@ -63,8 +63,8 @@ describe("app.views.StreamPost", function(){ one : "<%= count %> Like", other : "<%= count %> Likes" } - }}) - }) + }}); + }); context("reshare", function(){ it("displays a reshare count", function(){ @@ -84,34 +84,34 @@ describe("app.views.StreamPost", function(){ context("likes", function(){ it("displays a like count", function(){ - this.statusMessage.interactions.set({likes_count : 1}) + this.statusMessage.interactions.set({likes_count : 1}); var view = new this.PostViewClass({model : this.statusMessage}).render(); - expect($(view.el).html()).toContain(Diaspora.I18n.t('stream.likes', {count: 1})) - }) + expect($(view.el).html()).toContain(Diaspora.I18n.t('stream.likes', {count: 1})); + }); it("does not display a like count for 'zero'", function(){ - this.statusMessage.interactions.set({likes_count : 0}) + this.statusMessage.interactions.set({likes_count : 0}); var view = new this.PostViewClass({model : this.statusMessage}).render(); - expect($(view.el).html()).not.toContain("0 Likes") - }) - }) + expect($(view.el).html()).not.toContain("0 Likes"); + }); + }); context("embed_html", function(){ it("provides oembed html from the model response", function(){ - this.statusMessage.set({"o_embed_cache" : o_embed_cache}) + this.statusMessage.set({"o_embed_cache" : o_embed_cache}); var view = new app.views.StreamPost({model : this.statusMessage}).render(); - expect(view.$el.html()).toContain(o_embed_cache.data.html) - }) - }) + expect(view.$el.html()).toContain(o_embed_cache.data.html); + }); + }); context("og_html", function(){ it("provides opengraph preview based on the model reponse", function(){ this.statusMessage.set({"open_graph_cache" : open_graph_cache}); var view = new app.views.StreamPost({model : this.statusMessage}).render(); - expect(view.$el.html()).toContain(open_graph_cache.title) + expect(view.$el.html()).toContain(open_graph_cache.title); }); it("does not provide opengraph preview, when oembed is available", function(){ this.statusMessage.set({ @@ -120,23 +120,23 @@ describe("app.views.StreamPost", function(){ }); var view = new app.views.StreamPost({model : this.statusMessage}).render(); - expect(view.$el.html()).not.toContain(open_graph_cache.title) - }) + expect(view.$el.html()).not.toContain(open_graph_cache.title); + }); it("truncates long opengraph descriptions in stream view to be 250 chars or less", function() { this.statusMessage.set({"open_graph_cache" : open_graph_cache_extralong}); var view = new app.views.StreamPost({model : this.statusMessage}).render(); expect(view.$el.find('.og-description').html().length).toBeLessThan(251); }); - }) + }); context("user not signed in", function(){ it("does not provide a Feedback view", function(){ - logout() + logout(); var view = new this.PostViewClass({model : this.statusMessage}).render(); expect(view.feedbackView()).toBeFalsy(); - }) - }) + }); + }); context("NSFW", function(){ beforeEach(function(){ @@ -144,19 +144,19 @@ describe("app.views.StreamPost", function(){ this.view = new this.PostViewClass({model : this.statusMessage}).render(); this.hiddenPosts = function(){ - return this.view.$(".nsfw-shield") - } + return this.view.$(".nsfw-shield"); + }; }); it("contains a shield element", function(){ - expect(this.hiddenPosts().length).toBe(1) + expect(this.hiddenPosts().length).toBe(1); }); it("does not contain a shield element when nsfw is false", function(){ this.statusMessage.set({nsfw: false}); this.view.render(); expect(this.hiddenPosts()).not.toExist(); - }) + }); context("showing a single post", function(){ it("removes the shields when the post is clicked", function(){ @@ -168,12 +168,12 @@ describe("app.views.StreamPost", function(){ context("clicking the toggle nsfw link toggles it on the user", function(){ it("calls toggleNsfw on the user", function(){ - spyOn(app.user(), "toggleNsfwState") + spyOn(app.user(), "toggleNsfwState"); this.view.$(".toggle_nsfw_state").first().click(); expect(app.user().toggleNsfwState).toHaveBeenCalled(); }); - }) - }) + }); + }); context("user views their own post", function(){ beforeEach(function(){ @@ -181,11 +181,11 @@ describe("app.views.StreamPost", function(){ id : app.user().id }}); this.view = new this.PostViewClass({model : this.statusMessage}).render(); - }) + }); it("contains remove post", function(){ expect(this.view.$(".remove_post")).toExist(); - }) + }); it("destroys the view when they delete a their post from the show page", function(){ spyOn(window, "confirm").and.returnValue(true); @@ -194,8 +194,8 @@ describe("app.views.StreamPost", function(){ expect(window.confirm).toHaveBeenCalled(); expect(this.view.el).not.toBeInDOM(); - }) - }) + }); + }); - }) + }); }); diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js index 3935d13a2..412728222 100644 --- a/spec/javascripts/app/views/stream_view_spec.js +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -55,7 +55,7 @@ describe("app.views.Stream", function() { }); it("fetches moar when the user is at the bottom of the page", function() { - expect(this.view.model.fetch).toHaveBeenCalled() + expect(this.view.model.fetch).toHaveBeenCalled(); }); }); diff --git a/spec/javascripts/app/views/tag_following_action_view_spec.js b/spec/javascripts/app/views/tag_following_action_view_spec.js index 29f8b275c..8639ee5fa 100644 --- a/spec/javascripts/app/views/tag_following_action_view_spec.js +++ b/spec/javascripts/app/views/tag_following_action_view_spec.js @@ -2,22 +2,22 @@ describe("app.views.TagFollowingAction", function(){ beforeEach(function(){ app.tagFollowings = new app.collections.TagFollowings(); this.tagName = "test_tag"; - this.view = new app.views.TagFollowingAction({tagName : this.tagName}) - }) + this.view = new app.views.TagFollowingAction({tagName : this.tagName}); + }); describe("render", function(){ it("shows the output of followString", function(){ - spyOn(this.view, "tag_is_followed").and.returnValue(false) - spyOn(this.view, "followString").and.returnValue("a_follow_string") - expect(this.view.render().$('input').val()).toMatch(/^a_follow_string$/) - }) + spyOn(this.view, "tag_is_followed").and.returnValue(false); + spyOn(this.view, "followString").and.returnValue("a_follow_string"); + expect(this.view.render().$('input').val()).toMatch(/^a_follow_string$/); + }); it("should have the extra classes if the tag is followed", function(){ - spyOn(this.view, "tag_is_followed").and.returnValue(true) - expect(this.view.render().$('input').hasClass("followed")).toBe(true) - expect(this.view.render().$('input').hasClass("green")).toBe(true) - }) - }) + spyOn(this.view, "tag_is_followed").and.returnValue(true); + expect(this.view.render().$('input').hasClass("followed")).toBe(true); + expect(this.view.render().$('input').hasClass("green")).toBe(true); + }); + }); describe("tagAction", function(){ it("toggles the tagFollowed from followed to unfollowed", function(){ @@ -29,22 +29,22 @@ describe("app.views.TagFollowingAction", function(){ spyOn(this.view.model, "destroy").and.callFake(_.bind(function(){ // model.destroy leads to collection.remove, which is bound to getTagFollowing this.view.getTagFollowing(); - }, this) ) + }, this) ); this.view.tagAction(); - expect(origModel.destroy).toHaveBeenCalled() + expect(origModel.destroy).toHaveBeenCalled(); expect(this.view.tag_is_followed()).toBe(false); - }) + }); it("toggles the tagFollowed from unfollowed to followed", function(){ expect(this.view.tag_is_followed()).toBe(false); spyOn(app.tagFollowings, "create").and.callFake(function(model){ // 'save' the model by giving it an id - model.set("id", 3) - }) + model.set("id", 3); + }); this.view.tagAction(); expect(this.view.tag_is_followed()).toBe(true); - }) - }) -}) + }); + }); +}); diff --git a/spec/javascripts/app/views_spec.js b/spec/javascripts/app/views_spec.js index cf54c6eb0..ec8861577 100644 --- a/spec/javascripts/app/views_spec.js +++ b/spec/javascripts/app/views_spec.js @@ -1,22 +1,22 @@ describe("app.views.Base", function(){ describe("#render", function(){ beforeEach(function(){ - var staticTemplateClass = app.views.Base.extend({ templateName : "static-text" }) + var staticTemplateClass = app.views.Base.extend({ templateName : "static-text" }); - this.model = new Backbone.Model({text : "model attributes are in the default presenter"}) - this.view = new staticTemplateClass({model: this.model}) - this.view.render() - }) + this.model = new Backbone.Model({text : "model attributes are in the default presenter"}); + this.view = new staticTemplateClass({model: this.model}); + this.view.render(); + }); it("renders the template with the presenter", function(){ - expect($(this.view.el).text().trim()).toBe("model attributes are in the default presenter") - }) + expect($(this.view.el).text().trim()).toBe("model attributes are in the default presenter"); + }); it("it evaluates the presenter every render", function(){ - this.model.set({text : "OMG It's a party" }) - this.view.render() - expect($(this.view.el).text().trim()).toBe("OMG It's a party") - }) + this.model.set({text : "OMG It's a party" }); + this.view.render(); + expect($(this.view.el).text().trim()).toBe("OMG It's a party"); + }); context("subViewRendering", function(){ beforeEach(function(){ @@ -28,7 +28,7 @@ describe("app.views.Base", function(){ }, initialize : function(){ - this.subview1 = stubView("OMG First Subview") + this.subview1 = stubView("OMG First Subview"); }, presenter: { @@ -36,47 +36,47 @@ describe("app.views.Base", function(){ }, postRenderTemplate : function(){ - $(this.el).append("
    ") - $(this.el).append("
    ") + $(this.el).append("
    "); + $(this.el).append("
    "); }, createSubview2 : function(){ - return stubView("furreal this is the Second Subview") + return stubView("furreal this is the Second Subview"); } - }) + }); - this.view = new viewClass().render() - }) + this.view = new viewClass().render(); + }); it("repsects the respects the template rendered with the presenter", function(){ - expect(this.view.$('.text').text().trim()).toBe("this comes through on the original render") - }) + expect(this.view.$('.text').text().trim()).toBe("this comes through on the original render"); + }); it("renders subviews from views that are properties of the object", function(){ - expect(this.view.$('.subview1').text().trim()).toBe("OMG First Subview") - }) + expect(this.view.$('.subview1').text().trim()).toBe("OMG First Subview"); + }); it("renders the sub views from functions", function(){ - expect(this.view.$('.subview2').text().trim()).toBe("furreal this is the Second Subview") - }) - }) + expect(this.view.$('.subview2').text().trim()).toBe("furreal this is the Second Subview"); + }); + }); context("calling out to third party plugins", function(){ it("replaces .time with relative time ago in words", function(){ - spyOn($.fn, "timeago") - this.view.render() - expect($.fn.timeago).toHaveBeenCalled() - expect($.fn.timeago.calls.mostRecent().object.selector).toBe("time") - }) + spyOn($.fn, "timeago"); + this.view.render(); + expect($.fn.timeago).toHaveBeenCalled(); + expect($.fn.timeago.calls.mostRecent().object.selector).toBe("time"); + }); it("initializes tooltips declared with the view's tooltipSelector property", function(){ - this.view.tooltipSelector = ".christopher_columbus, .barrack_obama, .block_user" + this.view.tooltipSelector = ".christopher_columbus, .barrack_obama, .block_user"; - spyOn($.fn, "tooltip") - this.view.render() - expect($.fn.tooltip.calls.mostRecent().object.selector).toBe(".christopher_columbus, .barrack_obama, .block_user") - }) - }) - }) -}) + spyOn($.fn, "tooltip"); + this.view.render(); + expect($.fn.tooltip.calls.mostRecent().object.selector).toBe(".christopher_columbus, .barrack_obama, .block_user"); + }); + }); + }); +}); diff --git a/spec/javascripts/diaspora-spec.js b/spec/javascripts/diaspora-spec.js index 9c85666e5..944ee6ea7 100644 --- a/spec/javascripts/diaspora-spec.js +++ b/spec/javascripts/diaspora-spec.js @@ -57,8 +57,8 @@ describe("Diaspora", function() { describe("subscribe", function() { it("will subscribe to multiple events", function() { var firstEventCalled = false, - secondEventCalled = false - events = Diaspora.EventBroker.extend({}); + secondEventCalled = false, + events = Diaspora.EventBroker.extend({}); events.subscribe("first/event second/event", function() { if (firstEventCalled) { @@ -78,8 +78,8 @@ describe("Diaspora", function() { describe("publish", function() { it("will publish multiple events", function() { var firstEventCalled = false, - secondEventCalled = false - events = Diaspora.EventBroker.extend({}); + secondEventCalled = false, + events = Diaspora.EventBroker.extend({}); events.subscribe("first/event second/event", function() { if (firstEventCalled) { diff --git a/spec/javascripts/helpers/SpecHelper.js b/spec/javascripts/helpers/SpecHelper.js index 3b69d5dd5..9e7ac46cc 100644 --- a/spec/javascripts/helpers/SpecHelper.js +++ b/spec/javascripts/helpers/SpecHelper.js @@ -2,6 +2,45 @@ var realXMLHttpRequest = window.XMLHttpRequest; +// matches flash messages with success/error and contained text +var flashMatcher = function(flash, id, text) { + var textContained = true; + if( text ) { + textContained = (flash.text().indexOf(text) !== -1); + } + + return flash.is(id) && + flash.hasClass('expose') && + textContained; +}; + +// information for jshint +/* exported context */ +var context = describe; + +var spec = {}; +var customMatchers = { + toBeSuccessFlashMessage: function() { + return { + compare: function(actual, expected) { + var result = {}; + result.pass = flashMatcher(actual, '#flash_notice', expected); + return result; + } + }; + }, + toBeErrorFlashMessage: function() { + return { + compare: function(actual, expected) { + var result = {}; + result.pass = flashMatcher(actual, '#flash_error', expected); + return result; + } + }; + } +}; + + beforeEach(function() { $('#jasmine_content').html(spec.readFixture("underscore_templates")); @@ -33,66 +72,33 @@ afterEach(function() { jasmine.clock().uninstall(); jasmine.Ajax.uninstall(); - $("#jasmine_content").empty() + $("#jasmine_content").empty(); expect(spec.loadFixtureCount).toBeLessThan(2); spec.loadFixtureCount = 0; }); -// matches flash messages with success/error and contained text -var flashMatcher = function(flash, id, text) { - textContained = true; - if( text ) { - textContained = (flash.text().indexOf(text) !== -1); - } - - return flash.is(id) && - flash.hasClass('expose') && - textContained; -}; - -var context = describe; -var spec = {}; -var customMatchers = { - toBeSuccessFlashMessage: function(util) { - return { - compare: function(actual, expected) { - var result = {}; - result.pass = flashMatcher(actual, '#flash_notice', expected); - return result; - } - }; - }, - toBeErrorFlashMessage: function(util) { - return { - compare: function(actual, expected) { - var result = {}; - result.pass = flashMatcher(actual, '#flash_error', expected); - return result; - } - }; - } -}; - window.stubView = function stubView(text){ var stubClass = Backbone.View.extend({ render : function(){ $(this.el).html(text); - return this + return this; } - }) + }); - return new stubClass -} + return new stubClass(); +}; window.loginAs = function loginAs(attrs){ - return app.currentUser = app.user(factory.userAttrs(attrs)) -} + app.currentUser = app.user(factory.userAttrs(attrs)); + return app.currentUser; +}; window.logout = function logout(){ - this.app._user = undefined - return app.currentUser = new app.models.User() -} + this.app._user = undefined; + app.currentUser = new app.models.User(); + return app.currentUser; +}; window.hipsterIpsumFourParagraphs = "Mcsweeney's mumblecore irony fugiat, ex iphone brunch helvetica eiusmod retro" + " sustainable mlkshk. Pop-up gentrify velit readymade ad exercitation 3 wolf moon. Vinyl aute laboris artisan irony, " + @@ -119,12 +125,14 @@ window.hipsterIpsumFourParagraphs = "Mcsweeney's mumblecore irony fugiat, ex iph "mlkshk assumenda. Typewriter terry richardson pork belly, cupidatat tempor craft beer tofu sunt qui gentrify eiusmod " + "id. Letterpress pitchfork wayfarers, eu sunt lomo helvetica pickled dreamcatcher bicycle rights. Aliqua banksy " + "cliche, sapiente anim chambray williamsburg vinyl cardigan. Pork belly mcsweeney's anim aliqua. DIY vice portland " + - "thundercats est vegan etsy, gastropub helvetica aliqua. Artisan jean shorts american apparel duis esse trust fund." + "thundercats est vegan etsy, gastropub helvetica aliqua. Artisan jean shorts american apparel duis esse trust fund."; spec.clearLiveEventBindings = function() { var events = jQuery.data(document, "events"); - for (prop in events) { - delete events[prop]; + for (var prop in events) { + if(events.hasOwnProperty(prop)) { + delete events[prop]; + } } }; diff --git a/spec/javascripts/helpers/factory.js b/spec/javascripts/helpers/factory.js index b0e27ef87..c3efcafb7 100644 --- a/spec/javascripts/helpers/factory.js +++ b/spec/javascripts/helpers/factory.js @@ -1,13 +1,13 @@ -factory = { +var factory = { id : { current : 0, next : function(){ - return factory.id.current += 1 + return factory.id.current += 1; } }, guid : function(){ - return 'omGUID' + this.id.next() + return 'omGUID' + this.id.next(); }, like : function(overrides){ @@ -16,9 +16,9 @@ factory = { "author" : this.author(), "guid" : this.guid(), "id" : this.id.next() - } + }; - return _.extend(defaultAttrs, overrides) + return _.extend(defaultAttrs, overrides); }, comment : function(overrides) { @@ -28,17 +28,17 @@ factory = { "guid" : this.guid(), "id" : this.id.next(), "text" : "This is a comment!" - } + }; - return new app.models.Comment(_.extend(defaultAttrs, overrides)) + return new app.models.Comment(_.extend(defaultAttrs, overrides)); }, user : function(overrides) { - return new app.models.User(factory.userAttrs(overrides)) + return new app.models.User(factory.userAttrs(overrides)); }, userAttrs : function(overrides){ - var id = this.id.next() + var id = this.id.next(); var defaultAttrs = { "name":"Awesome User" + id, "id": id, @@ -47,9 +47,9 @@ factory = { "large":"http://localhost:3000/images/user/uma.jpg", "medium":"http://localhost:3000/images/user/uma.jpg", "small":"http://localhost:3000/images/user/uma.jpg"} - } + }; - return _.extend(defaultAttrs, overrides) + return _.extend(defaultAttrs, overrides); }, postAttrs : function(){ @@ -76,7 +76,7 @@ factory = { "likes" : [], "reshares" : [] } - } + }; }, profileAttrs: function(overrides) { @@ -145,16 +145,16 @@ factory = { medium: "http://localhost:3000/uploads/images/thumb_medium_d85410bd19db1016894c.jpg", small: "http://localhost:3000/uploads/images/thumb_small_d85410bd19db1016894c.jpg" } - }, overrides) + }, overrides); }, post : function(overrides) { - defaultAttrs = _.extend(factory.postAttrs(), {"author" : this.author()}) - return new app.models.Post(_.extend(defaultAttrs, overrides)) + var defaultAttrs = _.extend(factory.postAttrs(), {"author" : this.author()}); + return new app.models.Post(_.extend(defaultAttrs, overrides)); }, postWithPoll : function(overrides) { - defaultAttrs = _.extend(factory.postAttrs(), {"author" : this.author()}); + var defaultAttrs = _.extend(factory.postAttrs(), {"author" : this.author()}); defaultAttrs = _.extend(defaultAttrs, {"already_participated_in_poll" : false}); defaultAttrs = _.extend(defaultAttrs, {"poll" : factory.poll()}); return new app.models.Post(_.extend(defaultAttrs, overrides)); @@ -162,10 +162,10 @@ factory = { statusMessage : function(overrides){ //intentionally doesn't have an author to mirror creation process, maybe we should change the creation process - return new app.models.StatusMessage(_.extend(factory.postAttrs(), overrides)) + return new app.models.StatusMessage(_.extend(factory.postAttrs(), overrides)); }, - poll: function(overrides){ + poll: function(){ return { "question" : "This is an awesome question", "created_at" : "2012-01-03T19:53:13Z", @@ -175,19 +175,7 @@ factory = { "guid" : this.guid(), "poll_id": this.id.next(), "participation_count" : 10 - } - }, - - comment: function(overrides) { - var defaultAttrs = { - id: this.id.next(), - guid: this.guid(), - text: "This is an awesome comment!", - author: this.author(), - created_at: "2012-01-03T19:53:13Z" }; - - return new app.models.Comment(_.extend(defaultAttrs, overrides)) }, aspectAttrs: function(overrides) { @@ -212,6 +200,6 @@ factory = { window.gon = { preloads: {} }; _.extend(window.gon.preloads, defaults, overrides); } -} +}; factory.author = factory.userAttrs; diff --git a/spec/javascripts/helpers/mock-ajax.js b/spec/javascripts/helpers/mock-ajax.js index 9bd8c3f54..640287f8e 100644 --- a/spec/javascripts/helpers/mock-ajax.js +++ b/spec/javascripts/helpers/mock-ajax.js @@ -33,7 +33,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (function() { function extend(destination, source) { for (var property in source) { - destination[property] = source[property]; + if(source.hasOwnProperty(property)) { + destination[property] = source[property]; + } } return destination; } @@ -128,7 +130,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. onload: function() { }, - onreadystatechange: function(isTimeout) { + onreadystatechange: function() { }, status: null, @@ -225,7 +227,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. }; this.filter = function(url_to_match) { - if (requests.length == 0) return []; + if (requests.length === 0) return []; var matching_requests = []; for (var i = 0; i < requests.length; i++) { @@ -236,7 +238,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. url_to_match(requests[i])) { matching_requests.push(requests[i]); } else { - if (requests[i].url == url_to_match) { + if (requests[i].url === url_to_match) { matching_requests.push(requests[i]); } } diff --git a/spec/javascripts/osmlocator-spec.js b/spec/javascripts/osmlocator-spec.js index dbd6bcf3d..cc982e2bb 100644 --- a/spec/javascripts/osmlocator-spec.js +++ b/spec/javascripts/osmlocator-spec.js @@ -1,25 +1,25 @@ describe("Locator", function(){ navigator.geolocation = {}; navigator.geolocation.getCurrentPosition = function(myCallback){ - lat = 1; - lon = 2; - position = { coords: { latitude: lat, longitude: lon} } + var lat = 1; + var lon = 2; + var position = { coords: { latitude: lat, longitude: lon} }; return myCallback(position); }; $.getJSON = function(url, myCallback){ - if(url == "https://nominatim.openstreetmap.org/reverse?format=json&lat=1&lon=2&addressdetails=3") + if(url === "https://nominatim.openstreetmap.org/reverse?format=json&lat=1&lon=2&addressdetails=3") { - return myCallback({ display_name: 'locator address' }) + return myCallback({ display_name: 'locator address' }); } - } + }; var osmlocator = new OSM.Locator(); it("should return address, latitude, and longitude using getAddress method", function(){ osmlocator.getAddress(function(display_name, coordinates){ - expect(display_name, 'locator address') - expect(coordinates, { latitude: 1, longitude: 2 }) - }) + expect(display_name, 'locator address'); + expect(coordinates, { latitude: 1, longitude: 2 }); + }); }); }); diff --git a/spec/javascripts/rails-spec.js b/spec/javascripts/rails-spec.js index ae6424a21..5808daa6a 100644 --- a/spec/javascripts/rails-spec.js +++ b/spec/javascripts/rails-spec.js @@ -23,10 +23,10 @@ describe("rails", function() { it('should not clear normal hidden fields', function(){ $('#form').trigger('ajax:success'); expect($('#standard_hidden').val()).toEqual("keep this value"); - }) + }); it('should clear hidden fields marked clear_on_submit', function(){ $('#form').trigger('ajax:success'); expect($('#clearable_hidden').val()).toEqual(""); - }) + }); }); }); diff --git a/spec/javascripts/search-spec.js b/spec/javascripts/search-spec.js index 99f018dbf..ba767fe88 100644 --- a/spec/javascripts/search-spec.js +++ b/spec/javascripts/search-spec.js @@ -4,6 +4,7 @@ */ describe("List", function() { + /* global List */ describe("runDelayedSearch", function() { beforeEach( function(){ spec.loadFixture('empty_people_search'); diff --git a/spec/javascripts/widgets/i18n-spec.js b/spec/javascripts/widgets/i18n-spec.js index be404d73e..2315957ce 100644 --- a/spec/javascripts/widgets/i18n-spec.js +++ b/spec/javascripts/widgets/i18n-spec.js @@ -88,7 +88,7 @@ describe("Diaspora.I18n", function() { describe("::reset", function(){ it("clears the current locale", function() { Diaspora.I18n.load(locale, "en", locale); - Diaspora.I18n.reset() + Diaspora.I18n.reset(); expect(Diaspora.I18n.locale.data).toEqual({}); }); diff --git a/spec/javascripts/widgets/lightbox-spec.js b/spec/javascripts/widgets/lightbox-spec.js index 2ca0dfaad..52d5ee7f9 100644 --- a/spec/javascripts/widgets/lightbox-spec.js +++ b/spec/javascripts/widgets/lightbox-spec.js @@ -13,7 +13,7 @@ describe("Diaspora.Widgets.Lightbox", function() { imageClass: 'stream-photo' }; - classes = _.extend(defaults, opts); + var classes = _.extend(defaults, opts); var output = $('
    ').addClass(classes.imageParent); _.each(photos, function(photo){ @@ -48,7 +48,7 @@ describe("Diaspora.Widgets.Lightbox", function() { }); context("opens the lightbox correctly", function() { - var lightbox, page, photoElement; + var lightbox, photoElement; beforeEach(function() { $("#jasmine_content").append(createDummyMarkup()); @@ -67,7 +67,7 @@ describe("Diaspora.Widgets.Lightbox", function() { }); context("opens lightbox for differently named elements", function(){ - var lightbox, page, photoElement; + var lightbox, photoElement; beforeEach(function() { $("#jasmine_content").append(createDummyMarkup({ diff --git a/spec/javascripts/widgets/notifications-spec.js b/spec/javascripts/widgets/notifications-spec.js index f67955f82..9fd08458b 100644 --- a/spec/javascripts/widgets/notifications-spec.js +++ b/spec/javascripts/widgets/notifications-spec.js @@ -80,7 +80,7 @@ describe("Diaspora.Widgets.Notifications", function() { it("calls Notifications.changeNotificationCount", function() { notifications.decrementCount(); expect(notifications.changeNotificationCount).toHaveBeenCalled(); - }) + }); }); describe("incrementCount", function() { diff --git a/spec/javascripts/widgets/search-spec.js b/spec/javascripts/widgets/search-spec.js index e1f831af6..4f1fb659a 100644 --- a/spec/javascripts/widgets/search-spec.js +++ b/spec/javascripts/widgets/search-spec.js @@ -5,7 +5,7 @@ describe("Diaspora.Widgets.Search", function() { var search = Diaspora.BaseWidget.instantiate("Search", $("#jasmine_content > #searchForm")); var person = {"name": "