From 3c49770173445f8dd00f07b6dd79bc6279c7dff2 Mon Sep 17 00:00:00 2001 From: RobertPeek Date: Tue, 19 Jan 2016 14:25:44 +0000 Subject: [PATCH] Bug fix for multiple items --- bower.json | 2 +- js/adapt-icon-popup.js | 49 ++++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/bower.json b/bower.json index 289f8d2..7abc0b6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "adapt-icon-popup", - "version": "2.0.1", + "version": "2.0.2", "framework": "2.0.4", "homepage": "https://github.com/deltanet/adapt-icon-popup", "issues": "https://github.com/deltanet/adapt-icon-popup/issues", diff --git a/js/adapt-icon-popup.js b/js/adapt-icon-popup.js index 7f75719..69465ad 100644 --- a/js/adapt-icon-popup.js +++ b/js/adapt-icon-popup.js @@ -13,8 +13,8 @@ define(function(require) { }, events: { - "click .icon-popup-graphic-button":"openPopup", - "click .icon-popup-open-button":"openPopup" + "click .icon-popup-graphic-button":"onItemClicked", + "click .icon-popup-open-button":"onItemClicked" }, preRender: function() {}, @@ -34,38 +34,45 @@ define(function(require) { this.$('.icon-popup-inner').addClass('icon-popup-'+this.model.get("_type")); }, - - openPopup: function(event) { + onItemClicked: function(event) { if (event) event.preventDefault(); - var $item = $(event.currentTarget).parent(); - var currentItem = this.getCurrentItem($item.index()); - var popupObject = { - title: currentItem.title, - body: "
" + - currentItem.body + "
"+
-                currentItem._itemGraphic.alt +"" - }; + var $link = $(event.currentTarget); + var $item = $link; + var itemModel = this.model.get('_iconPopup')._items[$link.index() - 1]; - Adapt.trigger("notify:popup", popupObject); - $item.addClass("visited"); + this.showItemContent(itemModel); + }, + + showItemContent: function(itemModel) { + if(this.isPopupOpen) return;// ensure multiple clicks don't open multiple notify popups + + console.log(itemModel); + + Adapt.trigger("notify:popup", { + title: itemModel.title, + body: "
" + itemModel.body + "
" + + "" +
+                    itemModel._itemGraphic.alt + "" + }); + + this.isPopupOpen = true; ///// Audio ///// if (this.model.get('_iconPopup')._audio._isEnabled && Adapt.audio.audioClip[this.model.get('_iconPopup')._audio._channel].status==1) { // Determine which filetype to play - if (Adapt.audio.audioClip[this.model.get('_iconPopup')._audio._channel].canPlayType('audio/ogg')) this.audioFile = currentItem._audio.ogg; - if (Adapt.audio.audioClip[this.model.get('_iconPopup')._audio._channel].canPlayType('audio/mpeg')) this.audioFile = currentItem._audio.mp3; + if (Adapt.audio.audioClip[this.model.get('_iconPopup')._audio._channel].canPlayType('audio/ogg')) this.audioFile = itemModel._audio.ogg; + if (Adapt.audio.audioClip[this.model.get('_iconPopup')._audio._channel].canPlayType('audio/mpeg')) this.audioFile = itemModel._audio.mp3; // Trigger audio Adapt.trigger('audio:playAudio', this.audioFile, this.model.get('_id'), this.model.get('_iconPopup')._audio._channel); } ///// End of Audio ///// - }, - - getCurrentItem: function(index) { - return this.model.get("_iconPopup")._items[index]; + Adapt.once("notify:closed", _.bind(function() { + this.isPopupOpen = false; + }, this)); } });