From 88ece7bc755b7b70eff207c80b3df6d979a25d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 10 Jun 2014 09:49:46 +0200 Subject: [PATCH] add linear navigation between documents (#4730) --- .../theme/diazo_resources/static/main.css | 4 ++ .../theme/diazo_resources/static/main.js | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/pfwbged/theme/diazo_resources/static/main.css b/src/pfwbged/theme/diazo_resources/static/main.css index d69d6c8..fd5f44e 100644 --- a/src/pfwbged/theme/diazo_resources/static/main.css +++ b/src/pfwbged/theme/diazo_resources/static/main.css @@ -441,6 +441,10 @@ body.portaltype-folder ul#content-views #contentview-local_roles { display: inline-block; } +ul#content-views #contentview-edit { + margin-right: 25px; +} + #edit-bar { background: transparent; border: none; diff --git a/src/pfwbged/theme/diazo_resources/static/main.js b/src/pfwbged/theme/diazo_resources/static/main.js index d4dc6d8..cff323a 100644 --- a/src/pfwbged/theme/diazo_resources/static/main.js +++ b/src/pfwbged/theme/diazo_resources/static/main.js @@ -3,6 +3,49 @@ /*jslint white:false, onevar:true, undef:true, nomen:true, eqeqeq:true, plusplus:true, bitwise:true, regexp:true, newcap:true, immed:true, strict:false, browser:true */ /*global jQuery:false, document:false, window:false, location:false */ +(function ($) { + + /* define pfwbged namespace if it doesn't exist */ + if (typeof($.pfwbged) === "undefined") { + $.pfwbged = { }; + } + + $.pfwbged.prepareLinearNavigation = function () { + /* prepare for linear navigation from document page to document page */ + var doc_links = $('.ResultsTasksTable tr a, .ResultsTable tr a').map( + function(a, b) { return $(b).attr('href'); }); + if (doc_links.length > 0) { + window.localStorage.setItem('table-documents', JSON.stringify($.makeArray(doc_links))); + window.localStorage.setItem('table-documents-url', window.location.href); + } + }; + + $.pfwbged.doLinearNavigation = function () { + var doc_links = JSON.parse(localStorage.getItem('table-documents')); + var table_url = window.localStorage.getItem('table-documents-url'); + if (typeof(doc_links) != 'object') return; + var idx = doc_links.indexOf(window.location.href); + if (idx == -1) return; + if (idx < doc_links.length-1) { + /* append a "next" link */ + var url = doc_links[idx+1]; + $('#contentview-edit').after('
  • ' + + 'Suivant
  • '); + } + if (idx > 0) { + /* append a "previous" link */ + var url = doc_links[idx-1]; + $('#contentview-edit').after('
  • ' + + 'Précédent
  • '); + } + if (table_url) { + $('#contentview-edit').after('
  • ' + + 'Tableau
  • '); + } + }; + +}(jQuery)); + /* watch version being selected, so menu entries can be shown/hidden */ $('#contentActionMenus .version-action').closest('li').hide(); $('.version-link').closest('tr').on('select-version', function() { @@ -59,4 +102,8 @@ $(function() { if (xhr_preview !== null) xhr_preview.abort(); $('#preview-doc').remove(); }); + + $.pfwbged.prepareLinearNavigation(); + $.pfwbged.doLinearNavigation(); + });