summaryrefslogtreecommitdiff
path: root/addons/website/static/lib/summernote/src/js/module/Dialog.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/website/static/lib/summernote/src/js/module/Dialog.js')
-rw-r--r--addons/website/static/lib/summernote/src/js/module/Dialog.js158
1 files changed, 158 insertions, 0 deletions
diff --git a/addons/website/static/lib/summernote/src/js/module/Dialog.js b/addons/website/static/lib/summernote/src/js/module/Dialog.js
new file mode 100644
index 00000000000..8e7cf07b323
--- /dev/null
+++ b/addons/website/static/lib/summernote/src/js/module/Dialog.js
@@ -0,0 +1,158 @@
+define('summernote/module/Dialog', function () {
+ /**
+ * Dialog
+ *
+ * @class
+ */
+ var Dialog = function () {
+
+ /**
+ * toggle button status
+ *
+ * @param {jQuery} $btn
+ * @param {Boolean} isEnable
+ */
+ var toggleBtn = function ($btn, isEnable) {
+ $btn.toggleClass('disabled', !isEnable);
+ $btn.attr('disabled', !isEnable);
+ };
+
+ /**
+ * show image dialog
+ *
+ * @param {jQuery} $editable
+ * @param {jQuery} $dialog
+ * @return {Promise}
+ */
+ this.showImageDialog = function ($editable, $dialog) {
+ return $.Deferred(function (deferred) {
+ var $imageDialog = $dialog.find('.note-image-dialog');
+
+ var $imageInput = $dialog.find('.note-image-input'),
+ $imageUrl = $dialog.find('.note-image-url'),
+ $imageBtn = $dialog.find('.note-image-btn');
+
+ $imageDialog.one('shown.bs.modal', function () {
+ // Cloning imageInput to clear element.
+ $imageInput.replaceWith($imageInput.clone()
+ .on('change', function () {
+ deferred.resolve(this.files || this.value);
+ $imageDialog.modal('hide');
+ })
+ .val('')
+ );
+
+ $imageBtn.click(function (event) {
+ event.preventDefault();
+
+ deferred.resolve($imageUrl.val());
+ $imageDialog.modal('hide');
+ });
+
+ $imageUrl.on('keyup paste', function (event) {
+ var url;
+
+ if (event.type === 'paste') {
+ url = event.originalEvent.clipboardData.getData('text');
+ } else {
+ url = $imageUrl.val();
+ }
+
+ toggleBtn($imageBtn, url);
+ }).val('').trigger('focus');
+ }).one('hidden.bs.modal', function () {
+ $imageInput.off('change');
+ $imageUrl.off('keyup paste');
+ $imageBtn.off('click');
+
+ if (deferred.state() === 'pending') {
+ deferred.reject();
+ }
+ }).modal('show');
+ });
+ };
+
+ /**
+ * Show link dialog and set event handlers on dialog controls.
+ *
+ * @param {jQuery} $dialog
+ * @param {Object} linkInfo
+ * @return {Promise}
+ */
+ this.showLinkDialog = function ($editable, $dialog, linkInfo) {
+ return $.Deferred(function (deferred) {
+ var $linkDialog = $dialog.find('.note-link-dialog');
+
+ var $linkText = $linkDialog.find('.note-link-text'),
+ $linkUrl = $linkDialog.find('.note-link-url'),
+ $linkBtn = $linkDialog.find('.note-link-btn'),
+ $openInNewWindow = $linkDialog.find('input[type=checkbox]');
+
+ $linkDialog.one('shown.bs.modal', function () {
+ $linkText.val(linkInfo.text);
+
+ $linkText.on('input', function () {
+ // if linktext was modified by keyup,
+ // stop cloning text from linkUrl
+ linkInfo.text = $linkText.val();
+ });
+
+ // if no url was given, copy text to url
+ if (!linkInfo.url) {
+ linkInfo.url = linkInfo.text;
+ toggleBtn($linkBtn, linkInfo.text);
+ }
+
+ $linkUrl.on('input', function () {
+ toggleBtn($linkBtn, $linkUrl.val());
+ // display same link on `Text to display` input
+ // when create a new link
+ if (!linkInfo.text) {
+ $linkText.val($linkUrl.val());
+ }
+ }).val(linkInfo.url).trigger('focus').trigger('select');
+
+ $openInNewWindow.prop('checked', linkInfo.newWindow);
+
+ $linkBtn.one('click', function (event) {
+ event.preventDefault();
+
+ deferred.resolve({
+ range: linkInfo.range,
+ url: $linkUrl.val(),
+ text: $linkText.val(),
+ newWindow: $openInNewWindow.is(':checked')
+ });
+ $linkDialog.modal('hide');
+ });
+ }).one('hidden.bs.modal', function () {
+ // detach events
+ $linkText.off('input');
+ $linkUrl.off('input');
+ $linkBtn.off('click');
+
+ if (deferred.state() === 'pending') {
+ deferred.reject();
+ }
+ }).modal('show');
+ }).promise();
+ };
+
+ /**
+ * show help dialog
+ *
+ * @param {jQuery} $dialog
+ */
+ this.showHelpDialog = function ($editable, $dialog) {
+ return $.Deferred(function (deferred) {
+ var $helpDialog = $dialog.find('.note-help-dialog');
+
+ $helpDialog.one('hidden.bs.modal', function () {
+ deferred.resolve();
+ }).modal('show');
+ }).promise();
+ };
+ };
+
+ return Dialog;
+});