535749c8440e62d4495b920376e4bc0125255af8
[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                 if (this.perspective_id) {
16                         document.location.hash = '#' + this.perspective_id;
17                 }
18                          
19                 console.log(document.location.hash);
20         };
21         
22         $.wiki.Perspective.prototype.onExit = function () {
23                 // called when user switches to another perspective 
24         };       
25         
26         $.wiki.Perspective.prototype.freezeState = function () {
27                 // free UI state (don't store data here)
28         };
29         
30         $.wiki.Perspective.prototype.unfreezeState = function (frozenState) {
31                 // restore UI state
32         };
33         
34         $.wiki.renderStub = function($container, $stub, data) 
35         {
36                 var $elem = $stub.clone();
37                 $elem.removeClass('row-stub');
38                 $container.append($elem);
39         
40                 $('*[data-stub-value]', $elem).each(function() {
41                         var $this = $(this);
42                         var field = $this.attr('data-stub-value');
43                         var value = data[field];
44                 
45                         if(value === null || value === undefined) return;
46                          
47                         if(!$this.attr('data-stub-target')) {
48                                 $this.text(value);                      
49                         }               
50                         else {
51                                 $this.attr($this.attr('data-stub-target'), value);
52                                 $this.removeAttr('data-stub-target');
53                                 $this.removeAttr('data-stub-value');                    
54                         }               
55                 });
56         
57                 $elem.show();
58                 return $elem;                                           
59         };
60                 
61 })(jQuery);