diff options
Diffstat (limited to 'src/js/share-options.js')
-rwxr-xr-x | src/js/share-options.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/js/share-options.js b/src/js/share-options.js new file mode 100755 index 0000000..5ea077b --- /dev/null +++ b/src/js/share-options.js @@ -0,0 +1,89 @@ +(function($) { + 'use strict'; + + // Open and close the share options bar + + /** + * ShareOptionsBar + * @constructor + */ + var ShareOptionsBar = function() { + this.$shareOptionsBar = $('#share-options-bar'); + this.$openBtn = $('.btn-open-shareoptions'); + this.$closeBtn = $('#share-options-mask'); + }; + + ShareOptionsBar.prototype = { + + /** + * Run ShareOptionsBar feature + * @return {void} + */ + run: function() { + var self = this; + + // Detect the click on the open button + self.$openBtn.click(function() { + if (!self.$shareOptionsBar.hasClass('opened')) { + self.openShareOptions(); + self.$closeBtn.show(); + } + }); + + // Detect the click on the close button + self.$closeBtn.click(function() { + if (self.$shareOptionsBar.hasClass('opened')) { + self.closeShareOptions(); + self.$closeBtn.hide(); + } + }); + }, + + /** + * Open share options bar + * @return {void} + */ + openShareOptions: function() { + var self = this; + + // Check if the share option bar isn't opened + // and prevent multiple click on the open button with `.processing` class + if (!self.$shareOptionsBar.hasClass('opened') && + !this.$shareOptionsBar.hasClass('processing')) { + // Open the share option bar + self.$shareOptionsBar.addClass('processing opened'); + + setTimeout(function() { + self.$shareOptionsBar.removeClass('processing'); + }, 250); + } + }, + + /** + * Close share options bar + * @return {void} + */ + closeShareOptions: function() { + var self = this; + + // Check if the share options bar is opened + // and prevent multiple click on the close button with `.processing` class + if (self.$shareOptionsBar.hasClass('opened') && + !this.$shareOptionsBar.hasClass('processing')) { + // Close the share option bar + self.$shareOptionsBar + .addClass('processing') + .removeClass('opened'); + + setTimeout(function() { + self.$shareOptionsBar.removeClass('processing'); + }, 250); + } + } + }; + + $(document).ready(function() { + var shareOptionsBar = new ShareOptionsBar(); + shareOptionsBar.run(); + }); +})(jQuery); |