diff options
Diffstat (limited to 'core/src/jquery/ocdialog.js')
-rw-r--r-- | core/src/jquery/ocdialog.js | 306 |
1 files changed, 153 insertions, 153 deletions
diff --git a/core/src/jquery/ocdialog.js b/core/src/jquery/ocdialog.js index 8899d9433d1..68384311531 100644 --- a/core/src/jquery/ocdialog.js +++ b/core/src/jquery/ocdialog.js @@ -29,17 +29,17 @@ $.widget('oc.ocdialog', { closeOnEscape: true, modal: false }, - _create: function () { - var self = this; + _create: function() { + var self = this this.originalCss = { display: this.element[0].style.display, width: this.element[0].style.width, height: this.element[0].style.height - }; + } - this.originalTitle = this.element.attr('title'); - this.options.title = this.options.title || this.originalTitle; + this.originalTitle = this.element.attr('title') + this.options.title = this.options.title || this.originalTitle this.$dialog = $('<div class="oc-dialog" />') .attr({ @@ -47,224 +47,224 @@ $.widget('oc.ocdialog', { tabIndex: -1, role: 'dialog' }) - .insertBefore(this.element); - this.$dialog.append(this.element.detach()); - this.element.removeAttr('title').addClass('oc-dialog-content').appendTo(this.$dialog); + .insertBefore(this.element) + this.$dialog.append(this.element.detach()) + this.element.removeAttr('title').addClass('oc-dialog-content').appendTo(this.$dialog) this.$dialog.css({ display: 'inline-block', position: 'fixed' - }); + }) - this.enterCallback = null; + this.enterCallback = null - $(document).on('keydown keyup', function (event) { + $(document).on('keydown keyup', function(event) { if ( - event.target !== self.$dialog.get(0) && - self.$dialog.find($(event.target)).length === 0 + event.target !== self.$dialog.get(0) + && self.$dialog.find($(event.target)).length === 0 ) { - return; + return } // Escape if ( - event.keyCode === 27 && - event.type === 'keydown' && - self.options.closeOnEscape + event.keyCode === 27 + && event.type === 'keydown' + && self.options.closeOnEscape ) { - event.stopImmediatePropagation(); - self.close(); - return false; + event.stopImmediatePropagation() + self.close() + return false } // Enter if (event.keyCode === 13) { - event.stopImmediatePropagation(); + event.stopImmediatePropagation() if (self.enterCallback !== null) { - self.enterCallback(); - event.preventDefault(); - return false; + self.enterCallback() + event.preventDefault() + return false } if (event.type === 'keyup') { - event.preventDefault(); - return false; + event.preventDefault() + return false } // If no button is selected we trigger the primary if ( - self.$buttonrow && - self.$buttonrow.find($(event.target)).length === 0 + self.$buttonrow + && self.$buttonrow.find($(event.target)).length === 0 ) { - var $button = self.$buttonrow.find('button.primary'); + var $button = self.$buttonrow.find('button.primary') if ($button && !$button.prop('disabled')) { - $button.trigger('click'); + $button.trigger('click') } } else if (self.$buttonrow) { - $(event.target).trigger('click'); + $(event.target).trigger('click') } - return false; + return false } - }); + }) - this._setOptions(this.options); - this._createOverlay(); + this._setOptions(this.options) + this._createOverlay() }, - _init: function () { - this.$dialog.focus(); - this._trigger('open'); + _init: function() { + this.$dialog.focus() + this._trigger('open') }, - _setOption: function (key, value) { - var self = this; + _setOption: function(key, value) { + var self = this switch (key) { - case 'title': - if (this.$title) { - this.$title.text(value); - } else { - var $title = $('<h2 class="oc-dialog-title">' + case 'title': + if (this.$title) { + this.$title.text(value) + } else { + var $title = $('<h2 class="oc-dialog-title">' + value - + '</h2>'); - this.$title = $title.prependTo(this.$dialog); - } - this._setSizes(); - break; - case 'buttons': - if (this.$buttonrow) { - this.$buttonrow.empty(); - } else { - var $buttonrow = $('<div class="oc-dialog-buttonrow" />'); - this.$buttonrow = $buttonrow.appendTo(this.$dialog); - } - if (value.length === 1) { - this.$buttonrow.addClass('onebutton'); - } else if (value.length === 2) { - this.$buttonrow.addClass('twobuttons'); - } else if (value.length === 3) { - this.$buttonrow.addClass('threebuttons'); - } - $.each(value, function (idx, val) { - var $button = $('<button>').text(val.text); - if (val.classes) { - $button.addClass(val.classes); - } - if (val.defaultButton) { - $button.addClass('primary'); - self.$defaultButton = $button; - } - self.$buttonrow.append($button); - $button.click(function () { - val.click.apply(self.element[0], arguments); - }); - }); - this.$buttonrow.find('button') - .on('focus', function (event) { - self.$buttonrow.find('button').removeClass('primary'); - $(this).addClass('primary'); - }); - this._setSizes(); - break; - case 'style': - if (value.buttons !== undefined) { - this.$buttonrow.addClass(value.buttons); + + '</h2>') + this.$title = $title.prependTo(this.$dialog) + } + this._setSizes() + break + case 'buttons': + if (this.$buttonrow) { + this.$buttonrow.empty() + } else { + var $buttonrow = $('<div class="oc-dialog-buttonrow" />') + this.$buttonrow = $buttonrow.appendTo(this.$dialog) + } + if (value.length === 1) { + this.$buttonrow.addClass('onebutton') + } else if (value.length === 2) { + this.$buttonrow.addClass('twobuttons') + } else if (value.length === 3) { + this.$buttonrow.addClass('threebuttons') + } + $.each(value, function(idx, val) { + var $button = $('<button>').text(val.text) + if (val.classes) { + $button.addClass(val.classes) } - break; - case 'closeButton': - if (value) { - var $closeButton = $('<a class="oc-dialog-close"></a>'); - this.$dialog.prepend($closeButton); - $closeButton.on('click', function () { - self.close(); - }); - } else { - this.$dialog.find('.oc-dialog-close').remove(); + if (val.defaultButton) { + $button.addClass('primary') + self.$defaultButton = $button } - break; - case 'width': - this.$dialog.css('width', value); - break; - case 'height': - this.$dialog.css('height', value); - break; - case 'close': - this.closeCB = value; - break; + self.$buttonrow.append($button) + $button.click(function() { + val.click.apply(self.element[0], arguments) + }) + }) + this.$buttonrow.find('button') + .on('focus', function(event) { + self.$buttonrow.find('button').removeClass('primary') + $(this).addClass('primary') + }) + this._setSizes() + break + case 'style': + if (value.buttons !== undefined) { + this.$buttonrow.addClass(value.buttons) + } + break + case 'closeButton': + if (value) { + var $closeButton = $('<a class="oc-dialog-close"></a>') + this.$dialog.prepend($closeButton) + $closeButton.on('click', function() { + self.close() + }) + } else { + this.$dialog.find('.oc-dialog-close').remove() + } + break + case 'width': + this.$dialog.css('width', value) + break + case 'height': + this.$dialog.css('height', value) + break + case 'close': + this.closeCB = value + break } - //this._super(key, value); - $.Widget.prototype._setOption.apply(this, arguments); + // this._super(key, value); + $.Widget.prototype._setOption.apply(this, arguments) }, - _setOptions: function (options) { - //this._super(options); - $.Widget.prototype._setOptions.apply(this, arguments); + _setOptions: function(options) { + // this._super(options); + $.Widget.prototype._setOptions.apply(this, arguments) }, - _setSizes: function () { - var lessHeight = 0; + _setSizes: function() { + var lessHeight = 0 if (this.$title) { - lessHeight += this.$title.outerHeight(true); + lessHeight += this.$title.outerHeight(true) } if (this.$buttonrow) { - lessHeight += this.$buttonrow.outerHeight(true); + lessHeight += this.$buttonrow.outerHeight(true) } this.element.css({ 'height': 'calc(100% - ' + lessHeight + 'px)' - }); + }) }, - _createOverlay: function () { + _createOverlay: function() { if (!this.options.modal) { - return; + return } - var self = this; + var self = this this.overlay = $('<div>') .addClass('oc-dialog-dim') - .appendTo($('#content')); - this.overlay.on('click keydown keyup', function (event) { + .appendTo($('#content')) + this.overlay.on('click keydown keyup', function(event) { if (event.target !== self.$dialog.get(0) && self.$dialog.find($(event.target)).length === 0) { - event.preventDefault(); - event.stopPropagation(); - return; + event.preventDefault() + event.stopPropagation() + } - }); + }) }, - _destroyOverlay: function () { + _destroyOverlay: function() { if (!this.options.modal) { - return; + return } if (this.overlay) { - this.overlay.off('click keydown keyup'); - this.overlay.remove(); - this.overlay = null; + this.overlay.off('click keydown keyup') + this.overlay.remove() + this.overlay = null } }, - widget: function () { - return this.$dialog; + widget: function() { + return this.$dialog }, - setEnterCallback: function (callback) { - this.enterCallback = callback; + setEnterCallback: function(callback) { + this.enterCallback = callback }, - unsetEnterCallback: function () { - this.enterCallback = null; + unsetEnterCallback: function() { + this.enterCallback = null }, - close: function () { - this._destroyOverlay(); - var self = this; + close: function() { + this._destroyOverlay() + var self = this // Ugly hack to catch remaining keyup events. - setTimeout(function () { - self._trigger('close', self); - }, 200); + setTimeout(function() { + self._trigger('close', self) + }, 200) - self.$dialog.remove(); - this.destroy(); + self.$dialog.remove() + this.destroy() }, - destroy: function () { + destroy: function() { if (this.$title) { - this.$title.remove(); + this.$title.remove() } if (this.$buttonrow) { - this.$buttonrow.remove(); + this.$buttonrow.remove() } if (this.originalTitle) { - this.element.attr('title', this.originalTitle); + this.element.attr('title', this.originalTitle) } this.element.removeClass('oc-dialog-content') - .css(this.originalCss).detach().insertBefore(this.$dialog); - this.$dialog.remove(); + .css(this.originalCss).detach().insertBefore(this.$dialog) + this.$dialog.remove() } -}); +}) |