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;
				}
			}
		}
	}
Пример #2
0
		checkVisibility:function(id) {
			var model = Adapt.findById(id);
			if ($('.'+id).is(':visible') || model == Adapt.course) return;

			while (!$('.'+id).is(':visible') && model != Adapt.course) {
				model = model.getParent();
				id = model.get('_id');
			}
			console.log('adapt-devtools::checkVisibility scrolling to ancestor '+id);
			Adapt.scrollTo($('.'+id));
		}
Пример #3
0
		navigateAndDisableTrickle:function(id) {
			var model = Adapt.findById(id);
			var pageModel = Adapt.findById(Adapt.location._currentId);

			// first ensure page incomplete prompt won't activate
			this._disablePageIncompletePrompt(pageModel);

			if (model._siblings == 'contentObjects') {
				Backbone.history.navigate("#/id/"+id, {trigger:true});
			}
			else {
				// if already on page ensure trickle is disabled
				if (Adapt.location._currentId == model.findAncestor('contentObjects').get('_id')) {
					Adapt.devtools.set('_trickleEnabled', false);
					Adapt.scrollTo($('.'+id));
					this.checkVisibility(id);
				}
				else {
					// pick target model to determine trickle config according to trickle version (2.1 or 2.0.x)
					var targetModel = Adapt.trickle ? model.findAncestor('contentObjects') : Adapt.course;
					
					// if necessary disable trickle (until page is ready)
					if (!targetModel.has('_trickle')) {
						targetModel.set('_trickle', {_isEnabled:false});
						this.listenToOnce(Adapt, 'pageView:ready', function() {
							_.defer(_.bind(function() {
								targetModel.get('_trickle')._isEnabled = true;
								this.checkVisibility(id);
							}, this));
						});
					}
					else if (targetModel.get('_trickle')._isEnabled) {
						targetModel.get('_trickle')._isEnabled = false;
						this.listenToOnce(Adapt, 'pageView:ready', function() {
							_.defer(_.bind(function() {
								targetModel.get('_trickle')._isEnabled = true;
								this.checkVisibility(id);
							}, this));
						});
					}

					Backbone.history.navigate("#/id/"+id, {trigger:true});
				}
			}

			// restore pageIncompletePrompt config
			this._restorePageIncompletePrompt(pageModel);

			this.invalidate();
		},
Пример #4
0
						_.defer(_.bind(function() {
							Adapt.scrollTo($('.'+id));
							this.checkVisibility(id);
						}, this));
 Adapt.once('drawer:closed', function() {
     Adapt.scrollTo($currentComponent, { duration:400 });
 });