Mostly Javascript refactoring.
[redakcja.git] / platforma / static / js / wiki / base.js
1 (function($) 
2 {       
3         $.wiki = {};
4         
5         $.wiki.Perspective = function(document, callback) {
6                 // initialization
7         };
8         
9         $.wiki.Perspective.toString = function() {
10                 return this.perspective_id;
11         }
12         
13         $.wiki.Perspective.prototype.onEnter = function () {
14                 // called when perspective in initialized
15                 document.location.hash = '#' + this.perspective_id; 
16                 console.log(document.location.hash);
17         };
18         
19         $.wiki.Perspective.prototype.onExit = function () {
20                 // called when user switches to another perspective 
21         };       
22         
23         $.wiki.Perspective.prototype.freezeState = function () {
24                 // free UI state (don't store data here)
25         };
26         
27         $.wiki.Perspective.prototype.unfreezeState = function (frozenState) {
28                 // restore UI state
29         };
30         
31         $.wiki.renderStub = function($container, $stub, data) 
32         {
33                 var $elem = $stub.clone();
34                 $elem.removeClass('row-stub');
35                 $container.append($elem);
36         
37                 $('*[data-stub-value]', $elem).each(function() {
38                         var $this = $(this);
39                         var field = $this.attr('data-stub-value');
40                         var value = data[field];
41                 
42                         if(value === null || value === undefined) return;
43                          
44                         if(!$this.attr('data-stub-target')) {
45                                 $this.text(value);                      
46                         }               
47                         else {
48                                 $this.attr($this.attr('data-stub-target'), value);
49                                 $this.removeAttr('data-stub-target');
50                                 $this.removeAttr('data-stub-value');                    
51                         }               
52                 });
53         
54                 $elem.show();
55                 return $elem;                                           
56         };
57                 
58 })(jQuery);