mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Migrate to Ember CLI (#11932)
This encompasses a lot of work done over the last year, much of which has already been merged into master. This is the final set of changes required to get Ember CLI running locally for development. From here on it will be bug fixes / enhancements. Co-authored-by: Jarek Radosz <jradosz@gmail.com> Co-authored-by: romanrizzi <rizziromanalejandro@gmail.com> Co-authored-by: Jarek Radosz <jradosz@gmail.com> Co-authored-by: romanrizzi <rizziromanalejandro@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
|||||||
import { getOwner, setDefaultOwner } from "discourse-common/lib/get-owner";
|
import { getOwner, setDefaultOwner } from "discourse-common/lib/get-owner";
|
||||||
import { setApplication, setResolver } from "@ember/test-helpers";
|
import { setApplication, setResolver } from "@ember/test-helpers";
|
||||||
import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
|
import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
|
||||||
|
import Application from "../app";
|
||||||
import MessageBus from "message-bus-client";
|
import MessageBus from "message-bus-client";
|
||||||
import PreloadStore from "discourse/lib/preload-store";
|
import PreloadStore from "discourse/lib/preload-store";
|
||||||
import QUnit from "qunit";
|
import QUnit from "qunit";
|
||||||
@@ -26,6 +27,8 @@ import { clearAppEventsCache } from "discourse/services/app-events";
|
|||||||
import { createHelperContext } from "discourse-common/lib/helpers";
|
import { createHelperContext } from "discourse-common/lib/helpers";
|
||||||
import deprecated from "discourse-common/lib/deprecated";
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
import { flushMap } from "discourse/models/store";
|
import { flushMap } from "discourse/models/store";
|
||||||
|
import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects";
|
||||||
|
import { setupApplicationTest } from "ember-qunit";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
|
|
||||||
const Plugin = $.fn.modal;
|
const Plugin = $.fn.modal;
|
||||||
@@ -55,9 +58,33 @@ function AcceptanceModal(option, _relatedTarget) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function setupTests(app, container) {
|
let app;
|
||||||
|
let started = false;
|
||||||
|
|
||||||
|
function createApplication(config, settings) {
|
||||||
|
app = Application.create(config);
|
||||||
|
setApplication(app);
|
||||||
setResolver(buildResolver("discourse").create({ namespace: app }));
|
setResolver(buildResolver("discourse").create({ namespace: app }));
|
||||||
|
|
||||||
|
let container = app.__registry__.container();
|
||||||
|
app.__container__ = container;
|
||||||
|
setDefaultOwner(container);
|
||||||
|
|
||||||
|
if (!started) {
|
||||||
|
app.start();
|
||||||
|
started = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.SiteSettings = settings;
|
||||||
|
registerObjects(container, app);
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupTestsCommon(application, container, config) {
|
||||||
|
application.rootElement = "#ember-testing";
|
||||||
|
application.setupForTesting();
|
||||||
|
application.injectTestHelpers();
|
||||||
|
|
||||||
sinon.config = {
|
sinon.config = {
|
||||||
injectIntoThis: false,
|
injectIntoThis: false,
|
||||||
injectInto: null,
|
injectInto: null,
|
||||||
@@ -69,13 +96,6 @@ export default function setupTests(app, container) {
|
|||||||
// Stop the message bus so we don't get ajax calls
|
// Stop the message bus so we don't get ajax calls
|
||||||
MessageBus.stop();
|
MessageBus.stop();
|
||||||
|
|
||||||
app.rootElement = "#ember-testing";
|
|
||||||
app.setupForTesting();
|
|
||||||
app.SiteSettings = currentSettings();
|
|
||||||
app.start();
|
|
||||||
bootbox.$body = $("#ember-testing");
|
|
||||||
$.fn.modal = AcceptanceModal;
|
|
||||||
|
|
||||||
// disable logster error reporting
|
// disable logster error reporting
|
||||||
if (window.Logster) {
|
if (window.Logster) {
|
||||||
window.Logster.enabled = false;
|
window.Logster.enabled = false;
|
||||||
@@ -83,6 +103,8 @@ export default function setupTests(app, container) {
|
|||||||
window.Logster = { enabled: false };
|
window.Logster = { enabled: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.fn.modal = AcceptanceModal;
|
||||||
|
|
||||||
let server;
|
let server;
|
||||||
|
|
||||||
Object.defineProperty(window, "server", {
|
Object.defineProperty(window, "server", {
|
||||||
@@ -123,7 +145,14 @@ export default function setupTests(app, container) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.testStart(function (ctx) {
|
QUnit.testStart(function (ctx) {
|
||||||
|
bootbox.$body = $("#ember-testing");
|
||||||
let settings = resetSettings();
|
let settings = resetSettings();
|
||||||
|
|
||||||
|
if (config) {
|
||||||
|
// Ember CLI testing environment
|
||||||
|
app = createApplication(config, settings);
|
||||||
|
}
|
||||||
|
|
||||||
server = createPretender;
|
server = createPretender;
|
||||||
server.handlers = [];
|
server.handlers = [];
|
||||||
applyDefaultHandlers(server);
|
applyDefaultHandlers(server);
|
||||||
@@ -190,10 +219,12 @@ export default function setupTests(app, container) {
|
|||||||
$(".modal-backdrop").remove();
|
$(".modal-backdrop").remove();
|
||||||
flushMap();
|
flushMap();
|
||||||
|
|
||||||
|
if (!setupApplicationTest) {
|
||||||
// ensures any event not removed is not leaking between tests
|
// ensures any event not removed is not leaking between tests
|
||||||
// most likely in intialisers, other places (controller, component...)
|
// most likely in intialisers, other places (controller, component...)
|
||||||
// should be fixed in code
|
// should be fixed in code
|
||||||
clearAppEventsCache(getOwner(this));
|
clearAppEventsCache(getOwner(this));
|
||||||
|
}
|
||||||
|
|
||||||
MessageBus.unsubscribe("*");
|
MessageBus.unsubscribe("*");
|
||||||
server = null;
|
server = null;
|
||||||
@@ -226,7 +257,23 @@ export default function setupTests(app, container) {
|
|||||||
|
|
||||||
// forces 0 as duration for all jquery animations
|
// forces 0 as duration for all jquery animations
|
||||||
jQuery.fx.off = true;
|
jQuery.fx.off = true;
|
||||||
setApplication(app);
|
|
||||||
setDefaultOwner(container);
|
setApplication(application);
|
||||||
|
setDefaultOwner(application.__container__);
|
||||||
resetSite();
|
resetSite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setupTestsLegacy(application) {
|
||||||
|
app = application;
|
||||||
|
setResolver(buildResolver("discourse").create({ namespace: app }));
|
||||||
|
setupTestsCommon(application, app.__container__);
|
||||||
|
|
||||||
|
app.SiteSettings = currentSettings();
|
||||||
|
app.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function setupTests(config) {
|
||||||
|
let settings = resetSettings();
|
||||||
|
app = createApplication(config, settings);
|
||||||
|
setupTestsCommon(app, app.__container__, config);
|
||||||
|
}
|
||||||
|
|||||||
13
app/assets/javascripts/discourse/tests/test-helper.js
Normal file
13
app/assets/javascripts/discourse/tests/test-helper.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import config from "../config/environment";
|
||||||
|
import { setEnvironment } from "discourse-common/config/environment";
|
||||||
|
import { start } from "ember-qunit";
|
||||||
|
|
||||||
|
setEnvironment("testing");
|
||||||
|
|
||||||
|
document.addEventListener("discourse-booted", () => {
|
||||||
|
let setupTests = require("discourse/tests/setup-tests").default;
|
||||||
|
Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION = false;
|
||||||
|
|
||||||
|
setupTests(config.APP);
|
||||||
|
start();
|
||||||
|
});
|
||||||
@@ -50,7 +50,5 @@ document.write(
|
|||||||
"<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>"
|
"<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>"
|
||||||
);
|
);
|
||||||
|
|
||||||
let app = window.Discourse;
|
let setupTestsLegacy = require("discourse/tests/setup-tests").setupTestsLegacy;
|
||||||
app.injectTestHelpers();
|
setupTestsLegacy(window.Discourse);
|
||||||
let setupTests = require("discourse/tests/setup-tests").default;
|
|
||||||
setupTests(app, app.__container__);
|
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ discourseModule("Unit | Controller | avatar-selector", function (hooks) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("avatarTemplate", function (assert) {
|
test("avatarTemplate", function (assert) {
|
||||||
const avatarSelectorController = this.owner.lookup(
|
|
||||||
"controller:avatar-selector"
|
|
||||||
);
|
|
||||||
|
|
||||||
const user = EmberObject.create({
|
const user = EmberObject.create({
|
||||||
avatar_template: "avatar",
|
avatar_template: "avatar",
|
||||||
system_avatar_template: "system",
|
system_avatar_template: "system",
|
||||||
@@ -22,8 +18,9 @@ discourseModule("Unit | Controller | avatar-selector", function (hooks) {
|
|||||||
gravatar_avatar_upload_id: 2,
|
gravatar_avatar_upload_id: 2,
|
||||||
custom_avatar_upload_id: 3,
|
custom_avatar_upload_id: 3,
|
||||||
});
|
});
|
||||||
|
const avatarSelectorController = this.getController("avatar-selector", {
|
||||||
avatarSelectorController.setProperties({ user });
|
user,
|
||||||
|
});
|
||||||
|
|
||||||
user.set("avatar_template", "system");
|
user.set("avatar_template", "system");
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { test } from "qunit";
|
|||||||
|
|
||||||
discourseModule("Unit | Controller | create-account", function () {
|
discourseModule("Unit | Controller | create-account", function () {
|
||||||
test("basicUsernameValidation", async function (assert) {
|
test("basicUsernameValidation", async function (assert) {
|
||||||
const testInvalidUsername = async function (username, expectedReason) {
|
const testInvalidUsername = async (username, expectedReason) => {
|
||||||
const controller = await this.owner.lookup("controller:create-account");
|
const controller = this.getController("create-account");
|
||||||
controller.set("accountUsername", username);
|
controller.set("accountUsername", username);
|
||||||
|
|
||||||
let validation = controller.basicUsernameValidation(username);
|
let validation = controller.basicUsernameValidation(username);
|
||||||
@@ -15,7 +15,7 @@ discourseModule("Unit | Controller | create-account", function () {
|
|||||||
expectedReason,
|
expectedReason,
|
||||||
"username validation reason: " + username + ", " + expectedReason
|
"username validation reason: " + username + ", " + expectedReason
|
||||||
);
|
);
|
||||||
}.bind(this);
|
};
|
||||||
|
|
||||||
testInvalidUsername("", undefined);
|
testInvalidUsername("", undefined);
|
||||||
testInvalidUsername("x", I18n.t("user.username.too_short"));
|
testInvalidUsername("x", I18n.t("user.username.too_short"));
|
||||||
@@ -40,7 +40,7 @@ discourseModule("Unit | Controller | create-account", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("passwordValidation", async function (assert) {
|
test("passwordValidation", async function (assert) {
|
||||||
const controller = await this.owner.lookup("controller:create-account");
|
const controller = this.getController("create-account");
|
||||||
|
|
||||||
controller.set("authProvider", "");
|
controller.set("authProvider", "");
|
||||||
controller.set("accountEmail", "pork@chops.com");
|
controller.set("accountEmail", "pork@chops.com");
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { test } from "qunit";
|
|||||||
|
|
||||||
discourseModule("Unit | Controller | history", function () {
|
discourseModule("Unit | Controller | history", function () {
|
||||||
test("displayEdit", async function (assert) {
|
test("displayEdit", async function (assert) {
|
||||||
const HistoryController = this.owner.lookup("controller:history");
|
const HistoryController = this.getController("history");
|
||||||
|
|
||||||
HistoryController.setProperties({
|
HistoryController.setProperties({
|
||||||
model: { last_revision: 3, current_revision: 3, can_edit: false },
|
model: { last_revision: 3, current_revision: 3, can_edit: false },
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
import EmberObject from "@ember/object";
|
|
||||||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
|
||||||
discourseModule("Unit | Controller | preferences/account", function () {
|
discourseModule("Unit | Controller | preferences/account", function () {
|
||||||
test("updating of associated accounts", function (assert) {
|
test("updating of associated accounts", function (assert) {
|
||||||
const controller = this.owner.lookup("controller:preferences/account");
|
const controller = this.getController("preferences/account", {
|
||||||
controller.setProperties({
|
|
||||||
siteSettings: {
|
siteSettings: {
|
||||||
enable_google_oauth2_logins: true,
|
enable_google_oauth2_logins: true,
|
||||||
},
|
},
|
||||||
model: EmberObject.create({
|
model: {
|
||||||
id: 70,
|
id: 70,
|
||||||
second_factor_enabled: true,
|
second_factor_enabled: true,
|
||||||
is_anonymous: true,
|
is_anonymous: true,
|
||||||
}),
|
},
|
||||||
currentUser: EmberObject.create({
|
currentUser: {
|
||||||
id: 1234,
|
id: 1234,
|
||||||
}),
|
},
|
||||||
site: EmberObject.create({
|
site: {
|
||||||
isMobileDevice: false,
|
isMobileDevice: false,
|
||||||
}),
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(controller.get("canUpdateAssociatedAccounts"), false);
|
assert.equal(controller.get("canUpdateAssociatedAccounts"), false);
|
||||||
|
|||||||
@@ -3,15 +3,11 @@ import { test } from "qunit";
|
|||||||
|
|
||||||
discourseModule("Unit | Controller | preferences/second-factor", function () {
|
discourseModule("Unit | Controller | preferences/second-factor", function () {
|
||||||
test("displayOAuthWarning when OAuth login methods are enabled", function (assert) {
|
test("displayOAuthWarning when OAuth login methods are enabled", function (assert) {
|
||||||
const controller = this.owner.lookup(
|
const controller = this.getController("preferences/second-factor", {
|
||||||
"controller:preferences/second-factor"
|
|
||||||
);
|
|
||||||
controller.setProperties({
|
|
||||||
siteSettings: {
|
siteSettings: {
|
||||||
enable_google_oauth2_logins: true,
|
enable_google_oauth2_logins: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(controller.get("displayOAuthWarning"), true);
|
assert.equal(controller.get("displayOAuthWarning"), true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import EmberObject from "@ember/object";
|
|
||||||
import createStore from "discourse/tests/helpers/create-store";
|
import createStore from "discourse/tests/helpers/create-store";
|
||||||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
@@ -12,11 +11,10 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
|||||||
categories.push(store.createRecord("category", { id: i, position: 0 }));
|
categories.push(store.createRecord("category", { id: i, position: 0 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const site = EmberObject.create({ categories: categories });
|
const reorderCategoriesController = this.getController(
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
"reorder-categories",
|
||||||
"controller:reorder-categories"
|
{ site: { categories } }
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
reorderCategoriesController.reorder();
|
reorderCategoriesController.reorder();
|
||||||
|
|
||||||
reorderCategoriesController
|
reorderCategoriesController
|
||||||
@@ -52,14 +50,11 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
|||||||
slug: "other",
|
slug: "other",
|
||||||
});
|
});
|
||||||
|
|
||||||
const categories = [child2, parent, other, child1];
|
|
||||||
const expectedOrderSlugs = ["parent", "child2", "child1", "other"];
|
const expectedOrderSlugs = ["parent", "child2", "child1", "other"];
|
||||||
|
const reorderCategoriesController = this.getController(
|
||||||
const site = EmberObject.create({ categories: categories });
|
"reorder-categories",
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
{ site: { categories: [child2, parent, other, child1] } }
|
||||||
"controller:reorder-categories"
|
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
reorderCategoriesController.reorder();
|
reorderCategoriesController.reorder();
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
@@ -89,12 +84,10 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
|||||||
slug: "test",
|
slug: "test",
|
||||||
});
|
});
|
||||||
|
|
||||||
const categories = [elem1, elem2, elem3];
|
const reorderCategoriesController = this.getController(
|
||||||
const site = EmberObject.create({ categories: categories });
|
"reorder-categories",
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
{ site: { categories: [elem1, elem2, elem3] } }
|
||||||
"controller:reorder-categories"
|
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
|
|
||||||
reorderCategoriesController.actions.change.call(
|
reorderCategoriesController.actions.change.call(
|
||||||
reorderCategoriesController,
|
reorderCategoriesController,
|
||||||
@@ -136,12 +129,10 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
|||||||
slug: "test",
|
slug: "test",
|
||||||
});
|
});
|
||||||
|
|
||||||
const categories = [elem1, child1, elem2, elem3];
|
const reorderCategoriesController = this.getController(
|
||||||
const site = EmberObject.create({ categories: categories });
|
"reorder-categories",
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
{ site: { categories: [elem1, child1, elem2, elem3] } }
|
||||||
"controller:reorder-categories"
|
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
|
|
||||||
reorderCategoriesController.actions.change.call(
|
reorderCategoriesController.actions.change.call(
|
||||||
reorderCategoriesController,
|
reorderCategoriesController,
|
||||||
@@ -190,12 +181,10 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
|||||||
slug: "test",
|
slug: "test",
|
||||||
});
|
});
|
||||||
|
|
||||||
const categories = [elem1, child1, child2, elem2, elem3];
|
const reorderCategoriesController = this.getController(
|
||||||
const site = EmberObject.create({ categories: categories });
|
"reorder-categories",
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
{ site: { categories: [elem1, child1, child2, elem2, elem3] } }
|
||||||
"controller:reorder-categories"
|
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
reorderCategoriesController.reorder();
|
reorderCategoriesController.reorder();
|
||||||
|
|
||||||
reorderCategoriesController.actions.moveDown.call(
|
reorderCategoriesController.actions.moveDown.call(
|
||||||
|
|||||||
@@ -3,34 +3,37 @@ import { Placeholder } from "discourse/lib/posts-with-placeholders";
|
|||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import Topic from "discourse/models/topic";
|
import Topic from "discourse/models/topic";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import { moduleFor } from "ember-qunit";
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { next } from "@ember/runloop";
|
import { next } from "@ember/runloop";
|
||||||
import pretender from "discourse/tests/helpers/create-pretender";
|
import pretender from "discourse/tests/helpers/create-pretender";
|
||||||
|
import { settled } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
|
||||||
moduleFor("controller:topic", "controller:topic", {
|
|
||||||
needs: [
|
|
||||||
"controller:composer",
|
|
||||||
"controller:application",
|
|
||||||
"service:app-events",
|
|
||||||
"service:document-title",
|
|
||||||
],
|
|
||||||
beforeEach() {
|
|
||||||
this.registry.register("service:screen-track", {}, { instantiate: false });
|
|
||||||
this.registry.injection("controller", "appEvents", "service:app-events");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
function topicWithStream(streamDetails) {
|
function topicWithStream(streamDetails) {
|
||||||
let topic = Topic.create();
|
let topic = Topic.create();
|
||||||
topic.get("postStream").setProperties(streamDetails);
|
topic.get("postStream").setProperties(streamDetails);
|
||||||
return topic;
|
return topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
discourseModule("Unit | Controller | topic", function (hooks) {
|
||||||
|
hooks.beforeEach(function () {
|
||||||
|
this.registry.register("service:screen-track", {}, { instantiate: false });
|
||||||
|
this.registry.injection("controller", "appEvents", "service:app-events");
|
||||||
|
});
|
||||||
|
hooks.afterEach(function () {
|
||||||
|
this.registry.unregister("service:screen-track");
|
||||||
|
this.registry.unregister("current-user:main");
|
||||||
|
let topic = this.container.lookup("controller:topic");
|
||||||
|
topic.setProperties({
|
||||||
|
selectedPostIds: [],
|
||||||
|
selectedPostUsername: null,
|
||||||
|
currentUser: null,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("editTopic", function (assert) {
|
test("editTopic", function (assert) {
|
||||||
const model = Topic.create();
|
const model = Topic.create();
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", { model });
|
||||||
|
|
||||||
assert.not(controller.get("editingTopic"), "we are not editing by default");
|
assert.not(controller.get("editingTopic"), "we are not editing by default");
|
||||||
|
|
||||||
controller.set("model.details.can_edit", false);
|
controller.set("model.details.can_edit", false);
|
||||||
@@ -70,7 +73,7 @@ test("deleteTopic", function (assert) {
|
|||||||
destroyed = true;
|
destroyed = true;
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
const controller = this.subject({
|
const controller = this.getController("topic", {
|
||||||
model,
|
model,
|
||||||
siteSettings: {
|
siteSettings: {
|
||||||
min_topic_views_for_delete_confirm: 5,
|
min_topic_views_for_delete_confirm: 5,
|
||||||
@@ -90,9 +93,9 @@ test("deleteTopic", function (assert) {
|
|||||||
assert.ok(destroyed, "destroy not popular topic");
|
assert.ok(destroyed, "destroy not popular topic");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("toggleMultiSelect", function (assert) {
|
test("toggleMultiSelect", async function (assert) {
|
||||||
const model = Topic.create();
|
const model = Topic.create();
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", { model });
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
controller.get("multiSelect"),
|
controller.get("multiSelect"),
|
||||||
@@ -103,6 +106,7 @@ test("toggleMultiSelect", function (assert) {
|
|||||||
assert.equal(controller.get("selectedPostIds.length"), 1);
|
assert.equal(controller.get("selectedPostIds.length"), 1);
|
||||||
|
|
||||||
controller.send("toggleMultiSelect");
|
controller.send("toggleMultiSelect");
|
||||||
|
await settled();
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
controller.get("multiSelect"),
|
controller.get("multiSelect"),
|
||||||
@@ -118,6 +122,7 @@ test("toggleMultiSelect", function (assert) {
|
|||||||
assert.equal(controller.get("selectedPostIds.length"), 1);
|
assert.equal(controller.get("selectedPostIds.length"), 1);
|
||||||
|
|
||||||
controller.send("toggleMultiSelect");
|
controller.send("toggleMultiSelect");
|
||||||
|
await settled();
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
controller.get("multiSelect"),
|
controller.get("multiSelect"),
|
||||||
@@ -132,7 +137,7 @@ test("toggleMultiSelect", function (assert) {
|
|||||||
|
|
||||||
test("selectedPosts", function (assert) {
|
test("selectedPosts", function (assert) {
|
||||||
let model = topicWithStream({ posts: [{ id: 1 }, { id: 2 }, { id: 3 }] });
|
let model = topicWithStream({ posts: [{ id: 1 }, { id: 2 }, { id: 3 }] });
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", { model });
|
||||||
|
|
||||||
controller.set("selectedPostIds", [1, 2, 42]);
|
controller.set("selectedPostIds", [1, 2, 42]);
|
||||||
|
|
||||||
@@ -149,11 +154,14 @@ test("selectedPosts", function (assert) {
|
|||||||
|
|
||||||
test("selectedAllPosts", function (assert) {
|
test("selectedAllPosts", function (assert) {
|
||||||
let model = topicWithStream({ stream: [1, 2, 3] });
|
let model = topicWithStream({ stream: [1, 2, 3] });
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", { model });
|
||||||
|
|
||||||
controller.set("selectedPostIds", [1, 2]);
|
controller.set("selectedPostIds", [1, 2]);
|
||||||
|
|
||||||
assert.not(controller.get("selectedAllPosts"), "not all posts are selected");
|
assert.not(
|
||||||
|
controller.get("selectedAllPosts"),
|
||||||
|
"not all posts are selected"
|
||||||
|
);
|
||||||
|
|
||||||
controller.get("selectedPostIds").pushObject(3);
|
controller.get("selectedPostIds").pushObject(3);
|
||||||
|
|
||||||
@@ -186,7 +194,7 @@ test("selectedPostsUsername", function (assert) {
|
|||||||
],
|
],
|
||||||
stream: [1, 2, 3],
|
stream: [1, 2, 3],
|
||||||
});
|
});
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", { model });
|
||||||
const selectedPostIds = controller.get("selectedPostIds");
|
const selectedPostIds = controller.get("selectedPostIds");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -231,7 +239,7 @@ test("selectedPostsUsername", function (assert) {
|
|||||||
test("showSelectedPostsAtBottom", function (assert) {
|
test("showSelectedPostsAtBottom", function (assert) {
|
||||||
const site = EmberObject.create({ mobileView: false });
|
const site = EmberObject.create({ mobileView: false });
|
||||||
const model = Topic.create({ posts_count: 3 });
|
const model = Topic.create({ posts_count: 3 });
|
||||||
const controller = this.subject({ model, site });
|
const controller = this.getController("topic", { model, site });
|
||||||
|
|
||||||
assert.not(controller.get("showSelectedPostsAtBottom"), "false on desktop");
|
assert.not(controller.get("showSelectedPostsAtBottom"), "false on desktop");
|
||||||
|
|
||||||
@@ -264,7 +272,10 @@ test("canDeleteSelected", function (assert) {
|
|||||||
],
|
],
|
||||||
stream: [1, 2, 3],
|
stream: [1, 2, 3],
|
||||||
});
|
});
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", {
|
||||||
|
model,
|
||||||
|
currentUser,
|
||||||
|
});
|
||||||
const selectedPostIds = controller.get("selectedPostIds");
|
const selectedPostIds = controller.get("selectedPostIds");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
@@ -311,7 +322,7 @@ test("Can split/merge topic", function (assert) {
|
|||||||
stream: [1, 2, 3],
|
stream: [1, 2, 3],
|
||||||
});
|
});
|
||||||
model.set("details.can_move_posts", false);
|
model.set("details.can_move_posts", false);
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", { model });
|
||||||
const selectedPostIds = controller.get("selectedPostIds");
|
const selectedPostIds = controller.get("selectedPostIds");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
@@ -361,7 +372,10 @@ test("canChangeOwner", function (assert) {
|
|||||||
stream: [1, 2],
|
stream: [1, 2],
|
||||||
});
|
});
|
||||||
model.set("currentUser", { admin: false });
|
model.set("currentUser", { admin: false });
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", {
|
||||||
|
model,
|
||||||
|
currentUser,
|
||||||
|
});
|
||||||
const selectedPostIds = controller.get("selectedPostIds");
|
const selectedPostIds = controller.get("selectedPostIds");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
@@ -398,7 +412,9 @@ test("canMergePosts", function (assert) {
|
|||||||
],
|
],
|
||||||
stream: [1, 2, 3],
|
stream: [1, 2, 3],
|
||||||
});
|
});
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", {
|
||||||
|
model,
|
||||||
|
});
|
||||||
const selectedPostIds = controller.get("selectedPostIds");
|
const selectedPostIds = controller.get("selectedPostIds");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
@@ -437,7 +453,7 @@ test("canMergePosts", function (assert) {
|
|||||||
|
|
||||||
test("Select/deselect all", function (assert) {
|
test("Select/deselect all", function (assert) {
|
||||||
let model = topicWithStream({ stream: [1, 2, 3] });
|
let model = topicWithStream({ stream: [1, 2, 3] });
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", { model });
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
controller.get("selectedPostsCount"),
|
controller.get("selectedPostsCount"),
|
||||||
@@ -463,7 +479,7 @@ test("Select/deselect all", function (assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("togglePostSelection", function (assert) {
|
test("togglePostSelection", function (assert) {
|
||||||
const controller = this.subject();
|
const controller = this.getController("topic");
|
||||||
const selectedPostIds = controller.get("selectedPostIds");
|
const selectedPostIds = controller.get("selectedPostIds");
|
||||||
|
|
||||||
assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
||||||
@@ -485,19 +501,6 @@ test("togglePostSelection", function (assert) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// test("selectReplies", function(assert) {
|
|
||||||
// const controller = this.subject();
|
|
||||||
// const selectedPostIds = controller.get("selectedPostIds");
|
|
||||||
//
|
|
||||||
// assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
|
||||||
//
|
|
||||||
// controller.send("selectReplies", { id: 42 });
|
|
||||||
//
|
|
||||||
// assert.equal(selectedPostIds[0], 42, "selected post #42");
|
|
||||||
// assert.equal(selectedPostIds[1], 45, "selected post #45");
|
|
||||||
// assert.equal(selectedPostIds[2], 100, "selected post #100");
|
|
||||||
// });
|
|
||||||
|
|
||||||
test("selectBelow", function (assert) {
|
test("selectBelow", function (assert) {
|
||||||
const site = EmberObject.create({
|
const site = EmberObject.create({
|
||||||
post_types: { small_action: 3, whisper: 4 },
|
post_types: { small_action: 3, whisper: 4 },
|
||||||
@@ -510,7 +513,7 @@ test("selectBelow", function (assert) {
|
|||||||
{ id: 7, cooked: "", post_type: 4 },
|
{ id: 7, cooked: "", post_type: 4 },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
const controller = this.subject({ site, model });
|
const controller = this.getController("topic", { site, model });
|
||||||
let selectedPostIds = controller.get("selectedPostIds");
|
let selectedPostIds = controller.get("selectedPostIds");
|
||||||
|
|
||||||
assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
||||||
@@ -527,7 +530,7 @@ test("topVisibleChanged", function (assert) {
|
|||||||
let model = topicWithStream({
|
let model = topicWithStream({
|
||||||
posts: [{ id: 1 }],
|
posts: [{ id: 1 }],
|
||||||
});
|
});
|
||||||
const controller = this.subject({ model });
|
const controller = this.getController("topic", { model });
|
||||||
const placeholder = new Placeholder("post-placeholder");
|
const placeholder = new Placeholder("post-placeholder");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -561,7 +564,7 @@ test("deletePost - no modal is shown if post does not have replies", function (a
|
|||||||
stream: [2, 3, 4],
|
stream: [2, 3, 4],
|
||||||
posts: [post, { id: 3 }, { id: 4 }],
|
posts: [post, { id: 3 }, { id: 4 }],
|
||||||
});
|
});
|
||||||
const controller = this.subject({ model, currentUser });
|
const controller = this.getController("topic", { model, currentUser });
|
||||||
|
|
||||||
const done = assert.async();
|
const done = assert.async();
|
||||||
controller.send("deletePost", post);
|
controller.send("deletePost", post);
|
||||||
@@ -571,3 +574,4 @@ test("deletePost - no modal is shown if post does not have replies", function (a
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import { module, test } from "qunit";
|
|
||||||
/* global BreakString:true */
|
|
||||||
|
|
||||||
module("Unit | Utility | breakString", function () {
|
|
||||||
test("breakString", function (assert) {
|
|
||||||
const b = (s, hint) => new BreakString(s).break(hint);
|
|
||||||
|
|
||||||
assert.equal(b("hello"), "hello");
|
|
||||||
assert.equal(b("helloworld"), "helloworld");
|
|
||||||
assert.equal(b("HeMans11"), "He<wbr>​Mans<wbr>​11");
|
|
||||||
assert.equal(b("he_man"), "he_<wbr>​man");
|
|
||||||
assert.equal(b("he11111"), "he<wbr>​11111");
|
|
||||||
assert.equal(b("HRCBob"), "HRC<wbr>​Bob");
|
|
||||||
assert.equal(
|
|
||||||
b("bobmarleytoo", "Bob Marley Too"),
|
|
||||||
"bob<wbr>​marley<wbr>​too"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -2,13 +2,21 @@ import {
|
|||||||
currentUser,
|
currentUser,
|
||||||
discourseModule,
|
discourseModule,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import DocumentTitle from "discourse/services/document-title";
|
||||||
|
import AppEvents from "discourse/services/app-events";
|
||||||
|
import Session from "discourse/models/session";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
|
||||||
discourseModule("Unit | Service | document-title", function (hooks) {
|
discourseModule("Unit | Service | document-title", function (hooks) {
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
this.documentTitle = this.container.lookup("service:document-title");
|
const session = Session.current();
|
||||||
|
session.hasFocus = true;
|
||||||
|
|
||||||
|
this.documentTitle = DocumentTitle.create({
|
||||||
|
session,
|
||||||
|
appEvents: AppEvents.create(),
|
||||||
|
});
|
||||||
this.documentTitle.currentUser = null;
|
this.documentTitle.currentUser = null;
|
||||||
this.container.lookup("session:main").hasFocus = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
hooks.afterEach(function () {
|
hooks.afterEach(function () {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
import { afterRender } from "discourse-common/utils/decorators";
|
import { afterRender } from "discourse-common/utils/decorators";
|
||||||
import componentTest from "discourse/tests/helpers/component-test";
|
import componentTest, {
|
||||||
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
setupRenderingTest,
|
||||||
import { moduleForComponent } from "ember-qunit";
|
} from "discourse/tests/helpers/component-test";
|
||||||
|
import { discourseModule, exists } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import hbs from "htmlbars-inline-precompile";
|
||||||
|
|
||||||
const fooComponent = Component.extend({
|
const fooComponent = Component.extend({
|
||||||
layoutName: "foo-component",
|
|
||||||
|
|
||||||
classNames: ["foo-component"],
|
classNames: ["foo-component"],
|
||||||
|
|
||||||
baz: null,
|
baz: null,
|
||||||
@@ -29,23 +29,25 @@ const fooComponent = Component.extend({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
moduleForComponent("utils:decorators", { integration: true });
|
discourseModule("utils:decorators", function (hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
componentTest("afterRender", {
|
componentTest("afterRender", {
|
||||||
template: "{{foo-component baz=baz}}",
|
template: hbs`{{foo-component baz=baz}}`,
|
||||||
|
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
this.registry.register("component:foo-component", fooComponent);
|
this.registry.register("component:foo-component", fooComponent);
|
||||||
this.set("baz", 0);
|
this.set("baz", 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
test(assert) {
|
async test(assert) {
|
||||||
assert.ok(exists(document.querySelector(".foo-component")));
|
assert.ok(exists(document.querySelector(".foo-component")));
|
||||||
assert.equal(this.baz, 1);
|
assert.equal(this.baz, 1);
|
||||||
|
|
||||||
this.clearRender();
|
await this.clearRender();
|
||||||
|
|
||||||
assert.ok(!exists(document.querySelector(".foo-component")));
|
assert.ok(!exists(document.querySelector(".foo-component")));
|
||||||
assert.equal(this.baz, 1);
|
assert.equal(this.baz, 1);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|||||||
10168
app/assets/javascripts/discourse/yarn.lock
Normal file
10168
app/assets/javascripts/discourse/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
13
app/assets/javascripts/package.json
Normal file
13
app/assets/javascripts/package.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"workspaces": [
|
||||||
|
"discourse",
|
||||||
|
"admin",
|
||||||
|
"discourse-common",
|
||||||
|
"discourse-hbr",
|
||||||
|
"discourse-widget-hbs",
|
||||||
|
"pretty-text",
|
||||||
|
"select-kit"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -15,9 +15,10 @@
|
|||||||
"start": "ember serve"
|
"start": "ember serve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"ember-auto-import": "^1.5.3",
|
||||||
"ember-cli-babel": "^7.13.0",
|
"ember-cli-babel": "^7.13.0",
|
||||||
"ember-cli-htmlbars": "^4.2.0",
|
"ember-cli-htmlbars": "^4.2.0",
|
||||||
"ember-auto-import": "^1.5.3"
|
"xss": "^1.0.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ember/optional-features": "^1.1.0",
|
"@ember/optional-features": "^1.1.0",
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ define("@ember/test-helpers", () => {
|
|||||||
return window[attr](...arguments);
|
return window[attr](...arguments);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
helpers.triggerKeyEvent = window.keyEvent;
|
helpers.triggerKeyEvent = function () {
|
||||||
|
return window.keyEvent(...arguments);
|
||||||
|
};
|
||||||
return helpers;
|
return helpers;
|
||||||
});
|
});
|
||||||
define("pretender", () => {
|
define("pretender", () => {
|
||||||
|
|||||||
11580
app/assets/javascripts/yarn.lock
Normal file
11580
app/assets/javascripts/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -279,9 +279,13 @@ class Compiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function compile(template) {
|
const loader = typeof Ember !== "undefined" ? Ember.__loader.require : require;
|
||||||
const preprocessor = Ember.__loader.require("@glimmer/syntax");
|
|
||||||
const compiled = preprocessor.preprocess(template);
|
function compile(template, glimmer) {
|
||||||
|
if (!glimmer) {
|
||||||
|
glimmer = loader("@glimmer/syntax");
|
||||||
|
}
|
||||||
|
const compiled = glimmer.preprocess(template);
|
||||||
const compiler = new Compiler(compiled);
|
const compiler = new Compiler(compiled);
|
||||||
|
|
||||||
let code = compiler.compile();
|
let code = compiler.compile();
|
||||||
@@ -305,7 +309,7 @@ function error(path, state, msg) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.WidgetHbsCompiler = function (babel) {
|
const WidgetHbsCompiler = function (babel) {
|
||||||
let t = babel.types;
|
let t = babel.types;
|
||||||
return {
|
return {
|
||||||
visitor: {
|
visitor: {
|
||||||
@@ -353,11 +357,16 @@ exports.WidgetHbsCompiler = function (babel) {
|
|||||||
.join("");
|
.join("");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
path.replaceWithSourceString(compile(template));
|
path.replaceWithSourceString(
|
||||||
|
compile(template, WidgetHbsCompiler.glimmer)
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error("widget hbs error", e.toString());
|
||||||
return error(path, state, e.toString());
|
return error(path, state, e.toString());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.WidgetHbsCompiler = WidgetHbsCompiler;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ acceptance("Poll breakdown", function (needs) {
|
|||||||
"shows the breakdown button when poll_groupable_user_fields is non-empty"
|
"shows the breakdown button when poll_groupable_user_fields is non-empty"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".poll-show-breakdown:first");
|
await click(".poll-show-breakdown");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-breakdown-total-votes")[0].textContent.trim(),
|
queryAll(".poll-breakdown-total-votes")[0].textContent.trim(),
|
||||||
@@ -88,10 +88,10 @@ acceptance("Poll breakdown", function (needs) {
|
|||||||
|
|
||||||
test("Changing the display mode from percentage to count", async function (assert) {
|
test("Changing the display mode from percentage to count", async function (assert) {
|
||||||
await visit("/t/-/topic_with_pie_chart_poll");
|
await visit("/t/-/topic_with_pie_chart_poll");
|
||||||
await click(".poll-show-breakdown:first");
|
await click(".poll-show-breakdown");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-breakdown-option-count:first")[0].textContent.trim(),
|
queryAll(".poll-breakdown-option-count")[0].textContent.trim(),
|
||||||
"40.0%",
|
"40.0%",
|
||||||
"displays the correct vote percentage"
|
"displays the correct vote percentage"
|
||||||
);
|
);
|
||||||
@@ -99,7 +99,7 @@ acceptance("Poll breakdown", function (needs) {
|
|||||||
await click(".modal-tabs .count");
|
await click(".modal-tabs .count");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-breakdown-option-count:first")[0].textContent.trim(),
|
queryAll(".poll-breakdown-option-count")[0].textContent.trim(),
|
||||||
"2",
|
"2",
|
||||||
"displays the correct vote count"
|
"displays the correct vote count"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -68,15 +68,15 @@ acceptance("Rendering polls with bar charts - desktop", function (needs) {
|
|||||||
await click("button.toggle-results");
|
await click("button.toggle-results");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
25,
|
25,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".poll-voters-toggle-expand:first a");
|
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
26,
|
26,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
@@ -91,20 +91,20 @@ acceptance("Rendering polls with bar charts - desktop", function (needs) {
|
|||||||
await click("button.toggle-results");
|
await click("button.toggle-results");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
25,
|
25,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.notOk(
|
assert.notOk(
|
||||||
queryAll(".poll-voters:first li:first a").attr("href"),
|
queryAll(".poll-voters:nth-of-type(1) li:nth-of-type(1) a").attr("href"),
|
||||||
"user URL does not exist"
|
"user URL does not exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".poll-voters-toggle-expand:first a");
|
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
30,
|
30,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -30,20 +30,20 @@ acceptance("Rendering polls with bar charts - mobile", function (needs) {
|
|||||||
await click("button.toggle-results");
|
await click("button.toggle-results");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
25,
|
25,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.notOk(
|
assert.notOk(
|
||||||
queryAll(".poll-voters:first li:first a").attr("href"),
|
queryAll(".poll-voters:nth-of-type(1) li:nth-of-type(1) a").attr("href"),
|
||||||
"user URL does not exist"
|
"user URL does not exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".poll-voters-toggle-expand:first a");
|
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
35,
|
35,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|||||||
401
vendor/assets/javascripts/bootbox.js
vendored
401
vendor/assets/javascripts/bootbox.js
vendored
@@ -3,21 +3,22 @@
|
|||||||
*
|
*
|
||||||
* http://bootboxjs.com/license.txt
|
* http://bootboxjs.com/license.txt
|
||||||
*/
|
*/
|
||||||
var bootbox = window.bootbox || (function(document, $) {
|
var bootbox =
|
||||||
|
window.bootbox ||
|
||||||
|
(function (document, $) {
|
||||||
/*jshint scripturl:true sub:true */
|
/*jshint scripturl:true sub:true */
|
||||||
|
|
||||||
var _locale = 'en',
|
var _locale = "en",
|
||||||
_defaultLocale = 'en',
|
_defaultLocale = "en",
|
||||||
_animate = true,
|
_animate = true,
|
||||||
_backdrop = 'static',
|
_backdrop = "static",
|
||||||
_defaultHref = 'javascript:;',
|
_defaultHref = "javascript:;",
|
||||||
_classes = '',
|
_classes = "",
|
||||||
_btnClasses = {},
|
_btnClasses = {},
|
||||||
_icons = {},
|
_icons = {},
|
||||||
/* last var should always be the public object we'll return */
|
/* last var should always be the public object we'll return */
|
||||||
that = {};
|
that = {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* public API
|
* public API
|
||||||
*/
|
*/
|
||||||
@@ -28,11 +29,11 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error('Invalid locale: '+locale);
|
throw new Error("Invalid locale: " + locale);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.addLocale = function (locale, translations) {
|
that.addLocale = function (locale, translations) {
|
||||||
if (typeof _locales[locale] === 'undefined') {
|
if (typeof _locales[locale] === "undefined") {
|
||||||
_locales[locale] = {};
|
_locales[locale] = {};
|
||||||
}
|
}
|
||||||
for (var str in translations) {
|
for (var str in translations) {
|
||||||
@@ -42,21 +43,21 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
|
|
||||||
that.setIcons = function (icons) {
|
that.setIcons = function (icons) {
|
||||||
_icons = icons;
|
_icons = icons;
|
||||||
if (typeof _icons !== 'object' || _icons === null) {
|
if (typeof _icons !== "object" || _icons === null) {
|
||||||
_icons = {};
|
_icons = {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
that.setBtnClasses = function (btnClasses) {
|
that.setBtnClasses = function (btnClasses) {
|
||||||
_btnClasses = btnClasses;
|
_btnClasses = btnClasses;
|
||||||
if (typeof _btnClasses !== 'object' || _btnClasses === null) {
|
if (typeof _btnClasses !== "object" || _btnClasses === null) {
|
||||||
_btnClasses = {};
|
_btnClasses = {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
that.alert = function (/*str, label, cb*/) {
|
that.alert = function (/*str, label, cb*/) {
|
||||||
var str = "",
|
var str = "",
|
||||||
label = _translate('OK'),
|
label = _translate("OK"),
|
||||||
cb = null;
|
cb = null;
|
||||||
|
|
||||||
switch (arguments.length) {
|
switch (arguments.length) {
|
||||||
@@ -67,7 +68,7 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
case 2:
|
case 2:
|
||||||
// callback *or* custom button label dependent on type
|
// callback *or* custom button label dependent on type
|
||||||
str = arguments[0];
|
str = arguments[0];
|
||||||
if (typeof arguments[1] == 'function') {
|
if (typeof arguments[1] == "function") {
|
||||||
cb = arguments[1];
|
cb = arguments[1];
|
||||||
} else {
|
} else {
|
||||||
label = arguments[1];
|
label = arguments[1];
|
||||||
@@ -83,23 +84,27 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
throw new Error("Incorrect number of arguments: expected 1-3");
|
throw new Error("Incorrect number of arguments: expected 1-3");
|
||||||
}
|
}
|
||||||
|
|
||||||
return that.dialog(str, {
|
return that.dialog(
|
||||||
|
str,
|
||||||
|
{
|
||||||
// only button (ok)
|
// only button (ok)
|
||||||
"label" : label,
|
label: label,
|
||||||
"icon" : _icons.OK,
|
icon: _icons.OK,
|
||||||
"class" : _btnClasses.OK,
|
class: _btnClasses.OK,
|
||||||
"callback": cb
|
callback: cb,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
// ensure that the escape key works; either invoking the user's
|
// ensure that the escape key works; either invoking the user's
|
||||||
// callback or true to just close the dialog
|
// callback or true to just close the dialog
|
||||||
"onEscape": cb || true
|
onEscape: cb || true,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.confirm = function (/*str, labelCancel, labelOk, cb*/) {
|
that.confirm = function (/*str, labelCancel, labelOk, cb*/) {
|
||||||
var str = "",
|
var str = "",
|
||||||
labelCancel = _translate('CANCEL'),
|
labelCancel = _translate("CANCEL"),
|
||||||
labelOk = _translate('CONFIRM'),
|
labelOk = _translate("CONFIRM"),
|
||||||
cb = null;
|
cb = null;
|
||||||
|
|
||||||
switch (arguments.length) {
|
switch (arguments.length) {
|
||||||
@@ -108,7 +113,7 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
str = arguments[0];
|
str = arguments[0];
|
||||||
if (typeof arguments[1] == 'function') {
|
if (typeof arguments[1] == "function") {
|
||||||
cb = arguments[1];
|
cb = arguments[1];
|
||||||
} else {
|
} else {
|
||||||
labelCancel = arguments[1];
|
labelCancel = arguments[1];
|
||||||
@@ -117,7 +122,7 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
case 3:
|
case 3:
|
||||||
str = arguments[0];
|
str = arguments[0];
|
||||||
labelCancel = arguments[1];
|
labelCancel = arguments[1];
|
||||||
if (typeof arguments[2] == 'function') {
|
if (typeof arguments[2] == "function") {
|
||||||
cb = arguments[2];
|
cb = arguments[2];
|
||||||
} else {
|
} else {
|
||||||
labelOk = arguments[2];
|
labelOk = arguments[2];
|
||||||
@@ -134,39 +139,46 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cancelCallback = function () {
|
var cancelCallback = function () {
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === "function") {
|
||||||
return cb(false);
|
return cb(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var confirmCallback = function () {
|
var confirmCallback = function () {
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === "function") {
|
||||||
return cb(true);
|
return cb(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return that.dialog(str, [{
|
return that.dialog(
|
||||||
|
str,
|
||||||
|
[
|
||||||
|
{
|
||||||
// first button (cancel)
|
// first button (cancel)
|
||||||
"label" : labelCancel,
|
label: labelCancel,
|
||||||
"icon" : _icons.CANCEL,
|
icon: _icons.CANCEL,
|
||||||
"class" : _btnClasses.CANCEL,
|
class: _btnClasses.CANCEL,
|
||||||
"callback": cancelCallback
|
callback: cancelCallback,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
// second button (confirm)
|
// second button (confirm)
|
||||||
"label" : labelOk,
|
label: labelOk,
|
||||||
"icon" : _icons.CONFIRM,
|
icon: _icons.CONFIRM,
|
||||||
"class" : _btnClasses.CONFIRM,
|
class: _btnClasses.CONFIRM,
|
||||||
"callback": confirmCallback
|
callback: confirmCallback,
|
||||||
}], {
|
},
|
||||||
|
],
|
||||||
|
{
|
||||||
// escape key bindings
|
// escape key bindings
|
||||||
"onEscape": cancelCallback
|
onEscape: cancelCallback,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.prompt = function (/*str, labelCancel, labelOk, cb, defaultVal*/) {
|
that.prompt = function (/*str, labelCancel, labelOk, cb, defaultVal*/) {
|
||||||
var str = "",
|
var str = "",
|
||||||
labelCancel = _translate('CANCEL'),
|
labelCancel = _translate("CANCEL"),
|
||||||
labelOk = _translate('CONFIRM'),
|
labelOk = _translate("CONFIRM"),
|
||||||
cb = null,
|
cb = null,
|
||||||
defaultVal = "";
|
defaultVal = "";
|
||||||
|
|
||||||
@@ -176,7 +188,7 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
str = arguments[0];
|
str = arguments[0];
|
||||||
if (typeof arguments[1] == 'function') {
|
if (typeof arguments[1] == "function") {
|
||||||
cb = arguments[1];
|
cb = arguments[1];
|
||||||
} else {
|
} else {
|
||||||
labelCancel = arguments[1];
|
labelCancel = arguments[1];
|
||||||
@@ -185,7 +197,7 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
case 3:
|
case 3:
|
||||||
str = arguments[0];
|
str = arguments[0];
|
||||||
labelCancel = arguments[1];
|
labelCancel = arguments[1];
|
||||||
if (typeof arguments[2] == 'function') {
|
if (typeof arguments[2] == "function") {
|
||||||
cb = arguments[2];
|
cb = arguments[2];
|
||||||
} else {
|
} else {
|
||||||
labelOk = arguments[2];
|
labelOk = arguments[2];
|
||||||
@@ -212,10 +224,14 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
|
|
||||||
// let's keep a reference to the form object for later
|
// let's keep a reference to the form object for later
|
||||||
var form = $("<form></form>");
|
var form = $("<form></form>");
|
||||||
form.append("<input class='input-block-level' autocomplete=off type=text value='" + defaultVal + "' />");
|
form.append(
|
||||||
|
"<input class='input-block-level' autocomplete=off type=text value='" +
|
||||||
|
defaultVal +
|
||||||
|
"' />"
|
||||||
|
);
|
||||||
|
|
||||||
var cancelCallback = function () {
|
var cancelCallback = function () {
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === "function") {
|
||||||
// yep, native prompts dismiss with null, whereas native
|
// yep, native prompts dismiss with null, whereas native
|
||||||
// confirms dismiss with false...
|
// confirms dismiss with false...
|
||||||
return cb(null);
|
return cb(null);
|
||||||
@@ -223,30 +239,37 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var confirmCallback = function () {
|
var confirmCallback = function () {
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === "function") {
|
||||||
return cb(form.find("input[type=text]").val());
|
return cb(form.find("input[type=text]").val());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var div = that.dialog(form, [{
|
var div = that.dialog(
|
||||||
|
form,
|
||||||
|
[
|
||||||
|
{
|
||||||
// first button (cancel)
|
// first button (cancel)
|
||||||
"label" : labelCancel,
|
label: labelCancel,
|
||||||
"icon" : _icons.CANCEL,
|
icon: _icons.CANCEL,
|
||||||
"class" : _btnClasses.CANCEL,
|
class: _btnClasses.CANCEL,
|
||||||
"callback": cancelCallback
|
callback: cancelCallback,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
// second button (confirm)
|
// second button (confirm)
|
||||||
"label" : labelOk,
|
label: labelOk,
|
||||||
"icon" : _icons.CONFIRM,
|
icon: _icons.CONFIRM,
|
||||||
"class" : _btnClasses.CONFIRM,
|
class: _btnClasses.CONFIRM,
|
||||||
"callback": confirmCallback
|
callback: confirmCallback,
|
||||||
}], {
|
},
|
||||||
|
],
|
||||||
|
{
|
||||||
// prompts need a few extra options
|
// prompts need a few extra options
|
||||||
"header" : header,
|
header: header,
|
||||||
// explicitly tell dialog NOT to show the dialog...
|
// explicitly tell dialog NOT to show the dialog...
|
||||||
"show" : false,
|
show: false,
|
||||||
"onEscape": cancelCallback
|
onEscape: cancelCallback,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// ... the reason the prompt needs to be hidden is because we need
|
// ... the reason the prompt needs to be hidden is because we need
|
||||||
// to bind our own "shown" handler, after creating the modal but
|
// to bind our own "shown" handler, after creating the modal but
|
||||||
@@ -278,9 +301,9 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check for single object and convert to array if necessary
|
// check for single object and convert to array if necessary
|
||||||
if (typeof handlers === 'undefined') {
|
if (typeof handlers === "undefined") {
|
||||||
handlers = [];
|
handlers = [];
|
||||||
} else if (typeof handlers.length == 'undefined') {
|
} else if (typeof handlers.length == "undefined") {
|
||||||
handlers = [handlers];
|
handlers = [handlers];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,13 +311,15 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
while (i--) {
|
while (i--) {
|
||||||
var label = null,
|
var label = null,
|
||||||
href = null,
|
href = null,
|
||||||
_class = 'btn-default',
|
_class = "btn-default",
|
||||||
icon = '',
|
icon = "",
|
||||||
callback = null;
|
callback = null;
|
||||||
|
|
||||||
if (typeof handlers[i]['label'] == 'undefined' &&
|
if (
|
||||||
typeof handlers[i]['class'] == 'undefined' &&
|
typeof handlers[i]["label"] == "undefined" &&
|
||||||
typeof handlers[i]['callback'] == 'undefined') {
|
typeof handlers[i]["class"] == "undefined" &&
|
||||||
|
typeof handlers[i]["callback"] == "undefined"
|
||||||
|
) {
|
||||||
// if we've got nothing we expect, check for condensed format
|
// if we've got nothing we expect, check for condensed format
|
||||||
|
|
||||||
var propCount = 0, // condensed will only match if this == 1
|
var propCount = 0, // condensed will only match if this == 1
|
||||||
@@ -309,48 +334,59 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propCount == 1 && typeof handlers[i][j] == 'function') {
|
if (propCount == 1 && typeof handlers[i][j] == "function") {
|
||||||
// matches condensed format of label -> function
|
// matches condensed format of label -> function
|
||||||
handlers[i]['label'] = property;
|
handlers[i]["label"] = property;
|
||||||
handlers[i]['callback'] = handlers[i][j];
|
handlers[i]["callback"] = handlers[i][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof handlers[i]['callback']== 'function') {
|
if (typeof handlers[i]["callback"] == "function") {
|
||||||
callback = handlers[i]['callback'];
|
callback = handlers[i]["callback"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handlers[i]['class']) {
|
if (handlers[i]["class"]) {
|
||||||
_class = handlers[i]['class'];
|
_class = handlers[i]["class"];
|
||||||
} else if (i == handlers.length - 1 && handlers.length <= 2) {
|
} else if (i == handlers.length - 1 && handlers.length <= 2) {
|
||||||
// always add a primary to the main option in a two-button dialog
|
// always add a primary to the main option in a two-button dialog
|
||||||
_class = 'btn-primary';
|
_class = "btn-primary";
|
||||||
}
|
}
|
||||||
|
|
||||||
// See: https://github.com/makeusabrew/bootbox/pull/114
|
// See: https://github.com/makeusabrew/bootbox/pull/114
|
||||||
// Upgrade to official bootbox release when it gets merged.
|
// Upgrade to official bootbox release when it gets merged.
|
||||||
if (handlers[i]['link'] !== true) {
|
if (handlers[i]["link"] !== true) {
|
||||||
_class = 'btn ' + _class;
|
_class = "btn " + _class;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handlers[i]['label']) {
|
if (handlers[i]["label"]) {
|
||||||
label = handlers[i]['label'];
|
label = handlers[i]["label"];
|
||||||
} else {
|
} else {
|
||||||
label = "Option " + (i + 1);
|
label = "Option " + (i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handlers[i]['icon']) {
|
if (handlers[i]["icon"]) {
|
||||||
icon = handlers[i]['icon'];
|
icon = handlers[i]["icon"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handlers[i]['href']) {
|
if (handlers[i]["href"]) {
|
||||||
href = handlers[i]['href'];
|
href = handlers[i]["href"];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
href = _defaultHref;
|
href = _defaultHref;
|
||||||
}
|
}
|
||||||
|
|
||||||
buttons = buttons + "<a data-handler='"+i+"' class='"+_class+"' href='" + href + "'>"+icon+"<span class='d-button-label'>"+label+"</span></a>";
|
buttons =
|
||||||
|
buttons +
|
||||||
|
"<a data-handler='" +
|
||||||
|
i +
|
||||||
|
"' class='" +
|
||||||
|
_class +
|
||||||
|
"' href='" +
|
||||||
|
href +
|
||||||
|
"'>" +
|
||||||
|
icon +
|
||||||
|
"<span class='d-button-label'>" +
|
||||||
|
label +
|
||||||
|
"</span></a>";
|
||||||
|
|
||||||
callbacks[i] = callback;
|
callbacks[i] = callback;
|
||||||
}
|
}
|
||||||
@@ -361,15 +397,27 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
// @see https://github.com/twitter/bootstrap/issues/4854
|
// @see https://github.com/twitter/bootstrap/issues/4854
|
||||||
// for an explanation of tabIndex=-1
|
// for an explanation of tabIndex=-1
|
||||||
|
|
||||||
var parts = ["<div class='bootbox modal' tabindex='-1' style='overflow:hidden;'>"];
|
var parts = [
|
||||||
|
"<div class='bootbox modal' tabindex='-1' style='overflow:hidden;'>",
|
||||||
|
];
|
||||||
|
|
||||||
if (options['header']) {
|
if (options["header"]) {
|
||||||
var closeButton = '';
|
var closeButton = "";
|
||||||
if (typeof options['headerCloseButton'] == 'undefined' || options['headerCloseButton']) {
|
if (
|
||||||
closeButton = "<a href='"+_defaultHref+"' class='close'>×</a>";
|
typeof options["headerCloseButton"] == "undefined" ||
|
||||||
|
options["headerCloseButton"]
|
||||||
|
) {
|
||||||
|
closeButton =
|
||||||
|
"<a href='" + _defaultHref + "' class='close'>×</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
parts.push("<div class='modal-header'>"+closeButton+"<h3>"+options['header']+"</h3></div>");
|
parts.push(
|
||||||
|
"<div class='modal-header'>" +
|
||||||
|
closeButton +
|
||||||
|
"<h3>" +
|
||||||
|
options["header"] +
|
||||||
|
"</h3></div>"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// push an empty body into which we'll inject the proper content later
|
// push an empty body into which we'll inject the proper content later
|
||||||
@@ -384,13 +432,15 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
var div = $(parts.join("\n"));
|
var div = $(parts.join("\n"));
|
||||||
|
|
||||||
// check whether we should fade in/out
|
// check whether we should fade in/out
|
||||||
var shouldFade = (typeof options.animate === 'undefined') ? _animate : options.animate;
|
var shouldFade =
|
||||||
|
typeof options.animate === "undefined" ? _animate : options.animate;
|
||||||
|
|
||||||
if (shouldFade) {
|
if (shouldFade) {
|
||||||
div.addClass("fade");
|
div.addClass("fade");
|
||||||
}
|
}
|
||||||
|
|
||||||
var optionalClasses = (typeof options.classes === 'undefined') ? _classes : options.classes;
|
var optionalClasses =
|
||||||
|
typeof options.classes === "undefined" ? _classes : options.classes;
|
||||||
if (optionalClasses) {
|
if (optionalClasses) {
|
||||||
div.addClass(optionalClasses);
|
div.addClass(optionalClasses);
|
||||||
}
|
}
|
||||||
@@ -401,60 +451,60 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
function onCancel(source) {
|
function onCancel(source) {
|
||||||
// for now source is unused, but it will be in future
|
// for now source is unused, but it will be in future
|
||||||
var hideModal = null;
|
var hideModal = null;
|
||||||
if (typeof options.onEscape === 'function') {
|
if (typeof options.onEscape === "function") {
|
||||||
// @see https://github.com/makeusabrew/bootbox/issues/91
|
// @see https://github.com/makeusabrew/bootbox/issues/91
|
||||||
hideModal = options.onEscape();
|
hideModal = options.onEscape();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hideModal !== false) {
|
if (hideModal !== false) {
|
||||||
div.modal('hide');
|
div.modal("hide");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook into the modal's keyup trigger to check for the escape key
|
// hook into the modal's keyup trigger to check for the escape key
|
||||||
div.on('keyup.dismiss.modal', function(e) {
|
div.on("keyup.dismiss.modal", function (e) {
|
||||||
// any truthy value passed to onEscape will dismiss the dialog
|
// any truthy value passed to onEscape will dismiss the dialog
|
||||||
// as long as the onEscape function (if defined) doesn't prevent it
|
// as long as the onEscape function (if defined) doesn't prevent it
|
||||||
if (e.which === 27 && options.onEscape !== false) {
|
if (e.which === 27 && options.onEscape !== false) {
|
||||||
onCancel('escape');
|
onCancel("escape");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// handle close buttons too
|
// handle close buttons too
|
||||||
div.on('click', 'a.close', function(e) {
|
div.on("click", "a.close", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
onCancel('close');
|
onCancel("close");
|
||||||
});
|
});
|
||||||
|
|
||||||
// well, *if* we have a primary - give the first dom element focus
|
// well, *if* we have a primary - give the first dom element focus
|
||||||
div.on('shown.bs.modal', function() {
|
div.on("shown.bs.modal", function () {
|
||||||
div.find("a.btn-primary:first").focus();
|
div.find("a.btn-primary:first").focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
div.on('hidden.bs.modal', function() {
|
div.on("hidden.bs.modal", function () {
|
||||||
div.remove();
|
div.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
// wire up button handlers
|
// wire up button handlers
|
||||||
div.on('click', '.modal-footer a', function(e) {
|
div.on("click", ".modal-footer a", function (e) {
|
||||||
var self = this;
|
var self = this;
|
||||||
Ember.run(function () {
|
Ember.run(function () {
|
||||||
|
|
||||||
var handler = $(self).data("handler"),
|
var handler = $(self).data("handler"),
|
||||||
cb = callbacks[handler],
|
cb = callbacks[handler],
|
||||||
hideModal = null;
|
hideModal = null;
|
||||||
|
|
||||||
// sort of @see https://github.com/makeusabrew/bootbox/pull/68 - heavily adapted
|
// sort of @see https://github.com/makeusabrew/bootbox/pull/68 - heavily adapted
|
||||||
// if we've got a custom href attribute, all bets are off
|
// if we've got a custom href attribute, all bets are off
|
||||||
if (typeof handler !== 'undefined' &&
|
if (
|
||||||
typeof handlers[handler]['href'] !== 'undefined') {
|
typeof handler !== "undefined" &&
|
||||||
|
typeof handlers[handler]["href"] !== "undefined"
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === "function") {
|
||||||
hideModal = cb(e);
|
hideModal = cb(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,14 +522,17 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
|
|
||||||
div.modal({
|
div.modal({
|
||||||
// unless explicitly overridden take whatever our default backdrop value is
|
// unless explicitly overridden take whatever our default backdrop value is
|
||||||
backdrop : (typeof options.backdrop === 'undefined') ? _backdrop : options.backdrop,
|
backdrop:
|
||||||
|
typeof options.backdrop === "undefined"
|
||||||
|
? _backdrop
|
||||||
|
: options.backdrop,
|
||||||
// ignore bootstrap's keyboard options; we'll handle this ourselves (more fine-grained control)
|
// ignore bootstrap's keyboard options; we'll handle this ourselves (more fine-grained control)
|
||||||
keyboard: false,
|
keyboard: false,
|
||||||
// @ see https://github.com/makeusabrew/bootbox/issues/69
|
// @ see https://github.com/makeusabrew/bootbox/issues/69
|
||||||
// we *never* want the modal to be shown before we can bind stuff to it
|
// we *never* want the modal to be shown before we can bind stuff to it
|
||||||
// this method can also take a 'show' option, but we'll only use that
|
// this method can also take a 'show' option, but we'll only use that
|
||||||
// later if we need to
|
// later if we need to
|
||||||
show : false
|
show: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// @see https://github.com/makeusabrew/bootbox/issues/64
|
// @see https://github.com/makeusabrew/bootbox/issues/64
|
||||||
@@ -490,7 +543,7 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
$(document).off("focusin.modal");
|
$(document).off("focusin.modal");
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof options.show === 'undefined' || options.show === true) {
|
if (typeof options.show === "undefined" || options.show === true) {
|
||||||
div.modal("show");
|
div.modal("show");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,9 +561,9 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
var options;
|
var options;
|
||||||
|
|
||||||
var defaultOptions = {
|
var defaultOptions = {
|
||||||
"onEscape": null,
|
onEscape: null,
|
||||||
"keyboard": true,
|
keyboard: true,
|
||||||
"backdrop": _backdrop
|
backdrop: _backdrop,
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (arguments.length) {
|
switch (arguments.length) {
|
||||||
@@ -519,7 +572,7 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
str = arguments[0];
|
str = arguments[0];
|
||||||
if (typeof arguments[1] == 'object') {
|
if (typeof arguments[1] == "object") {
|
||||||
options = arguments[1];
|
options = arguments[1];
|
||||||
} else {
|
} else {
|
||||||
label = arguments[1];
|
label = arguments[1];
|
||||||
@@ -534,9 +587,9 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
throw new Error("Incorrect number of arguments: expected 1-3");
|
throw new Error("Incorrect number of arguments: expected 1-3");
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultOptions['header'] = label;
|
defaultOptions["header"] = label;
|
||||||
|
|
||||||
if (typeof options == 'object') {
|
if (typeof options == "object") {
|
||||||
options = $.extend(defaultOptions, options);
|
options = $.extend(defaultOptions, options);
|
||||||
} else {
|
} else {
|
||||||
options = defaultOptions;
|
options = defaultOptions;
|
||||||
@@ -545,7 +598,6 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
return that.dialog(str, [], options);
|
return that.dialog(str, [], options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
that.hideAll = function () {
|
that.hideAll = function () {
|
||||||
$(".bootbox").modal("hide");
|
$(".bootbox").modal("hide");
|
||||||
};
|
};
|
||||||
@@ -571,74 +623,74 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
* unlikely to be required. If this gets too large it can be split out into separate JS files.
|
* unlikely to be required. If this gets too large it can be split out into separate JS files.
|
||||||
*/
|
*/
|
||||||
var _locales = {
|
var _locales = {
|
||||||
'br' : {
|
br: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Cancelar',
|
CANCEL: "Cancelar",
|
||||||
CONFIRM : 'Sim'
|
CONFIRM: "Sim",
|
||||||
},
|
},
|
||||||
'da' : {
|
da: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Annuller',
|
CANCEL: "Annuller",
|
||||||
CONFIRM : 'Accepter'
|
CONFIRM: "Accepter",
|
||||||
},
|
},
|
||||||
'de' : {
|
de: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Abbrechen',
|
CANCEL: "Abbrechen",
|
||||||
CONFIRM : 'Akzeptieren'
|
CONFIRM: "Akzeptieren",
|
||||||
},
|
},
|
||||||
'en' : {
|
en: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Cancel',
|
CANCEL: "Cancel",
|
||||||
CONFIRM : 'OK'
|
CONFIRM: "OK",
|
||||||
},
|
},
|
||||||
'es' : {
|
es: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Cancelar',
|
CANCEL: "Cancelar",
|
||||||
CONFIRM : 'Aceptar'
|
CONFIRM: "Aceptar",
|
||||||
},
|
},
|
||||||
'fr' : {
|
fr: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Annuler',
|
CANCEL: "Annuler",
|
||||||
CONFIRM : 'D\'accord'
|
CONFIRM: "D'accord",
|
||||||
},
|
},
|
||||||
'it' : {
|
it: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Annulla',
|
CANCEL: "Annulla",
|
||||||
CONFIRM : 'Conferma'
|
CONFIRM: "Conferma",
|
||||||
},
|
},
|
||||||
'nl' : {
|
nl: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Annuleren',
|
CANCEL: "Annuleren",
|
||||||
CONFIRM : 'Accepteren'
|
CONFIRM: "Accepteren",
|
||||||
},
|
},
|
||||||
'pl' : {
|
pl: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Anuluj',
|
CANCEL: "Anuluj",
|
||||||
CONFIRM : 'Potwierdź'
|
CONFIRM: "Potwierdź",
|
||||||
},
|
},
|
||||||
'ru' : {
|
ru: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : 'Отмена',
|
CANCEL: "Отмена",
|
||||||
CONFIRM : 'Применить'
|
CONFIRM: "Применить",
|
||||||
},
|
},
|
||||||
'zh_CN' : {
|
zh_CN: {
|
||||||
OK : 'OK',
|
OK: "OK",
|
||||||
CANCEL : '取消',
|
CANCEL: "取消",
|
||||||
CONFIRM : '确认'
|
CONFIRM: "确认",
|
||||||
|
},
|
||||||
|
zh_TW: {
|
||||||
|
OK: "OK",
|
||||||
|
CANCEL: "取消",
|
||||||
|
CONFIRM: "確認",
|
||||||
},
|
},
|
||||||
'zh_TW' : {
|
|
||||||
OK : 'OK',
|
|
||||||
CANCEL : '取消',
|
|
||||||
CONFIRM : '確認'
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function _translate(str, locale) {
|
function _translate(str, locale) {
|
||||||
// we assume if no target locale is probided then we should take it from current setting
|
// we assume if no target locale is probided then we should take it from current setting
|
||||||
if (typeof locale === 'undefined') {
|
if (typeof locale === "undefined") {
|
||||||
locale = _locale;
|
locale = _locale;
|
||||||
}
|
}
|
||||||
if (typeof _locales[locale][str] === 'string') {
|
if (typeof _locales[locale][str] === "string") {
|
||||||
return _locales[locale][str];
|
return _locales[locale][str];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,8 +705,11 @@ var bootbox = window.bootbox || (function(document, $) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
})(document, window.jQuery);
|
||||||
}(document, window.jQuery));
|
|
||||||
|
|
||||||
// @see https://github.com/makeusabrew/bootbox/issues/71
|
// @see https://github.com/makeusabrew/bootbox/issues/71
|
||||||
window.bootbox = bootbox;
|
window.bootbox = bootbox;
|
||||||
|
|
||||||
|
define("bootbox", ["exports"], function (__exports__) {
|
||||||
|
__exports__.default = window.bootbox;
|
||||||
|
});
|
||||||
|
|||||||
@@ -2494,12 +2494,7 @@ pretender@^1.6:
|
|||||||
fake-xml-http-request "^1.6.0"
|
fake-xml-http-request "^1.6.0"
|
||||||
route-recognizer "^0.3.3"
|
route-recognizer "^0.3.3"
|
||||||
|
|
||||||
prettier@2.2.1:
|
prettier@2.2.1, prettier@^2.0.4:
|
||||||
version "2.2.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
|
|
||||||
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
|
|
||||||
|
|
||||||
prettier@^2.0.4:
|
|
||||||
version "2.2.1"
|
version "2.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
|
||||||
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
|
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
|
||||||
|
|||||||
Reference in New Issue
Block a user