dropdowns in top menu + changes in tutorial engine
[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             tutorial = $.makeArray(all_tutorial.sort(
67                 function(a, b) {return $(a).attr('data-tutorial') < $(b).attr('data-tutorial') ? -1 : 1}
68             ));
69
70             if (first_reset) {
71                 $.each(tutorial, function(i, e) {
72                     var but = (i < tutorial.length - 1) ? '>>' : 'OK';
73                     $(e).popover({
74                         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',
75                         trigger: 'focus',
76                         html: 'true',
77                         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>'
78                     });
79                 });
80                 first_reset = false;
81             } else {
82                 all_tutorial.popover('enable');
83             }
84         }
85         
86         function tuton() {
87             sessionStorage.setItem("tutorial", "on");
88             tutreset();
89             $('#tutModal').modal('show');
90             return false;
91         }
92         function tutoff() {
93             $(this).popover('hide');
94             if (start) $(start).popover('hide');
95             start = null;
96             sessionStorage.removeItem("tutorial");
97             $('[data-toggle="tutorial"]').popover('disable');
98             return false;
99         }
100         function tut() {
101             if (start) {
102                 $(start).popover('hide').popover('disable');
103             }
104             if (tutorial.length) {
105                 start = tutorial.shift();
106                 $(start).popover('show');
107             }
108             else {
109                 start = null;
110             }
111             return false;
112         }
113         $('#tutModal').on('hidden.bs.modal', tut);
114
115         var $tuton = $("#tuton");
116         if (sessionStorage.getItem("tutorial") == "on" && $tuton.length == 0) {
117             tutreset();
118             tut();
119         }
120         $tuton.on('click', tuton);
121         $(document).on('click', '.tutorial-off', tutoff);
122         $(document).on('click', '.tutorial-next', tut);
123     });
124 })(jQuery);
125