Exemplo n.º 1
0
		History.Adapter.bind(window, 'statechange', function() {
			var State = History.getState(); 
			//History.log(State.data, State.title, State.url);

			console.log('statechange');
			console.log(State.url);
			console.log('short: ' + History.getShortUrl(State.url));
			console.log('full: ' + History.getFullUrl(State.url));
			console.log('root: ' + History.getRootUrl());
			console.log('base: ' + History.getBaseHref());
			console.log('getBaseUrl: ' + History.getBaseUrl());
			console.log('getPageUrl: ' + History.getPageUrl());
			console.log('getBasePageUrl: ' + History.getBasePageUrl());

			var full = History.getFullUrl(State.url);
			var root = History.getRootUrl();
			var loc = full.replace(root, '');
			self.gotoBranch(loc);	
		});
Exemplo n.º 2
0
	p.init = function()
	{
		var self = this;

		this.siteController.init(this.flowController.defaultFlow);

		this.siteController.on.transitionOut.add(function(step){
			var $content = self.getOutgoingContent(self.transitioningBranch);
			var sequence = self.transitionController.getTransitionSequence('out', $content, step);
			sequence.play();
		});
		this.siteController.on.transitionIn.add(function(step){
			var $content = self.getIngoingContent(self.transitioningBranch);
			var sequence = self.transitionController.getTransitionSequence('in', $content, step);
			sequence.play();
		});


		this.siteController.on.transitionCross.add(function(step){

			console.log('transitionCross');

			var $contentOut = self.getOutgoingContent(self.transitioningBranch);
			var $contentIn = self.getIngoingContent(self.transitioningBranch);

			var sequenceOut = self.transitionController.getTransitionSequence('out', $contentOut, step);
			var sequenceIn = self.transitionController.getTransitionSequence('in', $contentIn, step);

			//	self.transitionController.on.transitionIn.add(function(){
			//	});

			var sequenceOutLen = sequenceOut.getChildren(false).length - 1;
			var sequenceInLen = sequenceIn.getChildren(false).length - 1;

			//alert(sequenceOutLen + ' :: ' + sequenceInLen)

			if(sequenceOutLen > 0)
			{
				sequenceOut.play();

				var inCounterDelay = sequenceOutLen;

				if(sequenceInLen > 0)
				{
					self.transitionController.on.transitionOut.removeAll();
					self.transitionController.on.transitionOut.add(function(){
						if(--inCounterDelay == 0)
						{
							sequenceIn.play();							
						}
					});		
				}
			}
			else
			{
				if(sequenceInLen > 0)
				{
					sequenceIn.play();
				}
			}
		});
	

		this.siteController.on.preload.add(function(step){
			//console.log('preload step hold!');
			step.hold();

			//	var url = self.transitioningBranch.replace(self.siteRoot , '')

			console.log ('preload: ', self.transitioningBranch);

			var promise = self.preloadController.get(self.transitioningBranch, step);

			promise.then(function(x){
				//console.log('preload step release!');

				if (x.parent().length == 0)
				{
					self.contentRenderer.addContent(x);
				}	

				step.release();
			})
		});

		this.siteController.on.complete.add(function(){
			self.currentBranch = self.transitioningBranch;
			self.navigateTo(self.targetBranch); //
		});

			console.log('INIT: ', History.getLocationHref() );
			console.log('short: ' + History.getShortUrl(History.getLocationHref()));
			console.log('full: ' + History.getFullUrl(History.getLocationHref()));
			console.log('root: ' + History.getRootUrl());
			console.log('base: ' + History.getBaseHref());
			console.log('getBaseUrl: ' + History.getBaseUrl());
			console.log('getPageUrl: ' + History.getPageUrl());
			console.log('getBasePageUrl: ' + History.getBasePageUrl());		

			var full = History.getFullUrl(History.getLocationHref());
			var root = History.getRootUrl();

		var anchor = History.getHash(); // window.location.hash.substring(1);

		console.log('anchor: ', anchor);

		var loc = full.replace(root, ''); //root
		var siteRoot = this.siteRoot;

		var branch;

		if (History.emulated.pushState)
		{
			//HTML4
				
			//	#/one/two -> goto
			//	/one/two -> #/one/two

			if (anchor.length > 0)
			{
				console.log ("TEST: " + '/' + loc +  '  vs  ' +   siteRoot + '/' + '#' + anchor);

//    /giga/site/#/project2/pic1/  vs  /giga/site/ 

				if('/' + loc == siteRoot + '/' + '#' + anchor)
				{
					//alert('goto anchor: ' + siteRoot + '/' + anchor);
					branch = siteRoot + '/' + anchor;

					//IE < 10 will "eat" the hash if we got here via redirect!
					window.document.location.href = window.document.URL;

				}
				else
				{
					var newLoc = root.substring(0, root.length-1) + siteRoot + '#' + anchor;
					//	alert('A: window.location.href = ' + newLoc);
					window.location.href = newLoc;
					return;
				}	
			}
			else
			{
				loc = this.normalizeBranch(loc).replace(siteRoot, '');
				
				if (loc == '/')
				{
					//alert('C: goto branch ' + siteRoot + loc);
					branch = siteRoot + loc;
				}	
				else
				{
					// + '.'
					var newLoc = root.substring(0, root.length-1) + siteRoot + '#' + loc.substring(1);
					//	alert('B: window.location.href = ' + newLoc);
					window.location.href = newLoc;
					return;					
				}
			}
		}
		else
		{
			//HTML5
				
			//	#/one/two -> /one/two
			//	/one/two -> goto

			if (anchor.length > 0)
			{
				//	if(loc == '/' + siteRoot + '#' + anchor)
				//	{
				//		this.gotoBranch(anchor);
				//	}
				//	else
				//	{
					window.location.href = this.normalizeBranch(siteRoot)  + anchor;
					return;
				//	}	
			}
			else
			{
				branch = '/' + loc;
			}			
		}

		this.preloadController.init(branch);
		this.gotoBranch(branch);

			

		//this.gotoBranch(History.getShortUrl(History.getLocationHref()));


	};