tutorial button
[redakcja.git] / redakcja / static / js / catalogue / catalogue.js
1 (function($) {
2     $(function() {
3
4
5         $('.filter').change(function() {
6             document.filter[this.name].value = this.value;
7             document.filter.submit();
8         });
9
10         $('.check-filter').change(function() {
11             document.filter[this.name].value = this.checked ? '1' : '';
12             document.filter.submit();
13         });
14
15         $('.text-filter').each(function() {
16             var inp = this;
17             $(inp).parent().submit(function() {
18                 document.filter[inp.name].value = inp.value;
19                 document.filter.submit();
20                 return false;
21             });
22         });
23
24
25         $('.autoslug-source').change(function() {
26             $('.autoslug').attr('value', slugify(this.value));
27         });
28
29
30         var nowTemp = new Date();
31         var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
32
33         $('.datepicker-field').each(function() {
34             var checkout = $(this).datepicker({
35                 format: 'yyyy-mm-dd',
36                 weekStart: 1,
37                 onRender: function(date) {
38                     return date.valueOf() < now.valueOf() ? 'disabled' : '';
39                 },
40             }).on('changeDate', function(ev) {
41                 checkout.hide();
42             }).data('datepicker');
43         });
44
45
46         $("select").change(function() {
47             var helpdiv = $(this).next();
48             if (helpdiv.hasClass('help-text')) {
49                 var helptext = $("option:selected", this).attr('data-help');
50                 helpdiv.html($("option:selected", this).attr('data-help') || '');
51             }
52         });
53
54
55
56         // tutorial mode
57         var tutorial;
58         var start;
59
60         var first_reset = true;
61         function tutreset() {
62             if (start) $(start).popover('hide');
63             start = null;
64             var all_tutorial = $('[data-toggle="tutorial"]');
65
66             function sortKey(a) {
67                 return parseInt($(a).attr('data-tutorial'));
68             }
69             tutorial = $.makeArray(all_tutorial.sort(
70                 function(a, b) {return sortKey(a) < sortKey(b) ? -1 : 1}
71             ));
72
73             console.log($(tutorial[0]).data('popover'));
74             console.log($(tutorial[16]).data('popover'));
75             if (first_reset) {
76                 $.each(tutorial, function(i, e) {
77                     var but = (i < tutorial.length - 1) ? '>>' : 'OK';
78                     $(e).popover({
79                         title: '<a class="btn btn-default tutorial-off" href="#-" id="tutoff'+i+'" style="float:right; padding:0 8px 4px 8px; position:relative; top:-6px; right:-10px;">&times;</a>Tutorial',
80                         trigger: 'focus',
81                         html: 'true',
82                         template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div><div><a style="float:right" class="btn btn-default tutorial-next" href="#-" id="nt'+i+'">' + but + '</a></div></div>'
83                     });
84                 });
85                 first_reset = false;
86             } else {
87                 all_tutorial.popover('enable');
88             }
89         }
90         
91         function tuton() {
92             sessionStorage.setItem("tutorial", "on");
93             tutreset();
94             var $tutModal = $('#tutModal');
95             if($tutModal.length === 0) {
96                 tut();
97             } else {
98                 $tutModal.modal('show');
99             }
100             return false;
101         }
102         function tutoff() {
103             $(this).popover('hide');
104             if (start) $(start).popover('hide');
105             start = null;
106             sessionStorage.removeItem("tutorial");
107             $('[data-toggle="tutorial"]').popover('disable');
108             return false;
109         }
110         function tut() {
111             if (start) {
112                 $(start).popover('hide').popover('disable');
113             }
114             if (tutorial.length) {
115                 start = tutorial.shift();
116                 $(start).popover('show');
117             }
118             else {
119                 start = null;
120             }
121             return false;
122         }
123         $('#tutModal').on('hidden.bs.modal', tut);
124
125         if (sessionStorage.getItem("tutorial") == "on" && $('#tuton').length == 0) {
126             tutreset();
127             tut();
128         }
129         $(document).on('click', '#tuton', tuton);
130         $(document).on('click', '.tutorial-off', tutoff);
131         $(document).on('click', '.tutorial-next', tut);
132     });
133 })(jQuery);
134