Commit 840e021a authored by Grégoire Détrez's avatar Grégoire Détrez Committed by Claude Paroz

Remember "Hide completed modules"

* refactor the javascript come to use jquery
* add the module jquery.cookie.js
* stores the current state in a cookie.

https://bugzilla.gnome.org/show_bug.cgi?id=660005
parent 3f3fb3ee
/*!
* jQuery Cookie Plugin v1.4.1
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2013 Klaus Hartl
* Released under the MIT license
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
var pluses = /\+/g;
function encode(s) {
return config.raw ? s : encodeURIComponent(s);
}
function decode(s) {
return config.raw ? s : decodeURIComponent(s);
}
function stringifyCookieValue(value) {
return encode(config.json ? JSON.stringify(value) : String(value));
}
function parseCookieValue(s) {
if (s.indexOf('"') === 0) {
// This is a quoted cookie as according to RFC2068, unescape...
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}
try {
// Replace server-side written pluses with spaces.
// If we can't decode the cookie, ignore it, it's unusable.
// If we can't parse the cookie, ignore it, it's unusable.
s = decodeURIComponent(s.replace(pluses, ' '));
return config.json ? JSON.parse(s) : s;
} catch(e) {}
}
function read(s, converter) {
var value = config.raw ? s : parseCookieValue(s);
return $.isFunction(converter) ? converter(value) : value;
}
var config = $.cookie = function (key, value, options) {
// Write
if (value !== undefined && !$.isFunction(value)) {
options = $.extend({}, config.defaults, options);
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setTime(+t + days * 864e+5);
}
return (document.cookie = [
encode(key), '=', stringifyCookieValue(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}
// Read
var result = key ? undefined : {};
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling $.cookie().
var cookies = document.cookie ? document.cookie.split('; ') : [];
for (var i = 0, l = cookies.length; i < l; i++) {
var parts = cookies[i].split('=');
var name = decode(parts.shift());
var cookie = parts.join('=');
if (key && key === name) {
// If second argument (value) is a function it's a converter...
result = read(cookie, value);
break;
}
// Prevent storing a cookie that we couldn't decode.
if (!key && (cookie = read(cookie)) !== undefined) {
result[name] = cookie;
}
}
return result;
};
config.defaults = {};
$.removeCookie = function (key, options) {
if ($.cookie(key) === undefined) {
return false;
}
// Must not alter options, thus extending a fresh object...
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
return !$.cookie(key);
};
}));
......@@ -2,29 +2,30 @@
// This function shows or hides all modules in a release that are
// 100% translated
// ***
function showHideCompleted(target) {
var regex = /complete$/i;
dl = (function($, undefined){
var COOKIE = "DL_HIDE_COMPLETED_MODULES",
selector = '.completed-module';
var tbls = document.getElementsByName(target);
for (var tb=0; tb < tbls.length; tb++) {
var translations = tbls[tb].getElementsByTagName("tr");
for(var i=0;i<translations.length;i++) {
if ( regex.exec(translations[i].id) ) {
if ( translations[i].style.display != 'none' ) {
translations[i].style.display = 'none';
}
else {
translations[i].style.display = '';
}
}
}
hide = function() {
$(selector).hide();
$.cookie(COOKIE, true);
$('#show-completed-modules').show();
$('#hide-completed-modules').hide();
return false;
}
var hide = document.getElementById("hide");
var show = document.getElementById("show");
show = function() {
$(selector).show();
$.cookie(COOKIE, false);
$('#show-completed-modules').hide();
$('#hide-completed-modules').show();
return false;
}
hide.style.display = (hide.style.display != 'none' ? 'none' : '' );
show.style.display = (show.style.display != 'none' ? 'none' : '' );
return false;
}
$(function() {
if($.cookie(COOKIE) == "true")
hide();
$('#show-completed-modules').click(show);
$('#hide-completed-modules').click(hide);
});
})($);
......@@ -11,10 +11,11 @@
{% if LANGUAGE_BIDI %}
<link rel="stylesheet" href="{{ STATIC_URL }}css/rtl.css">
{% endif %}
<script type="text/javascript" src="{{ STATIC_URL }}js/main.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.tools.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.cookie.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/overlayhelpers.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/main.js"></script>
<script type="text/javascript">
$(document).ready(function () {
......
......@@ -26,13 +26,8 @@ $(document).ready(function()
{% endif %}
<div id="hide-show">
<p id="hide">
<a href="#" onclick="return showHideCompleted('stats-table');">{% trans "Hide completed modules" %}</a>
</p>
<p id="show" style="display:none">
<a href="#" onclick="return showHideCompleted('stats-table');">{% trans "Show completed modules" %}</a>
</p>
<a href="#" id="hide-completed-modules">{% trans "Hide completed modules" %}</a>
<a href="#" id="show-completed-modules" style="display: none;">{% trans "Show completed modules" %}</a>
</div>
<h3>{{ stats_title }}</h3>
......
......@@ -42,7 +42,7 @@
{% for dom in doms %}
{% with dom.0 as domname and dom.1 as stat %}
{% if stat and not stat.is_fake %}
<tr id="{{ modname }}-{{ stat.domain.id }}{% if stat.tr_percentage == 100 %}-complete{% endif %}">
<tr id="{{ modname }}-{{ stat.domain.id }}{% if stat.tr_percentage == 100 %}-complete{% endif %}" {% if stat.tr_percentage == 100 %}class="completed-module"{% endif %}>
<td class="leftcell">
{% if language and not module.archived %}
<a href="{% url 'vertimus_by_names' modname branch stat.domain.name language.locale %}">{{ stat.module_description }}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment