show: function(duration, callback) { if (typeof duration == "function") { callback = duration; duration = undefined; } if (!visibility.hidden) return; Adapt.trigger("popup:opened"); this.render(); if (typeof duration == "undefined") duration = this.model.get("_duration").show; var rollay = this; if (duration > 0) { this.$el.css({top: $(window).height() + "px", display: "block" }); this.$el.animate({ top: visibility.top + "px" }, {duration:duration, start: function() { visibility.hidden = false; Adapt.trigger("rollay:opening"); }, complete: function() { visibility.scrollTop = $("body").scrollTop(); $("body").css({ "height": $(window).height() + "px" }).addClass("stop-scroll"); Adapt.trigger("rollay:opened"); callback(); }}); } else { Adapt.trigger("rollay:opening"); this.$el.css({top: visibility.top + "px", display: "block" }); visibility.hidden = false; visibility.scrollTop = $("body").scrollTop(); $("body").css({ "height": $(window).height() + "px" }).addClass("stop-scroll"); Adapt.trigger("rollay:opened"); callback(); } },
handleId: function(id) { var currentModel = Adapt.findById(id); switch (currentModel.get('_type')) { case 'page': case 'menu': this.removeViews(); this.showLoading(); this.setContentObjectToVisited(currentModel); if (currentModel.get('_type') == 'page') { var location = 'page-' + id; this.updateLocation(location, 'page', id); Adapt.trigger('router:page', currentModel); this.$wrapper.append(new PageView({model:currentModel}).$el); } else { var location = 'menu-' + id; this.updateLocation(location, 'menu', id); Adapt.trigger('router:menu', currentModel); } break; default: Adapt.navigateToElement('.' + id); } },
onscreen: function(event, measurements) { var visible = this.model.get('_isVisible'); var isOnscreenY = measurements.percentFromTop < Adapt.audio.triggerPosition && measurements.percentFromTop > 0; var isOnscreenX = measurements.percentInviewHorizontal == 100; var isOnscreen = measurements.onscreen; // Check for element coming on screen if (visible && isOnscreenY && isOnscreenX && this.canAutoplay && this.onscreenTriggered == false) { // Check if audio is set to on if (Adapt.audio.audioClip[this.audioChannel].status == 1) { Adapt.trigger('audio:playAudio', this.audioFile, this.elementId, this.audioChannel); } // Set to false to stop autoplay when onscreen again if (this.autoplayOnce) { this.canAutoplay = false; } // Set to true to stop onscreen looping this.onscreenTriggered = true; } // Check when element is off screen if (visible && isOnscreen == false) { this.onscreenTriggered = false; Adapt.trigger('audio:onscreenOff', this.elementId, this.audioChannel); } },
closeNotify: function (event) { if (this.disableAnimation) { this.$('.notify-popup').css("visibility", "hidden"); this.$el.css("visibility", "hidden"); this.remove(); } else { this.$('.notify-popup').velocity({ opacity: 0 }, {duration:400, complete: _.bind(function() { this.$('.notify-popup').css("visibility", "hidden"); }, this)}); this.$('.notify-shadow').velocity({ opacity: 0 }, {duration:400, complete:_.bind(function() { this.$el.css("visibility", "hidden"); this.remove(); }, this)}); } $('body').scrollEnable(); Adapt.trigger('popup:closed'); Adapt.trigger('notify:closed'); }
handleId: function(id) { console.log("router.js,handleId " + id); this.removeViews(); this.showLoading(); var currentModel = Adapt.contentObjects.findWhere({_id:id}); /* if(Adapt.course.get("_locationIds") && Adapt.course.get("_locationIds")._menu) { console.log(Adapt.course.get("_locationIds")._menu); if(Adapt.course.get("_locationIds")._menu === id) { var location = 'menu-' + id; this.updateLocation(location, 'menu', id); console.log("tigger router:menu",currentModel); Adapt.trigger('router:menu', currentModel); return; } } */ this.setContentObjectToVisited(currentModel); if (currentModel.get('_type') == 'page') { var location = 'page-' + id; this.updateLocation(location, 'page', id); Adapt.trigger('router:page', currentModel); this.$wrapper.append(new PageView({model:currentModel}).$el); } else { var location = 'menu-' + id; this.updateLocation(location, 'menu', id); Adapt.trigger('router:menu', currentModel); } },
assessmentComplete: function() { function notComplete(model) { return !model.get('_isComplete'); } if(notComplete(this.model) || _.some(this.getQuestionComponents(), notComplete)) return; var isPercentageBased = this.model.get('_assessment')._isPercentageBased; var scoreToPass = this.model.get('_assessment')._scoreToPass; var score = this.getScore(); var scoreAsPercent = this.getScoreAsPercent(); var isPass = false; this.setFeedbackMessage(); this.model.set({ 'feedbackTitle': this.model.get('_assessment')._completionMessage.title, 'score': isPercentageBased ? scoreAsPercent + '%' : score }); Adapt.trigger('questionView:showFeedback', this); if (isPercentageBased) { isPass = (scoreAsPercent >= scoreToPass) ? true : false; } else { isPass = (score >= scoreToPass) ? true : false; } Adapt.trigger('assessment:complete', {isPass: isPass, score: score, scoreAsPercent: scoreAsPercent}); },
function finished() { visibility.hidden = true; Adapt.trigger("popup:closed"); Adapt.trigger("bottomnavigation:closed"); bottomnavigation.$el.hide(); bottomnavigation.$el.css("height", ""); }
showDrawer: function(emptyDrawer) { Adapt.trigger('popup:opened'); var drawerWidth = this.$el.width(); if (emptyDrawer) { this.$('.drawer-back').addClass('display-none'); this._isCustomViewVisible = false; this.emptyDrawer(); this.renderItems(); Adapt.trigger('drawer:openedItemView'); } else { if (this._hasBackButton) { this.$('.drawer-back').removeClass('display-none'); } else { this.$('.drawer-back').addClass('display-none'); } Adapt.trigger('drawer:openedCustomView'); } _.defer(_.bind(function() { var showEasingAnimation = Adapt.config.get('_drawer')._showEasing; var easing = (showEasingAnimation) ? showEasingAnimation : 'easeOutQuart'; this.$el.velocity({'right': 0}, this.drawerDuration, easing); // Dim down the page or menu containers // CSS is used here as on mobile/tablet devices it makes the animation jerky $('.page, .menu').css({opacity:0.5}); this.addBodyEvent(); Adapt.trigger('drawer:opened'); }, this)); },
scrollToPageElement: function(event) { event.preventDefault(); var currentComponentSelector = '.' + $(event.currentTarget).attr('data-page-level-progress-id'); var $currentComponent = $(currentComponentSelector); $(window).scrollTo($currentComponent, {offset:{top:-$('.navigation').height()}}); Adapt.trigger('page:scrollTo', currentComponentSelector); Adapt.trigger('drawer:closeDrawer'); },
function finished() { visibility.hidden = true; Adapt.trigger("popup:closed"); Adapt.trigger("rollay:closed"); rollay.$el.css({ display: "none" }); $("body").css("height", "auto"); callback(); }
var onRouteTo = function (item, to, replaceUrl, event) { if (event) { event.preventDefault(); event.stopPropagation(); } if (to.substr(0,1) == "#") { Adapt.trigger("remove"); Backbone.history.navigate(to, {trigger: true, replace: false}); } else if (to == "") { Adapt.trigger("remove"); Backbone.history.navigate("#/", {trigger: true, replace: false}); } else if (to.substr(0,1) == "@") { var sections = to.substr(1).split(" "); var type = sections[0]; var amount = eval( "0" + sections[1] + ";" ); var currentId = this.model.get("_id"); var currentType = this.model.get("_type"); var currentPage = resolveType(currentId, "page"); switch (type) { case "article": var currentArticle = resolveType(currentId, "article"); var toItem = resolveItem(item, currentPage, currentArticle, amount, "articles"); if (toItem === undefined) return; var next = $("." + toItem.get("_id")); if (next.length === 0) return; $.scrollTo(next.offset()['top'] - $('.navigation').height() - parseInt(next.css("margin-top")), {axis:'y', duration: 1000 }); break; case "block": var currentBlock = resolveType(currentId, "block"); var toItem = resolveItem(item, currentPage, currentBlock, amount, "blocks"); if (toItem === undefined) return; var next = $("." + toItem.get("_id")); if (next.length === 0) return; Adapt.scrollTo(next.offset()['top'] - $('.navigation').height() - parseInt(next.css("margin-top")), {axis:'y', duration: 1000 }); break; case "component": var currentComponent = resolveType(currentId, "component"); var toItem = resolveItem(item, currentPage, currentComponent, amount, "components"); if (toItem === undefined) return; var next = $("." + toItem.get("_id")); if (next.length === 0) return; Adapt.scrollTo(next.offset()['top'] - $('.navigation').height() - parseInt(next.css("margin-top")), {axis:'y', duration: 1000 }); break; } } else { var model = Adapt.findById(to); if (model) { switch (model.get("_type")) { case "page": case "menu": Backbone.history.navigate("#/id/"+to, {trigger: true, replace: replaceUrl}); break; default: Adapt.navigateToElement("." + to); break; } } } }
showFeedback: function() { if (this.model.get('_canShowFeedback')) { Adapt.trigger('questionView:showFeedback', this); } else { Adapt.trigger('questionView:disabledFeedback', this); } },
toggleAudio: function(event) { if (event) event.preventDefault(); Adapt.audio.audioClip[this.audioChannel].onscreenID = ""; if ($(event.currentTarget).hasClass('playing')) { Adapt.trigger('audio:pauseAudio', this.audioChannel); } else { Adapt.trigger('audio:playAudio', this.audioFile, this.elementId, this.audioChannel); } },
success: _.bind(function() { Adapt.trigger('configModel:dataLoaded'); if (this.get('_canLoadData')) { Adapt.trigger('configModel:loadCourseData'); } if(this.get('_defaultDirection')=='rtl'){//We're going to use rtl style $('html').addClass('dir-rtl'); } }, this),
var onWindowResize = _.debounce(function onScreenSizeChanged() { Adapt.device.screenWidth = $window.width(); Adapt.trigger('device:resize', Adapt.device.screenWidth); var newScreenSize = checkScreenSize(); if (newScreenSize !== Adapt.device.screenSize) { Adapt.device.screenSize = newScreenSize; Adapt.trigger('device:changed', Adapt.device.screenSize); } }, 100);
openPopup: function (event) { event.preventDefault(); var currentItem = this.getCurrentItem(this.model.get('_stage')), popupObject = { title: currentItem.title, body: currentItem.body }; Adapt.trigger('notify:popup', popupObject); Adapt.trigger('popup:opened'); },
handlePluginRouter: function(pluginName, location, action) { var pluginLocation = pluginName; if (location) { pluginLocation = pluginLocation + '-' +location; if (action) { pluginLocation = pluginLocation + '-' + action; } } this.updateLocation(pluginLocation); Adapt.trigger('router:plugin:' + pluginName, pluginName, location, action); Adapt.trigger('router:plugin', pluginName, location, action); },
function success(result) { if ('undefined' === typeof result || 404 === result.status) { Adapt.trigger('xapi:loadStateFailed'); return; } try { self.set('state', JSON.parse(result.response.toString)); self.trigger('xapi:stateLoaded'); } catch (ex) { Adapt.trigger('xapi:loadStateFailed'); } }
showFeedback: function() { if(this.model.get('_selectable') === 1) { if(this.getOptionSpecificFeedback()) { this.model.set('feedbackMessage', this.getOptionSpecificFeedback()); } } if (this.model.get('_canShowFeedback')) { Adapt.trigger('questionView:showFeedback', this); } else { Adapt.trigger('questionView:disabledFeedback', this); } },
toggleLock: function(bool) { if (this.model.get("_isLocked") === bool) return; switch(this.model.get("_strickle")._buttonType) { case "jump-lock": bool = true; } if (bool) { this.$el.find('.component-inner').addClass("locked"); this.model.set("_isLocked", true); Adapt.trigger("strickle-button:locked", this); } else { this.$el.find('.component-inner').removeClass("locked"); this.model.set("_isLocked", false); Adapt.trigger("strickle-button:unlocked", this); } },
hideDrawer: function() { Adapt.trigger('popup:closed'); var showEasingAnimation = Adapt.config.get('_drawer')._hideEasing; var easing = (showEasingAnimation) ? showEasingAnimation : 'easeOutQuart'; var duration = Adapt.config.get('_drawer')._duration; duration = (duration) ? duration : 400; this.$el.velocity({'right': -this.$el.width()}, this.drawerDuration, easing); $('.page, .menu').css({opacity:1}); this._isCustomViewVisible = false; this.removeBodyEvent(); Adapt.trigger('drawer:closed'); },
revealArticle: function(event) { if (event) event.preventDefault(); if(this.$el.closest(".article").hasClass("locked")) return; // in conjunction with pageLocking // Change text this.$('.article-body-inner').html(this.model.get('_articleReveal').bodyClose).a11y_text(); this.$('.article-instruction-inner').html(this.model.get('_articleReveal').instructionClose).a11y_text(); //set article visited and article showing in css this.$(".article-reveal-open-button").addClass('visited'); this.$(".article-reveal-open-button").addClass('article-reveal-hidden'); this.$(".article-reveal-close-button").removeClass('article-reveal-hidden'); //animate reveal Adapt.trigger("article:revealing", this); this.$el.siblings(".article-inner").velocity("slideDown", 800, _.bind(function() { Adapt.trigger("article:revealed", this); // Call window resize to force components to rerender - // fixes components that depend on being visible for setting up layout $(window).resize(); }, this)); this.$el.velocity("scroll", { delay: 400, duration: 800, offset: this.$el.height() - $(".navigation").outerHeight() }); //set components to isVisible true this.toggleisVisible(true); },
function complete() { this.addShadowEvent(); Adapt.trigger('drawer:opened'); //focus on first tabbable element in drawer this.$el.a11y_focus(); }
closePopup: function (event) { event.preventDefault(); this.$('.textPlus-popup-close').blur(); this.$('.textPlus-popup-content').addClass('textPlus-hidden'); this.$('.textPlus-popup').addClass('textPlus-hidden'); Adapt.trigger('popup:closed'); },
setCustomView: function(bottomnavigationView) { bottomnavigationView.undelegateEvents(); Adapt.trigger("bottomnavigation:setCustomView", bottomnavigationView); this.view = bottomnavigationView; this.$el.html("").append(this.view.$el); bottomnavigationView.delegateEvents(); },
complete: function() { view.$el.css("display","none"); rollay.$el.html("").append( view.$el ); view.$el.fadeIn(); view.delegateEvents(); Adapt.trigger("rollay:setCustomView", view); },
setCustomView: function(view) { if (view === rollay.model.get("_customView")) return; view.undelegateEvents(); rollay.model.set("_customView", view); if (visibility.hidden) { view.$el.css("display",""); rollay.$el.html("").append( view.$el ); view.delegateEvents(); Adapt.trigger("rollay:setCustomView", view); } else { rollay.$el.children().fadeOut({ complete: function() { view.$el.css("display","none"); rollay.$el.html("").append( view.$el ); view.$el.fadeIn(); view.delegateEvents(); Adapt.trigger("rollay:setCustomView", view); }, duration: 200 }); } },
renderItems: function() { Adapt.trigger('drawer:empty'); this.emptyDrawer(); this.collection.each(function(item) { new DrawerItemView({model: item}); }); },
_.defer(_.bind(function() { $('.loading').hide(); $(window).scrollTop(0); Adapt.trigger('menuView:ready', this); this.$el.velocity({'opacity': 1}, 'fast'); $(window).scroll(); }, this));
currentItemInView: function(model) { var $currentItemInView = $(".menu-item-" + model.get("_id")); $(".menu-item").removeClass("inview"); $currentItemInView.addClass("inview"); //AA $(".menu-item").find(".menu-item-route").attr('tabindex', -1); $(".menu-item").find(".menu-item-title-inner").a11y_on(false); $(".menu-item").find(".menu-item-body-inner").a11y_on(false); $(".menu-item").find(".menu-item-duration-inner").a11y_on(false); $(".menu-item").find(".page-level-progress-menu-item-indicator-bar .aria-label").attr('tabindex', -1); $currentItemInView.find(".menu-item-route").attr('tabindex', 0); $currentItemInView.find(".menu-item-title-inner").a11y_on(true); $currentItemInView.find(".menu-item-body-inner").a11y_on(true); $currentItemInView.find(".menu-item-duration-inner").a11y_on(true); $currentItemInView.find(".page-level-progress-menu-item-indicator-bar .aria-label").attr('tabindex', 0); if (!Adapt.audio) return; if (model.get('_coverMenuAudio') && model.get('_coverMenuAudio')._audio && model.get('_coverMenuAudio')._audio._isEnabled && model.get('_coverMenuAudio')._audio._autoplay) { thisAudio = model.get('_coverMenuAudio')._audio; if(Adapt.audio.audioClip[thisAudio._channel].status == 1) { Adapt.trigger('audio:playAudio', thisAudio._media.src, model.get('_id'), thisAudio._channel); } } }