Moved JSHint into Qunit suite. It's much harder to forget about now!

This commit is contained in:
Robin Ward
2013-06-21 14:06:20 -04:00
parent a4dceed379
commit 82c21868f3
59 changed files with 4320 additions and 181 deletions

View File

@@ -15,7 +15,7 @@ Discourse.AdminEmailPreviewDigestController = Discourse.ObjectController.extend(
Discourse.EmailPreview.findDigest(this.get('lastSeen')).then(function (email) {
model.setProperties(email.getProperties('html_content', 'text_content'));
controller.set('loading', false);
})
});
}
});

View File

@@ -94,7 +94,7 @@ Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Pres
Discourse.AdminUser.findAll(this.get('query'), this.get('username')).then(function (result) {
adminUsersListController.set('content', result);
adminUsersListController.set('loading', false);
})
});
},

View File

@@ -14,7 +14,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({
.map(function(v,k){
return Em.String.i18n("admin.flags.summary.action_type_" + k, {count: v.length});
})
.join(",")
.join(",");
}.property(),
flaggers: function() {

View File

@@ -20,7 +20,7 @@ Discourse.GithubCommit = Discourse.Model.extend({
}.property("sha"),
timeAgo: function() {
return moment(this.get('commit.committer.date')).relativeAge({format: 'medium', leaveAgo: true})
return moment(this.get('commit.committer.date')).relativeAge({format: 'medium', leaveAgo: true});
}.property("commit.committer.date")
});

View File

@@ -14,12 +14,12 @@ Discourse.Group = Discourse.Model.extend({
if(id && !this.get('loaded')) {
var group = this;
Discourse.ajax('/admin/groups/' + this.get('id') + '/users').then(function(payload){
var users = Em.A()
var users = Em.A();
_.each(payload,function(user){
users.addObject(Discourse.User.create(user));
});
group.set('users', users)
group.set('loaded', true)
group.set('users', users);
group.set('loaded', true);
});
}
},
@@ -30,7 +30,7 @@ Discourse.Group = Discourse.Model.extend({
if(users) {
usernames = _.map(users, function(user){
return user.get('username');
}).join(',')
}).join(',');
}
return usernames;
}.property('users'),

View File

@@ -11,7 +11,7 @@ Discourse.AdminEmailIndexRoute = Discourse.Route.extend({
setupController: function(controller) {
Discourse.EmailSettings.find().then(function (model) {
controller.set('model', model);
})
});
},
renderTemplate: function() {

View File

@@ -9,7 +9,7 @@
var oneWeekAgo = function() {
return moment().subtract('days',7).format('YYYY-MM-DD');
}
};
Discourse.AdminEmailPreviewDigestRoute = Discourse.Route.extend(Discourse.ModelReady, {

View File

@@ -36,7 +36,7 @@ Discourse.AdminSiteContentEditRoute = Discourse.Route.extend({
Discourse.SiteContent.find(Em.get(model, 'content_type')).then(function (sc) {
controller.set('content', sc);
controller.set('loaded', true);
})
});
}

View File

@@ -199,7 +199,7 @@ Discourse = Ember.Application.createWithMixins({
// Reloading will refresh unbound properties
Discourse.KeyValueStore.abandonLocal();
window.location.reload();
})
});
},
authenticationComplete: function(options) {
@@ -255,7 +255,7 @@ Discourse = Ember.Application.createWithMixins({
if (fixture) {
return Ember.Deferred.promise(function(promise) {
promise.resolve(fixture);
})
});
}
return Ember.Deferred.promise(function (promise) {
@@ -263,7 +263,7 @@ Discourse = Ember.Application.createWithMixins({
args.success = function(xhr) {
Ember.run(promise, promise.resolve, xhr);
if (oldSuccess) oldSuccess(xhr);
}
};
var oldError = args.error;
args.error = function(xhr) {
@@ -273,7 +273,7 @@ Discourse = Ember.Application.createWithMixins({
promise.reject(xhr);
if (oldError) oldError(xhr);
}
};
// We default to JSON on GET. If we don't, sometimes if the server doesn't return the proper header
// it will not be parsed as an object.
@@ -307,7 +307,7 @@ Discourse = Ember.Application.createWithMixins({
bus.subscribe("/categories", function(data){
var site = Discourse.Site.instance();
_.each(data.categories,function(c){
site.updateCategory(c)
site.updateCategory(c);
});
});

View File

@@ -158,7 +158,7 @@ Discourse.BBCode = {
extractQuotes: function(text) {
var result = {text: "" + text, replacements: []};
var replacements = []
var replacements = [];
var matches;
while (matches = Discourse.BBCode.QUOTE_REGEXP.exec(result.text)) {
@@ -178,7 +178,7 @@ Discourse.BBCode = {
input = input.replace(r.key, val);
});
return input;
}
};
return(result);
},
@@ -192,21 +192,24 @@ Discourse.BBCode = {
**/
formatQuote: function(text, opts) {
var args, matches, params, paramsSplit, paramsString, templateName, username;
var splitter = function(p,i) {
if (i > 0) {
var assignment = p.split(':');
if (assignment[0] && assignment[1]) {
return params.push({
key: assignment[0],
value: assignment[1].trim()
});
}
}
};
while (matches = this.QUOTE_REGEXP.exec(text)) {
paramsString = matches[1].replace(/\"/g, '');
paramsSplit = paramsString.split(/\, */);
params = [];
_.each(paramsSplit,function(p,i) {
if (i > 0) {
var assignment = p.split(':');
if (assignment[0] && assignment[1]) {
return params.push({
key: assignment[0],
value: assignment[1].trim()
});
}
}
});
_.each(paramsSplit, splitter);
username = paramsSplit[0];
// remove leading <br>s

View File

@@ -59,12 +59,12 @@ Discourse.debouncePromise = function(func, wait) {
timeout = Em.run.later(function () {
timeout = null;
func.apply(context, args).then(function (y) {
promise.resolve(y)
promise.resolve(y);
});
}, wait);
}
return promise;
}
};
};

View File

@@ -1,3 +1,5 @@
/*jshint onecase:true */
Discourse.Formatter = (function(){
var updateRelativeAge, autoUpdatingRelativeAge, relativeAge, relativeAgeTiny,
@@ -15,7 +17,7 @@ Discourse.Formatter = (function(){
return str.replace(/\w\S*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
};
longDate = function(dt) {
if (!dt) return;
@@ -105,7 +107,7 @@ Discourse.Formatter = (function(){
var t = function(key, opts){
return Ember.String.i18n("dates.medium" + (leaveAgo?"_with_ago":"") + "." + key, opts);
}
};
switch(true){
case(distanceInMinutes >= 1 && distanceInMinutes <= 56):

View File

@@ -47,5 +47,5 @@ Discourse.KeyValueStore = {
}
return localStorage[this.context + key];
}
}
};

View File

@@ -17,4 +17,4 @@ Discourse.Lightbox = {
});
});
}
}
};

View File

@@ -58,7 +58,7 @@ Discourse.Onebox = {
var loadingFinished = function() {
$elem.removeClass('loading-onebox');
$elem.data('onebox-loaded');
}
};
var onebox = this;
promise.then(function(html) {

View File

@@ -110,8 +110,8 @@
}
return r;
}
}
};
};
clear();

View File

@@ -21,7 +21,7 @@ Discourse.Search = {
if (!opts) opts = {};
// Only include the data we have
var data = { term: term }
var data = { term: term };
if (opts.typeFilter) data.type_filter = opts.typeFilter;
if (opts.searchContext) {
@@ -34,5 +34,5 @@ Discourse.Search = {
return Discourse.ajax('/search', { data: data });
}
}
};

View File

@@ -96,7 +96,7 @@ Discourse.EditCategoryController = Discourse.ObjectController.extend(Discourse.M
}.property(),
showCategoryTopic: function() {
this.send('closeModal')
this.send('closeModal');
Discourse.URL.routeTo(this.get('topic_url'));
return false;
},

View File

@@ -27,7 +27,7 @@ Discourse.FlagActionTypeController = Discourse.ObjectController.extend({
showDescription: Em.computed.not('showMessageInput'),
customMessageLengthClasses: function() {
return (this.get('message.length') < Discourse.SiteSettings.min_private_message_post_length) ? "too-short" : "ok"
return (this.get('message.length') < Discourse.SiteSettings.min_private_message_post_length) ? "too-short" : "ok";
}.property('message.length'),
customMessageLength: function() {

View File

@@ -43,14 +43,14 @@ Discourse.FlagController = Discourse.ObjectController.extend(Discourse.ModalFunc
}.property('selected.is_custom_flag'),
takeAction: function() {
this.createFlag({takeAction: true})
this.createFlag({takeAction: true});
this.set('hidden', true);
},
createFlag: function(opts) {
var flagController = this;
var postAction = this.get('actionByName.' + this.get('selected.name_key'));
var params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {}
var params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {};
if (opts) params = $.extend(params, opts);

View File

@@ -71,7 +71,7 @@ Discourse.LoginController = Discourse.Controller.extend(Discourse.ModalFunctiona
// Failed to login
loginController.flash(Em.String.i18n('login.error'), 'error');
loginController.set('loggingIn', false);
})
});
return false;
},
@@ -153,7 +153,7 @@ Discourse.LoginController = Discourse.Controller.extend(Discourse.ModalFunctiona
accountUsername: options.username,
accountName: options.name,
authOptions: Em.Object.create(options)
})
});
this.send('showCreateAccount');
}

