From 96bf38757d183bf1da41084d18ca9d84abf8618d Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sat, 8 Mar 2014 00:37:28 -0500 Subject: [PATCH 1/4] Update indexOf polyfill MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated from the same source as the original comment. If IE8 isn’t supported then this can be removed. --- app/assets/javascripts/locales/i18n.js | 42 +++++++++----------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/locales/i18n.js b/app/assets/javascripts/locales/i18n.js index d8591f32715..05edb4fe225 100644 --- a/app/assets/javascripts/locales/i18n.js +++ b/app/assets/javascripts/locales/i18n.js @@ -1,40 +1,28 @@ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function(searchElement /*, fromIndex */) { - "use strict"; - - if (this === void 0 || this === null) { - throw new TypeError(); + Array.prototype.indexOf = function (searchElement, fromIndex) { + if ( this === undefined || this === null ) { + throw new TypeError( '"this" is null or not defined' ); } - var t = Object(this); - var len = t.length >>> 0; + var length = this.length >>> 0; // Hack to convert object.length to a UInt32 - if (len === 0) { - return -1; + fromIndex = +fromIndex || 0; + + if (Math.abs(fromIndex) === Infinity) { + fromIndex = 0; } - var n = 0; - if (arguments.length > 0) { - n = Number(arguments[1]); - if (n !== n) { // shortcut for verifying if it's NaN - n = 0; - } else if (n !== 0 && n !== (Infinity) && n !== -(Infinity)) { - n = (n > 0 || -1) * Math.floor(Math.abs(n)); + if (fromIndex < 0) { + fromIndex += length; + if (fromIndex < 0) { + fromIndex = 0; } } - if (n >= len) { - return -1; - } - - var k = n >= 0 - ? n - : Math.max(len - Math.abs(n), 0); - - for (; k < len; k++) { - if (k in t && t[k] === searchElement) { - return k; + for (;fromIndex < length; fromIndex++) { + if (this[fromIndex] === searchElement) { + return fromIndex; } } From 761822029623caa01aef9ef2350c4f010aae98ad Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sat, 8 Mar 2014 01:14:29 -0500 Subject: [PATCH 2/4] Add JSHint to Travis validation Run before the install as it acts as a fast fail vs the gem install time --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2d0c7231302..1e28bb360f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: ruby rvm: - 2.0.0 - 2.1.1 +before_install: + - npm i -g jshint + - jshint . before_script: - psql -c 'create database discourse_test;' -U postgres - export DISCOURSE_HOSTNAME=www.example.com From c47b9a1b84b44b20d53c1771825a8e01fd114900 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sat, 8 Mar 2014 01:31:02 -0500 Subject: [PATCH 3/4] Add jshintignore for failing files --- .jshintignore | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .jshintignore diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 00000000000..a9024da831c --- /dev/null +++ b/.jshintignore @@ -0,0 +1,16 @@ +app/assets/javascripts/defer/html-sanitizer-bundle.js +app/assets/javascripts/locales/ +lib/autospec/run-qunit.js +lib/headless-ember.js +lib/javascripts/locale/ +lib/javascripts/messageformat.js +lib/javascripts/moment.js +lib/javascripts/moment_locale/ +plugins/poll/assets/javascripts/poll_ui.js +public/javascripts/ +spec/phantom_js/smoke_test.js +test/javascripts/helpers/assertions.js +test/javascripts/helpers/parse_html.js +test/javascripts/helpers/qunit_helpers.js +test/javascripts/test_helper.js +vendor/ From 9f51ab347a23511d74ce075521446a869e5c7a24 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sat, 8 Mar 2014 01:35:12 -0500 Subject: [PATCH 4/4] JSHint: Add strict comparisons to poll_ui.js --- .jshintignore | 1 - plugins/poll/assets/javascripts/poll_ui.js | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.jshintignore b/.jshintignore index a9024da831c..a69f6a1f5e6 100644 --- a/.jshintignore +++ b/.jshintignore @@ -6,7 +6,6 @@ lib/javascripts/locale/ lib/javascripts/messageformat.js lib/javascripts/moment.js lib/javascripts/moment_locale/ -plugins/poll/assets/javascripts/poll_ui.js public/javascripts/ spec/phantom_js/smoke_test.js test/javascripts/helpers/assertions.js diff --git a/plugins/poll/assets/javascripts/poll_ui.js b/plugins/poll/assets/javascripts/poll_ui.js index 891254dc095..fdafc7ec268 100644 --- a/plugins/poll/assets/javascripts/poll_ui.js +++ b/plugins/poll/assets/javascripts/poll_ui.js @@ -14,7 +14,7 @@ var Poll = Discourse.Model.extend({ options.push(Ember.Object.create({ option: option, votes: json["options"][option], - checked: (option == selectedOption) + checked: (option === selectedOption) })); }); this.set('options', options); @@ -22,7 +22,7 @@ var Poll = Discourse.Model.extend({ saveVote: function(option) { this.get('options').forEach(function(opt) { - opt.set('checked', opt.get('option') == option); + opt.set('checked', opt.get('option') === option); }); return Discourse.ajax("/poll", { @@ -99,7 +99,7 @@ Discourse.PostView.reopen({ var view = initializePollView(this); var pollContainer = $post.find(".poll-ui:first"); - if (pollContainer.length == 0) { + if (pollContainer.length === 0) { pollContainer = $post.find("ul:first"); }