Node.js based forum software built for the modern web
Bootbox wrapper improvements
Peter Jaszkowiakbae1daf5dca2
diff --git a/public/src/modules/translator.js b/public/src/modules/translator.jsindex c19c705eaf..0c960f2234 100644--- a/public/src/modules/translator.js+++ b/public/src/modules/translator.js@@ -22,8 +22,8 @@if (global.env === 'development') {var winston = require('winston');- warn = function (a, b, c, d) {- winston.warn(a, b, c, d);+ warn = function (a) {+ winston.warn(a);};}diff --git a/public/vendor/bootbox/wrapper.js b/public/vendor/bootbox/wrapper.jsindex 6988c4398d..bfc9457241 100644--- a/public/vendor/bootbox/wrapper.js+++ b/public/vendor/bootbox/wrapper.js@@ -3,27 +3,52 @@require(['translator'], function (shim) {"use strict";+ function descendantTextNodes(node) {+ var textNodes = [];++ function helper(node) {+ if (node.nodeType === 3) {+ textNodes.push(node);+ } else {+ for (var i = 0, c = node.childNodes, l = c.length; i < l; i += 1) {+ helper(c[i]);+ }+ }+ }++ helper(node);+ return textNodes;+ }+var translator = shim.Translator.create();var dialog = bootbox.dialog;bootbox.dialog = function (options) {- var translate = [- translator.translate(options.message),- options.title && translator.translate(options.title),- ].concat(Object.keys(options.buttons).map(function (key) {- if (/cancel|confirm|ok/.test(key)) {- return null;- }- return translator.translate(options.buttons[key].label).then(function (label) {- options.buttons[key].label = label;- });- }));+ var show, $elem, nodes, text;- Promise.all(translate).then(function (translations) {- options.message = translations[0];- options.title = translations[1];+ show = options.show !== false;+ options.show = false;- dialog.call(bootbox, options);- });+ $elem = dialog.call(bootbox, options);++ if (/\[\[[a-zA-Z0-9\-_.\/:]+\]\]/.test($elem[0].outerHTML)) {+ nodes = descendantTextNodes($elem[0]);+ text = nodes.map(function (node) {+ return node.nodeValue;+ }).join(' || ');++ translator.translate(text).then(function (translated) {+ translated.split(' || ').forEach(function (str, i) {+ nodes[i].nodeValue = str;+ });+ if (show) {+ $elem.modal('show');+ }+ });+ } else if (show) {+ $elem.modal('show');+ }++ return $elem;};Promise.all([