Stats for audiobooks
[wolnelektury.git] / src / wolnelektury / static / js / base.js
index adc340b..8f26db4 100644 (file)
             })
         });
 
+        $('.more-expand').each(function () {
+            $(this).shorten({
+                showChars: 150,
+                moreText: "wiÄ™cej",
+                lessText: "mniej"
+            });
+        });
+
+
+        $('.carousel').on('cycle-before', function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
+            $("iframe", outgoingSlideEl).attr("src", '');
+            $("iframe", incomingSlideEl).attr("src", $("iframe", incomingSlideEl).attr('data-src'));
+        });
+        $('.carousel section').first().each(function() {
+            $("iframe", this).attr("src", $("iframe", this).attr('data-src'));
+        });
+
+        $(".carousel").each(function() {
+            opts = {};
+            if ($('html').hasClass('media-eink')) {
+                opts.fx = 'none'
+            }
+            $(this).cycle(opts);
+        });
 
 
         (function() {
         });
 
         $('.hoverclick').click(function() {$(this).closest('.hoverget').toggleClass('hover');});
+        $('.hoverclick').keydown(function(event){ 
+            var keyCode = (event.keyCode ? event.keyCode : event.which);   
+            if (keyCode == 13) {
+                $(this).trigger('click');
+            }
+        });
 
         $(function(){
             $("#search").search();
         tlite(function (el) {
             return $(el).hasClass('tlite-tooltip');
         });
+
+        /* more/less switch from https://codepen.io/JoshBlackwood/pen/pEwHe */
+        // Hide the extra content initially, using JS so that if JS is disabled, no problemo:
+        $('.read-more-content').addClass('hide');
+        $('.read-more-show, .read-more-hide').removeClass('hide');
+
+        // Set up the toggle effect:
+        $('.read-more-show').on('click', function(e) {
+          $(this).next('.read-more-content').removeClass('hide');
+          $(this).addClass('hide');
+          e.preventDefault();
+        });
+
+        // Changes contributed by @diego-rzg
+        $('.read-more-hide').on('click', function(e) {
+          var p = $(this).parent('.read-more-content');
+          p.addClass('hide');
+          p.prev('.read-more-show').removeClass('hide'); // Hide only the preceding "Read More"
+          e.preventDefault();
+        });
+
+
+        function update_info() {
+            var amount = parseInt($("#id_amount").val());
+            var monthly =  $("#id_monthly").val() == 'True';
+            if (monthly) slug = "monthly";
+            else if (amount >= parseInt($("#plan-single").attr('data-min-for-year'))) slug = 'single-year';
+            else slug = 'single';
+
+            var chunk = $('.club-form-info .chunk-' + slug);
+            if (chunk.css('display') == 'none') {
+                $('.chunk-alt').css('height', $('.chunk-alt').height());
+                $('.chunk-alt .chunk').css('position', 'absolute');
+
+                $('.club-form-info .chunk').fadeOut();
+                $('.club-form-info .chunk.chunk-' + slug).fadeIn(function() {
+                    $('.chunk-alt .chunk').css('position', 'static');
+                    $('.chunk-alt').css('height', 'auto');
+                });
+                $('.chunk-alt').animate({height: chunk.height()}, 100);
+            }
+        }
+        
+        $("#id_amount").val($("#plan-monthly").attr('data-amount'));
+        
+        $(".button.kwota").click(function() {
+            var plan = $(this).closest('.plan');
+            $('.kwota', plan).removeClass('active')
+            $('.inna', plan).removeClass('active')
+            $(this).addClass('active');
+
+            var amount = $(this).text();
+            plan.attr("data-amount", amount);
+            $("#id_amount").val(amount);
+
+            update_info();
+            return false;
+        });
+
+        $(".plan-toggle").click(function() {
+            $(".plan-toggle").removeClass('active');
+            $(this).addClass('active')
+            $(".plan").hide();
+            var plan = $("#" + $(this).attr('data-plan'));
+            plan.show();
+            $("#id_amount").val(plan.attr('data-amount'));
+            $("#id_monthly").val(plan.attr('data-monthly'));
+
+            update_info();
+            return false;
+        });
+
+        $(".inna .button").click(function() {
+            var plan = $(this).closest('.plan');
+            $('.kwota', plan).removeClass('active');
+            $(this).parent().addClass('active');
+            $('input', plan).focus();
+
+            var amount = $('input', $(this).parent()).val();
+            plan.attr("data-amount", amount);
+            $("#id_amount").val(amount);
+
+            update_info();
+            return false;
+        });
+        
+        $(".inna input").on('input', function() {
+            var plan = $(this).closest('.plan');
+            $('.kwota', plan).removeClass('active');
+            var amount = $(this).val();
+            plan.attr("data-amount", amount);
+            $("#id_amount").val(amount);
+
+            update_info();
+            return false;
+        });
+
+        $("#id_method").val('payu-re');
+        $(".methods .button").click(function() {
+            $("#id_method").val($(this).attr('data-method'));
+            $(".methods .button").removeClass('active');
+            $(this).addClass("active");
+        });
+
+
+        $("#skiplink-search").click(function() {
+            console.log('skiplink search');
+            $("#search").focus();
+            return false;
+        });
+        
     });
 })(jQuery);