Skip to content

Add issues #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.DS_Store
package-lock.json
node_modules
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sonar.sources=dist
#sonar.inclusions=

# Path to tests
sonar.tests=tests
#sonar.tests=tests
#sonar.test.exclusions=
#sonar.test.inclusions=

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Migrate qunit tests to mocha

## [2.1.0] - 2019-02-09

### Added
Expand Down
8 changes: 4 additions & 4 deletions develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Install dependencies:

Verify that all automated tests are passing:

TODO
npm test

Open the unit tests:
Optionally, open the unit tests in a browser:

open tests/vanilla.html
open tests/jquery.html
open test/vanilla.html
open test/jquery.html


Importing from another new Stack Exchange site
Expand Down
25 changes: 10 additions & 15 deletions dist/upvotejs/upvotejs.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,18 @@
const enabledClass = 'upvotejs-enabled';

function init(dom, options) {
var total = 0;
var failed = 0;
var ret = dom.each(function() {
const jqdom = $(this);
methods.destroy(jqdom);

const id = jqdom.attr('id');
try {
total++;
const created = [];
try {
var ret = dom.each(function() {
const jqdom = $(this);
const id = jqdom.attr('id');
const obj = Upvote.create(id, options);
jqdom.data(namespace, obj);
} catch (e) {
failed++;
}
});
if (failed > 0) {
throw 'error: failed to create ' + failed + '/' + total + ' controllers';
created.push(jqdom);
});
} catch (e) {
created.forEach(obj => methods.destroy(obj));
throw e;
}
return ret;
}
Expand Down
51 changes: 45 additions & 6 deletions dist/upvotejs/upvotejs.vanilla.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO
// TODO
/*
* UpvoteJS - a Stack Exchange look-alike voting widget
* ----------------------------------------------------
Expand Down Expand Up @@ -27,10 +29,16 @@
* Upvote.create('id', {count: 5, upvoted: true});
*
*/
const a = 1;
if (a = a) {
console.log('foo');
}

const UpvoteJS = function(document) {
"use strict";

const Upvote = function() {
const upvoteClass = 'upvote';
const enabledClass = 'upvotejs-enabled';
const upvoteClass = 'upvote';
const upvoteOnClass = 'upvote-on';
const downvoteClass = 'downvote';
const downvoteOnClass = 'downvote-on';
Expand Down Expand Up @@ -135,7 +143,7 @@ const Upvote = function() {
const create = id => {
const dom = document.getElementById(id);
if (dom === null) {
throw 'error: could not find element with ID ' + id + ' in the DOM';
throw 'error: element with ID "' + id + '" must exist in the DOM';
}

if (Utils.classes(dom).includes(enabledClass)) {
Expand All @@ -146,7 +154,7 @@ const Upvote = function() {
const firstElementByClass = className => {
const list = dom.getElementsByClassName(className);
if (list === null) {
throw 'error: could not find element with class ' + className + ' within element with ID ' + id + ' in the DOM';
throw 'error: element with class "' + className + '" must exist within element with ID "' + id + '" in the DOM';
}
return list[0];
};
Expand Down Expand Up @@ -274,7 +282,7 @@ const Upvote = function() {
const callback = action => {
const data = model.data();
combinedParams.callback({
id: data.id,
id: id,
action: action,
newState: {
count: data.count,
Expand Down Expand Up @@ -345,4 +353,35 @@ const Upvote = function() {
return {
create: create
};
}();
};

(function(global, factory) {
"use strict";

if (typeof module === "object" && typeof module.exports === "object") {
const create = () => {
if (global.document) {
return factory(global, true);
}
return w => {
if (!w.document) {
throw new Error("UpvoteJS requires a window with a document");
}
return factory(w);
};
};
module.exports = create();
} else {
factory(global);
}
})(typeof window !== "undefined" ? window : this, function(window, noGlobal) {
const Upvote = UpvoteJS(window.document);
if (!noGlobal) {
window.Upvote = Upvote;
}
const a = 1;
if (a = a) {
console.log('foo');
}
return Upvote;
});
Loading