From 30d81a47c689e1d7d963fcd3fd42af9958805e31 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 22 Jan 2016 13:45:10 +0100 Subject: Move public assets for themes So they can be installed using the `assets:install` command and there'll no longer symlink in the repo They moved from `web/themes/...` to `bundles/wallabagcore/themes/...` --- .../Resources/public/themes/baggy/js/autoClose.js | 6 ++ .../public/themes/baggy/js/autoCompleteTags.js | 47 +++++++++ .../public/themes/baggy/js/closeMessage.js | 17 ++++ .../Resources/public/themes/baggy/js/init.js | 51 ++++++++++ .../Resources/public/themes/baggy/js/popupForm.js | 83 ++++++++++++++++ .../public/themes/baggy/js/restoreScroll.js | 25 +++++ .../Resources/public/themes/baggy/js/saveLink.js | 109 +++++++++++++++++++++ 7 files changed, 338 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/autoClose.js create mode 100755 src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/autoCompleteTags.js create mode 100644 src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/closeMessage.js create mode 100755 src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/init.js create mode 100644 src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/popupForm.js create mode 100644 src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/restoreScroll.js create mode 100755 src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/saveLink.js (limited to 'src/Wallabag/CoreBundle/Resources/public/themes/baggy/js') diff --git a/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/autoClose.js b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/autoClose.js new file mode 100644 index 00000000..e9145b7e --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/autoClose.js @@ -0,0 +1,6 @@ +$(document).ready(function() { + current_url = window.location.href + if (current_url.match("&closewin=true")) { + window.close(); + } +}); diff --git a/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/autoCompleteTags.js b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/autoCompleteTags.js new file mode 100755 index 00000000..90bc982c --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/autoCompleteTags.js @@ -0,0 +1,47 @@ +jQuery(function($) { + + function split( val ) { + return val.split( /,\s*/ ); + } + function extractLast( term ) { + return split( term ).pop(); + } + + + $("#value").bind("keydown", function(event) { + if (event.keyCode === $.ui.keyCode.TAB && $(this).data("ui-autocomplete").menu.active) { + event.preventDefault(); + } + }).autocomplete({ + source : function(request, response) { + $.getJSON("./?view=tags", { + term : extractLast(request.term), + //id: $(':hidden#entry_id').val() + }, response); + }, + search : function() { + // custom minLength + var term = extractLast(this.value); + if (term.length < 1) { + return false; + } + }, + focus : function() { + // prevent value inserted on focus + return false; + }, + select : function(event, ui) { + var terms = split(this.value); + // remove the current input + terms.pop(); + // add the selected item + terms.push(ui.item.value); + // add placeholder to get the comma-and-space at the end + terms.push(""); + this.value = terms.join(", "); + return false; + } + }); + + +}); diff --git a/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/closeMessage.js b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/closeMessage.js new file mode 100644 index 00000000..527719d5 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/closeMessage.js @@ -0,0 +1,17 @@ +$(function(){ + //--------------------------------------------------------------------------- + // Show the close icon when the user hover over a message + //--------------------------------------------------------------------------- + // $('.messages').on('mouseenter', function(){ + // $(this).find('a.closeMessage').stop(true, true).show(); + // }).on('mouseleave', function(){ + // $(this).find('a.closeMessage').stop(true, true).hide(); + // }); + //--------------------------------------------------------------------------- + // Close the message box when the user clicks the close icon + //--------------------------------------------------------------------------- + $('a.closeMessage').on('click', function(){ + $(this).parents('div.messages').slideUp(300, function(){ $(this).remove(); }); + return false; + }); +}); \ No newline at end of file diff --git a/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/init.js b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/init.js new file mode 100755 index 00000000..74cbae68 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/init.js @@ -0,0 +1,51 @@ +$.fn.ready(function() { + + var $listmode = $('#listmode'), + $listentries = $("#list-entries"); + + /* ========================================================================== + Menu + ========================================================================== */ + + $("#menu").click(function(){ + $("#links").toggleClass('menu--open'); + if ($('#content').hasClass('opacity03')) { + $('#content').removeClass('opacity03'); + } + }); + + /* ========================================================================== + List mode or Table Mode + ========================================================================== */ + + $listmode.click(function(){ + if ( $.cookie("listmode") == 1 ) { + // Cookie + $.removeCookie("listmode"); + + $listentries.removeClass("listmode"); + $listmode.removeClass("tablemode"); + $listmode.addClass("listmode"); + } + else { + // Cookie + $.cookie("listmode", 1, {expires: 365}); + + $listentries.addClass("listmode"); + $listmode.removeClass("listmode"); + $listmode.addClass("tablemode"); + } + + }); + + /* ========================================================================== + Cookie listmode + ========================================================================== */ + + if ( $.cookie("listmode") == 1 ) { + $listentries.addClass("listmode"); + $listmode.removeClass("listmode"); + $listmode.addClass("tablemode"); + } + +}); diff --git a/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/popupForm.js b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/popupForm.js new file mode 100644 index 00000000..b933acd1 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/popupForm.js @@ -0,0 +1,83 @@ +$(document).ready(function() { + + $("#search-form").hide(); + $("#bagit-form").hide(); + $("#filter-form").hide(); + + //--------------------------------------------------------------------------- + // Toggle the "Search" popup in the sidebar + //--------------------------------------------------------------------------- + function toggleSearch() { + $("#search-form").toggle(); + $("#search").toggleClass("current"); + $("#search").toggleClass("active-current"); + $("#search-arrow").toggleClass("arrow-down"); + if ($("#search").hasClass("current")) { + $("#content").addClass("opacity03"); + } else { + $("#content").removeClass("opacity03"); + } + } + + //--------------------------------------------------------------------------- + // Toggle the "Filter" popup on entries list + //--------------------------------------------------------------------------- + function toggleFilter() { + $("#filter-form").toggle(); + } + + //--------------------------------------------------------------------------- + // Toggle the "Save a Link" popup in the sidebar + //--------------------------------------------------------------------------- + function toggleBagit() { + $("#bagit-form").toggle(); + $("#bagit").toggleClass("current"); + $("#bagit").toggleClass("active-current"); + $("#bagit-arrow").toggleClass("arrow-down"); + if ($("#bagit").hasClass("current")) { + $("#content").addClass("opacity03"); + } else { + $("#content").removeClass("opacity03"); + } + } + + //--------------------------------------------------------------------------- + // Close all #links popups in the sidebar + //--------------------------------------------------------------------------- + function closePopups() { + $("#links .messages").hide(); + $("#links > li > a").removeClass("active-current"); + $("#links > li > a").removeClass("current"); + $("[id$=-arrow]").removeClass("arrow-down"); + $("#content").removeClass("opacity03"); + } + + $("#search").click(function(){ + closePopups(); + toggleSearch(); + $("#searchfield").focus(); + }); + + $("#filter").click(function(){ + closePopups(); + toggleFilter(); + }); + + $("#bagit").click(function(){ + closePopups(); + toggleBagit(); + $("#plainurl").focus(); + }); + + $("#search-form-close").click(function(){ + toggleSearch(); + }); + + $("#filter-form-close").click(function(){ + toggleFilter(); + }); + + $("#bagit-form-close").click(function(){ + toggleBagit(); + }); +}); diff --git a/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/restoreScroll.js b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/restoreScroll.js new file mode 100644 index 00000000..331c9e19 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/restoreScroll.js @@ -0,0 +1,25 @@ +function supportsLocalStorage() { + try { + return 'localStorage' in window && window['localStorage'] !== null; + } catch (e) { + return false; + } +} + +function savePercent(id, percent) { + if (!supportsLocalStorage()) { return false; } + localStorage["poche.article." + id + ".percent"] = percent; + return true; +} + +function retrievePercent(id) { + if (!supportsLocalStorage()) { return false; } + + var bheight = $(document).height(); + var percent = localStorage["poche.article." + id + ".percent"]; + var scroll = bheight * percent; + + $('html,body').animate({scrollTop: scroll}, 'fast'); + + return true; +} \ No newline at end of file diff --git a/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/saveLink.js b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/saveLink.js new file mode 100755 index 00000000..a7acd84c --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/saveLink.js @@ -0,0 +1,109 @@ +$.fn.ready(function() { + + var $bagit = $('#bagit'), + $bagitForm = $('#bagit-form'), + $bagitFormForm = $('#bagit-form-form'); + + /* ========================================================================== + bag it link and close button + ========================================================================== */ + + function toggleSaveLinkForm(url, event) { + $("#add-link-result").empty(); + + $bagit.toggleClass("active-current"); + + //only if bag-it link is not presented on page + if ( $bagit.length === 0 ) { + if ( event !== 'undefined' && event ) { + $bagitForm.css( {position:"absolute", top:event.pageY, left:event.pageX-200}); + } + else { + $bagitForm.css( {position:"relative", top:"auto", left:"auto"}); + } + } + + if ($("#search-form").length != 0) { + $("#search").removeClass("current"); + $("#search-arrow").removeClass("arrow-down"); + $("#search-form").hide(); + } + $bagitForm.toggle(); + $('#content').toggleClass("opacity03"); + if (url !== 'undefined' && url) { + $('#plainurl').val(url); + } + $('#plainurl').focus(); + } + + //--------------------------------------------------------------------------- + // These two functions are now taken care of in popupForm.js + //--------------------------------------------------------------------------- + + // $bagit.click(function(){ + // $bagit.toggleClass("current"); + // $("#bagit-arrow").toggleClass("arrow-down"); + // toggleSaveLinkForm(); + // }); + + // $("#bagit-form-close").click(function(){ + // $bagit.removeClass("current"); + // $("#bagit-arrow").removeClass("arrow-down"); + // toggleSaveLinkForm(); + // }); + + + //send "bag it link" form request via ajax + $bagitFormForm.submit( function(event) { + $("body").css("cursor", "wait"); + $("#add-link-result").empty(); + + $.ajax({ + type: $bagitFormForm.attr('method'), + url: $bagitFormForm.attr('action'), + data: $bagitFormForm.serialize(), + success: function(data) { + $('#add-link-result').html("Done!"); + $('#plainurl').val(''); + $('#plainurl').blur(''); + $("body").css("cursor", "auto"); + //setTimeout( function() { toggleSaveLinkForm(); }, 1000); //close form after 1000 delay + }, + error: function(data) { + $('#add-link-result').html("Failed!"); + $("body").css("cursor", "auto"); + } + }); + + event.preventDefault(); + }); + + /* ========================================================================== + Keyboard gestion + ========================================================================== */ + + $(window).keydown(function(e){ + if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || (e.keyCode == 27 && $bagitForm.is(':visible') ) ) { + $bagit.removeClass("current"); + $("#bagit-arrow").removeClass("arrow-down"); + toggleSaveLinkForm(); + return false; + } + }); + + /* ========================================================================== + Process all links inside an article + ========================================================================== */ + + $("article a[href^='http']").after(function() { + return " "; + }); + + $(".add-to-wallabag-link-after").click(function(event){ + toggleSaveLinkForm($(this).attr('href'), event); + event.preventDefault(); + }); + +}); + + -- cgit v1.2.3