View File

@@ -38,7 +38,7 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, {
var index = 0;
results = _(['topic', 'category', 'user'])
.map(function(n){
return _(results).where({type: n}).first()
return _(results).where({type: n}).first();
})
.compact()
.each(function(list){

View File

@@ -223,7 +223,7 @@ Handlebars.registerHelper('editDate', function(property, options) {
**/
Ember.Handlebars.registerHelper('percentile', function(property, options) {
var percentile = Ember.Handlebars.get(this, property, options);
return Math.round((1.0 - percentile) * 100)
return Math.round((1.0 - percentile) * 100);
});
/**
@@ -236,7 +236,7 @@ Ember.Handlebars.registerHelper('float', function(property, options) {
var x = Ember.Handlebars.get(this, property, options);
if (!x) return "0";
if (Math.round(x) === x) return x;
return x.toFixed(3)
return x.toFixed(3);
});
/**

View File

@@ -66,4 +66,4 @@ Discourse.ScrollingDOMMethods = {
$(document).unbind('touchmove.discourse');
}
}
};

View File

@@ -49,10 +49,10 @@ Discourse.CategoryList.reopenClass({
var finder = null;
if (filter === 'categories') {
finder = PreloadStore.getAndRemove("categories_list", function() {
return Discourse.ajax("/categories.json")
return Discourse.ajax("/categories.json");
});
} else {
finder = Discourse.ajax("/" + filter + ".json")
finder = Discourse.ajax("/" + filter + ".json");
}
return finder.then(function(result) {
@@ -63,7 +63,7 @@ Discourse.CategoryList.reopenClass({
categories: route.categoriesFrom(result),
draft_key: result.category_list.draft_key,
draft_sequence: result.category_list.draft_sequence
})
});
return categoryList;
});
}

View File

@@ -10,4 +10,4 @@ Discourse.PostActionType = Discourse.Model.extend({});
Discourse.PostActionType.reopenClass({
MAX_MESSAGE_LENGTH: 500
})
});

View File

@@ -1,24 +1,28 @@
// this allows you to track the selected item in an array, ghetto for now
Discourse.SelectableArray = Em.ArrayProxy.extend({
init: function() {
this.content = [];
this._super();
},
selectIndex: function(index){
this.select(this[index]);
},
select: function(selected){
_.each(this.content,function(item){
if(item === selected){
Em.set(item, "active", true)
Em.set(item, "active", true);
} else {
if (item.get("active")) {
Em.set(item, "active", false)
Em.set(item, "active", false);
}
}
});
this.set("active", selected);
},
removeObject: function(object) {
if(object === this.get("active")){
this.set("active", null);
@@ -27,4 +31,5 @@ Discourse.SelectableArray = Em.ArrayProxy.extend({
this._super(object);
}
});

View File

@@ -69,7 +69,7 @@ Discourse.Topic = Discourse.Model.extend({
// The last post in the topic
lastPost: function() {
var posts = this.get('posts')
var posts = this.get('posts');
return posts[posts.length-1];
},
@@ -287,7 +287,7 @@ Discourse.Topic = Discourse.Model.extend({
topic.set('allowed_users', Em.A(result.allowed_users));
topic.set('loaded', true);
}
};
var errorLoadingTopic = function(result) {
@@ -295,22 +295,22 @@ Discourse.Topic = Discourse.Model.extend({
// If the result was 404 the post is not found
if (result.status === 404) {
topic.set('errorTitle', Em.String.i18n('topic.not_found.title'))
topic.set('errorTitle', Em.String.i18n('topic.not_found.title'));
topic.set('message', Em.String.i18n('topic.not_found.description'));
return;
}
// If the result is 403 it means invalid access
if (result.status === 403) {
topic.set('errorTitle', Em.String.i18n('topic.invalid_access.title'))
topic.set('errorTitle', Em.String.i18n('topic.invalid_access.title'));
topic.set('message', Em.String.i18n('topic.invalid_access.description'));
return;
}
// Otherwise supply a generic error message
topic.set('errorTitle', Em.String.i18n('topic.server_error.title'))
topic.set('errorTitle', Em.String.i18n('topic.server_error.title'));
topic.set('message', Em.String.i18n('topic.server_error.description'));
}
};
// Finally, call our find method
return Discourse.Topic.find(this.get('id'), {

View File

@@ -148,7 +148,7 @@ Discourse.TopicList.reopenClass({
var url = Discourse.getURL("/") + filter + ".json";
if (excludeCategory) { url += "?exclude_category=" + excludeCategory; }
return Discourse.ajax(url);
}
};
return PreloadStore.getAndRemove("topic_list", finder).then(function(result) {
var topicList = Discourse.TopicList.create({

View File

@@ -30,7 +30,7 @@ Discourse.Route.buildRoutes(function() {
});
// the homepage is the first item of the 'top_menu' site setting
var settings = Discourse.SiteSettings || PreloadStore.get('siteSettings')
var settings = Discourse.SiteSettings || PreloadStore.get('siteSettings');
var homepage = settings.top_menu.split("|")[0].split(",")[0];
this.route(homepage, { path: '/' });

View File

@@ -18,8 +18,9 @@ var popstateReady = false;
Ember.DiscourseLocation = Ember.Object.extend({
init: function() {
set(this, 'location', get(this, 'location') || window.location);
if ( $.inArray('state', $.event.props) < 0 )
jQuery.event.props.push('state')
if ( $.inArray('state', $.event.props) < 0 ) {
jQuery.event.props.push('state');
}
this.initState();
},

View File

@@ -16,7 +16,7 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({
var uncategorized = Discourse.Category.uncategorizedInstance();
if (slug === uncategorized.get('slug')) return uncategorized;
var category = categories.findProperty('slug', Em.get(params, 'slug'))
var category = categories.findProperty('slug', Em.get(params, 'slug'));
// In case the slug didn't work, try to find it by id instead.
if (!category) {

View File

@@ -34,7 +34,7 @@ Discourse.TopicRoute = Discourse.Route.extend({
},
showPrivateInvite: function() {
Discourse.Route.showModal(this, 'invitePrivate', this.modelFor('topic'))
Discourse.Route.showModal(this, 'invitePrivate', this.modelFor('topic'));
this.controllerFor('invitePrivate').setProperties({
email: null,
error: false,
@@ -46,7 +46,7 @@ Discourse.TopicRoute = Discourse.Route.extend({
showHistory: function(post) {
Discourse.Route.showModal(this, 'history', post);
this.controllerFor('history').refresh();
this.controllerFor('modal').set('modalClass', 'history-modal')
this.controllerFor('modal').set('modalClass', 'history-modal');
},
mergeTopic: function() {

View File

@@ -15,7 +15,7 @@ Discourse.AutoCloseFormView = Ember.View.extend({
autoCloseChanged: function() {
if( this.get('autoCloseDays') && this.get('autoCloseDays').length > 0 ) {
this.set('autoCloseDays', this.get('autoCloseDays').replace(/[^\d]/g, '') )
this.set('autoCloseDays', this.get('autoCloseDays').replace(/[^\d]/g, '') );
}
}.observes('autoCloseDays')
});

View File

@@ -14,7 +14,7 @@ Discourse.ClearPinButton = Discourse.ButtonView.extend({
// Hide the button if it becomes unpinned
unpinned: function() {
// When not logged in don't show the button
if (!Discourse.User.current()) return 'hidden'
if (!Discourse.User.current()) return 'hidden';
return this.get('controller.pinned') ? null : 'hidden';
}.property('controller.pinned'),

View File

@@ -104,7 +104,7 @@ Discourse.HeaderView = Discourse.View.extend({
if(logo && logo.length > 1) {
result += "<img class='logo-big' src=\"" + logo + "\" alt=\"" + Discourse.SiteSettings.title + "\" id='site-logo'>";
} else {
result += "<h2 class='text-logo' id='site-text-logo'>" + Discourse.SiteSettings.title + "</h2>"
result += "<h2 class='text-logo' id='site-text-logo'>" + Discourse.SiteSettings.title + "</h2>";
}
}
result += "</a></div>";

View File

@@ -66,7 +66,7 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
if (!hasMoreResults) {
listTopicsView.get('eyeline').flushRest();
}
})
});
},
// Remember where we were scrolled to

View File

@@ -31,7 +31,7 @@ Discourse.PopupInputTipView = Discourse.View.extend({
bounce: function() {
if( this.get('shownAt') ) {
var $elem = this.$()
var $elem = this.$();
if( !this.animateAttribute ) {
this.animateAttribute = $elem.css('left') === 'auto' ? 'right' : 'left';
}

View File

@@ -54,7 +54,7 @@ Discourse.TopicClosingView = Discourse.View.extend({
willDestroyElement: function() {
if( this.delayedRerender ) {
Em.run.cancel(this.delayedRerender)
Em.run.cancel(this.delayedRerender);
}
}
});

View File

@@ -46,7 +46,7 @@ Discourse.TopicSummaryView = Discourse.ContainerView.extend({
templateName: 'topic_summary/info',
topic: this.get('topic'),
summaryView: this
})
});
this.trigger('appendSummaryInformation', this);
},

View File

@@ -106,7 +106,7 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, {
this.resetExamineDockCache();
// this happens after route exit, stuff could have trickled in
this.set('controller.controllers.header.showExtraInfo', false)
this.set('controller.controllers.header.showExtraInfo', false);
},
didInsertElement: function(e) {

View File

@@ -28,4 +28,4 @@ Discourse.View.reopenClass({
});
}
})
});