diff options
| author | 2015-11-04 20:26:30 +0100 | |
|---|---|---|
| committer | 2015-11-04 20:26:30 +0100 | |
| commit | 74639cb1535feddb808a4262e058a67d4a3aef6b (patch) | |
| tree | 78c5567578751752a3623574cbd768e602a46754 /p/scripts/main.js | |
| parent | 4c99fd689f0778cbf6a987471ebf72b3787739c2 (diff) | |
| parent | 4525e547faa8781e37f86125110f28248eb67fd3 (diff) | |
Merge branch 'dev'
Diffstat (limited to 'p/scripts/main.js')
| -rw-r--r-- | p/scripts/main.js | 64 |
1 files changed, 45 insertions, 19 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js index 1be75bb12..f64927c14 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -238,12 +238,7 @@ function toggleContent(new_active, old_active) { old_active.removeClass("active current"); new_active.addClass("current"); if (context['auto_remove_article'] && !old_active.hasClass('not_read')) { - var p = old_active.prev(); - var n = old_active.next(); - if (p.hasClass('day') && n.hasClass('day')) { - p.remove(); - } - old_active.remove(); + auto_remove(old_active); } } else { new_active.toggleClass('active'); @@ -258,7 +253,7 @@ function toggleContent(new_active, old_active) { if (context['sticky_post']) { var prev_article = new_active.prevAll('.flux'), - new_pos = new_active.position().top, + new_pos = new_active.position().top, old_scroll = $(box_to_move).scrollTop(); if (prev_article.length > 0 && new_pos - prev_article.position().top <= 150) { @@ -289,6 +284,16 @@ function toggleContent(new_active, old_active) { } } +function auto_remove(element) { + var p = element.prev(); + var n = element.next(); + if (p.hasClass('day') && n.hasClass('day')) { + p.remove(); + } + element.remove(); + $('#stream > .flux:not(.not_read):not(.active)').remove(); +} + function prev_entry() { var old_active = $(".flux.current"), new_active = old_active.length === 0 ? $(".flux:last") : old_active.prevAll(".flux:first"); @@ -683,7 +688,7 @@ function init_stream(divStream) { } var old_active = $(".flux.current"), new_active = $(this).parent(); - isCollapsed = true; + isCollapsed = true; if (e.target.tagName.toUpperCase() === 'A') { //Leave real links alone if (context['auto_mark_article']) { mark_read(new_active, true); @@ -696,12 +701,7 @@ function init_stream(divStream) { divStream.on('click', '.flux a.read', function () { var active = $(this).parents(".flux"); if (context['auto_remove_article'] && active.hasClass('not_read')) { - var p = active.prev(); - var n = active.next(); - if (p.hasClass('day') && n.hasClass('day')) { - p.remove(); - } - active.remove(); + auto_remove(active); } mark_read(active, false); return false; @@ -882,8 +882,8 @@ function notifs_html5_show(nb) { if (context['html5_notif_timeout'] !== 0){ setTimeout(function() { - notification.close(); - }, context['html5_notif_timeout'] * 1000); + notification.close(); + }, context['html5_notif_timeout'] * 1000); } } @@ -899,7 +899,7 @@ function init_notifs_html5() { function refreshUnreads() { $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) { var isAll = $('.category.all.active').length > 0, - new_articles = false; + new_articles = false; $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; @@ -1097,7 +1097,7 @@ function init_share_observers() { $('.share.add').on('click', function(e) { var opt = $(this).siblings('select').find(':selected'); var row = $(this).parents('form').data(opt.data('form')); - row = row.replace('##label##', opt.html(), 'g'); + row = row.replace('##label##', opt.html().trim(), 'g'); row = row.replace('##type##', opt.val(), 'g'); row = row.replace('##help##', opt.data('help'), 'g'); row = row.replace('##key##', shares, 'g'); @@ -1195,7 +1195,7 @@ function faviconNbUnread(n) { function init_slider_observers() { var slider = $('#slider'), - closer = $('#close-slider'); + closer = $('#close-slider'); if (slider.length < 1) { return; } @@ -1229,6 +1229,31 @@ function init_slider_observers() { }); } +function init_configuration_alert() { + $(window).on('submit', function(e) { + window.hasSubmit = true; + }); + $(window).on('beforeunload', function(e) { + if (window.hasSubmit) { + return; + } + var fields = $("[data-leave-validation]"); + for (var i = 0; i < fields.length; i++) { + if ($(fields[i]).attr('type') === 'checkbox' || $(fields[i]).attr('type') === 'radio') { + // The use of != is done on purpose to check boolean against integer + if ($(fields[i]).is(':checked') != $(fields[i]).attr('data-leave-validation')) { + return false; + } + } else { + if ($(fields[i]).attr('data-leave-validation') !== $(fields[i]).val()) { + return false; + } + } + } + return; + }); +} + function init_all() { if (!(window.$ && window.context)) { if (window.console) { @@ -1260,6 +1285,7 @@ function init_all() { init_password_observers(); init_stats_observers(); init_slider_observers(); + init_configuration_alert(); } if (window.console) { |
