diff --git a/Resources/Themes/Frontend/BootstrapBare/frontend/_public/src/js/swbt.modal.js b/Resources/Themes/Frontend/BootstrapBare/frontend/_public/src/js/swbt.modal.js index a79de58..222080f 100755 --- a/Resources/Themes/Frontend/BootstrapBare/frontend/_public/src/js/swbt.modal.js +++ b/Resources/Themes/Frontend/BootstrapBare/frontend/_public/src/js/swbt.modal.js @@ -1,8 +1,622 @@ -;(function ($) { +; (function ($) { "use strict"; var $body = $('body'); + // create shopware modal fallback to prevent js errors in shopware plugins + $.modal = { + /** + * The complete template wrapped in jQuery. + * + * @private + * @property _$modalBox + * @type {jQuery} + */ + _$modalBox: null, + + /** + * Container for the title wrapped in jQuery. + * + * @private + * @property _$header + * @type {jQuery} + */ + _$header: null, + + /** + * The title element wrapped in jQuery. + * + * @private + * @property _$title + * @type {jQuery} + */ + _$title: null, + + /** + * The content element wrapped in jQuery. + * + * @private + * @property _$content + * @type {jQuery} + */ + _$content: null, + + /** + * The close button wrapped in jQuery. + * + * @private + * @property _$closeButton + * @type {jQuery} + */ + _$closeButton: null, + + /** + * Default options of a opening session. + * + * @public + * @property defaults + * @type {jQuery} + */ + defaults: { + /** + * The mode in which the lightbox should be showing. + * + * 'local': + * + * The given content is either text or HTML. + * + * 'ajax': + * + * The given content is the URL from what it should load the HTML. + * + * 'iframe': + * + * The given content is the source URL of the iframe. + * + * @type {String} + */ + mode: 'local', + + /** + * Sizing mode of the modal box. + * + * 'auto': + * + * Will set the given width as max-width so the container can shrink. + * Fullscreen mode on small mobile devices. + * + * 'fixed': + * + * Will use the width and height as static sizes and will not change to fullscreen mode. + * + * 'content': + * + * Will use the height of its content instead of a given height. + * The 'height' option will be ignored when set. + * + * 'full': + * + * Will set the modalbox to fullscreen. + * + * @type {String} + */ + sizing: 'modal-lg', + + /** + * The width of the modal box window. + * NOT used for bsmodal! + * + * @type {Number} + */ + width: false, + + /** + * The height of the modal box window. + * NOT used for bsmodal! + * + * @type {Number} + */ + height: false, + + /** + * The max height if sizing is set to `content`. + * NOT used for bsmodal! + * + * @type {Number} + */ + maxHeight: false, + + /** + * Whether or not the overlay should be shown. + * NOT used for bsmodal! It always has an overlay! + * + * @type {Boolean} + */ + overlay: true, + + /** + * Whether or not the modal box should be closed when the user clicks on the overlay. + * NOT used for bsmodal! + * + * @type {Boolean} + */ + closeOnOverlay: true, + + /** + * Whether or not the closing button should be shown. + * Not used for bsmodal! + * + * @type {Boolean} + */ + showCloseButton: true, + + /** + * Speed for every CSS transition animation. + * NOT used for bsmodal! + * + * @type {Number} + */ + animationSpeed: 500, + + /** + * The window title of the modal box. + * If empty, the header will be hidden. + * + * @type {String} + */ + title: '', + + /** + * Will be overridden by the current URL when the mode is 'ajax' or 'iframe'. + * Can be accessed by the options object. + * NOT used for bsmodal! + * + * @type {String} + */ + src: '', + + /** + * Array of key codes the modal box can be closed. + * + * @type {Array} + */ + closeKeys: [27], + + /** + * Whether or not it is possible to close the modal box by the keyboard. + * + * @type {Boolean} + */ + keyboardClosing: true, + + /** + * Function which will be called when the modal box is closing. + * + * @type {Function} + */ + onClose: function () {}, + + /** + * Whether or not the picturefill function will be called when setting content. + * NOT used for bsmodal! + * + * @type {Boolean} + */ + updateImages: false, + + /** + * Class that will be added to the modalbox. + * + * @type {String} + */ + additionalClass: '', + footer: null, + id: null, + }, + + /** + * The current merged options of the last .open() call. + * + * @public + * @property options + * @type {Object} + */ + options: {}, + + /** + * Opens the modal box. + * Sets the given content and applies the given options to the current session. + * If given, the overlay options will be passed in its .open() call. + * + * @public + * @method open + * @param {String|jQuery|HTMLElement} content + * @param {Object} options + */ + open: function (content, options) { + var me = this, + $modalBox = me._$modalBox, + opts; + + me.options = opts = $.extend({}, me.defaults, options); + + // Bootstrap Modal start: + $('body').createModal(content, opts.sizing, opts.additionalClass + ' fade', opts.title, opts.footer, function(){}, opts); + // Bootstrap Modal end: + + $.publish('plugin/swModal/onOpen', [ me ]); + return me; + }, + + /** + * Closes the modal box and the overlay if its enabled. + * if the fading is completed, the content will be removed. + * + * @public + * @method close + */ + close: function () { + var me = this, + opts = me.options, + $modalBox = me._$modalBox; + + // TODO: Expected to work, but undefined: + // me.$el.modal('hide'); + // Workaround: + $(".modal").modal('hide'); + + $.publish('plugin/swModal/onClose', [ me ]); + + return me; + }, + + /** + * Sets the transition of the modal box. + * + * @public + * @method setTransition + * @param {Object} css + * @param {Number} duration + * @param {String} animation + * @param {Function} callback + */ + setTransition: function (css, duration, animation, callback) { + // TODO: NO YET IMPLEMENTED FOR Bootstrap Theme! + // Original Responsive Theme Code: + + var me = this, + // $modalBox = me._$modalBox, + opts = $.extend({ + animation: 'ease', + duration: me.options.animationSpeed + }, { + animation: animation, + duration: duration + }); + + // if (!$.support.transition) { + // $modalBox.stop(true).animate(css, opts.duration, opts.animation, callback); + // return; + // } + + // $modalBox.stop(true).transition(css, opts.duration, opts.animation, callback); + + $.publish('plugin/swModal/onSetTransition', [ me, css, opts ]); + }, + + /** + * Sets the title of the modal box. + * + * @public + * @method setTitle + * @param {String} title + */ + setTitle: function (title) { + // TODO: NO YET IMPLEMENTED FOR Bootstrap Theme! + // Original Responsive Theme Code: + var me = this; + + // me._$title.html(title); + + $.publish('plugin/swModal/onSetTitle', [ me, title ]); + }, + + /** + * Sets the content of the modal box. + * + * @public + * @method setContent + * @param {String|jQuery|HTMLElement} content + */ + setContent: function (content) { + // TODO: NO YET IMPLEMENTED FOR Bootstrap Theme! + // Original Responsive Theme Code: + + var me = this, + opts = me.options; + + // me._$content.html(content); + + // if (opts.sizing === 'content') { + // // initial centering + // me.center(); + + // // centering again to fix some styling/positioning issues + // window.setTimeout(me.center.bind(me), 25); + // } + + // if (opts.updateImages) { + // picturefill(); + // } + + $.publish('plugin/swModal/onSetContent', [ me ]); + }, + + /** + * Sets the width of the modal box. + * If a string was passed containing a only number, it will be parsed as a pixel value. + * + * @public + * @method setWidth + * @param {Number|String} width + */ + setWidth: function (width) { + // TODO: NO YET IMPLEMENTED FOR Bootstrap Theme! + // Original Responsive Theme Code: + var me = this; + + // me._$modalBox.css('width', (typeof width === 'string' && !(/^\d+$/.test(width))) ? width : parseInt(width, 10)); + + $.publish('plugin/swModal/onSetWidth', [ me ]); + }, + + /** + * Sets the height of the modal box. + * If a string was passed containing a only number, it will be parsed as a pixel value. + * + * @public + * @method setHeight + * @param {Number|String} height + */ + setHeight: function (height) { + // TODO: NO YET IMPLEMENTED FOR Bootstrap Theme! + // Original Responsive Theme Code: + var me = this, + hasTitle = me._$title.text().length > 0, + headerHeight; + + // height = (typeof height === 'string' && !(/^\d+$/.test(height))) ? height : window.parseInt(height, 10); + + // if (hasTitle) { + // headerHeight = window.parseInt(me._$header.css('height'), 10); + // me._$content.css('height', (height - headerHeight)); + // } else { + // me._$content.css('height', '100%'); + // } + + // me._$modalBox.css('height', height); + $.publish('plugin/swModal/onSetHeight', [ me ]); + }, + + /** + * Sets the max height of the modal box if the provided value is not empty or greater than 0. + * If a string was passed containing a only number, it will be parsed as a pixel value. + * + * @public + * @method setMaxHeight + * @param {Number|String} height + */ + setMaxHeight: function (height) { + // TODO: NO YET IMPLEMENTED FOR Bootstrap Theme! + // Original Responsive Theme Code: + var me = this; + + // if (!height) { + // return; + // } + + // height = (typeof height === 'string' && !(/^\d+$/.test(height))) ? height : window.parseInt(height, 10); + + // me._$modalBox.css('max-height', height); + $.publish('plugin/swModal/onSetMaxHeight', [ me ]); + }, + + /** + * Creates the modal box and all its elements. + * Appends it to the body. + * + * @public + * @method initModalBox + */ + initModalBox: function () { + // TODO: NO YET IMPLEMENTED FOR Bootstrap Theme! + // Original Responsive Theme Code: + var me = this; + + // me._$modalBox = $('