Last change
on this file since 256 was
256,
checked in by hendrikvanantwerpen, 13 years ago
|
Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).
|
File size:
1.3 KB
|
Line | |
---|
1 | define(['dojo/_base/connect','dojo/_base/xhr','dojo/_base/Deferred','dojo/hash'],function(connect,xhr,Deferred,hash){ |
---|
2 | return new (function() { |
---|
3 | var self = this; |
---|
4 | var current = ""; |
---|
5 | |
---|
6 | function init() { |
---|
7 | connect.subscribe('/dojo/hashchange', function(){ |
---|
8 | var url = hash(); |
---|
9 | self.goTo(url); |
---|
10 | }); |
---|
11 | } |
---|
12 | |
---|
13 | self.initial = function(location) { |
---|
14 | if ( current ) { |
---|
15 | self.goTo(location); |
---|
16 | } |
---|
17 | var url = hash(); |
---|
18 | self.goTo(url || location); |
---|
19 | } |
---|
20 | |
---|
21 | self.goTo = function(location) { |
---|
22 | var contentPane = dijit.byId('content'); |
---|
23 | var d = new Deferred(); |
---|
24 | if ( current == location ) { |
---|
25 | d.resolve(); |
---|
26 | return d.promise; |
---|
27 | } |
---|
28 | |
---|
29 | current = location; |
---|
30 | hash(location); |
---|
31 | xhr.get({ |
---|
32 | url: 'pages/'+location+'/'+location+'.html' |
---|
33 | }) |
---|
34 | .then(function(content){ |
---|
35 | contentPane.set('content',content); |
---|
36 | d.resolve(); |
---|
37 | },function(){ |
---|
38 | contentPane.set('content',"Page "+location+" not found."); |
---|
39 | d.reject(); |
---|
40 | }); |
---|
41 | return d.promise; |
---|
42 | } |
---|
43 | |
---|
44 | init(); |
---|
45 | })(); |
---|
46 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.