diff options
author | Jochen Topf <jochen@topf.org> | 2014-05-16 20:08:00 +0200 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2014-05-16 20:08:00 +0200 |
commit | 19ec1d7e4325df4b802acf1c0b57f6e447601b92 (patch) | |
tree | 809dd6b12c85fec398f0e04785370c002675b73a /web/public/js/taginfo.js | |
parent | b086da01dccf250ff0ae79a2c309d376c2ba81e5 (diff) | |
download | taginfo-19ec1d7e4325df4b802acf1c0b57f6e447601b92.tar taginfo-19ec1d7e4325df4b802acf1c0b57f6e447601b92.tar.gz |
Add cookie-base comparison list.
Diffstat (limited to 'web/public/js/taginfo.js')
-rw-r--r-- | web/public/js/taginfo.js | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js index 47d949e..abb8589 100644 --- a/web/public/js/taginfo.js +++ b/web/public/js/taginfo.js @@ -443,7 +443,6 @@ function create_flexigrid(domid, options) { }); jQuery('div.bDiv:visible').bind('click', function(event) { var row = jQuery(event.target).parents('tr'); - console.log("click", row); jQuery('div.bDiv:visible tr').removeClass('trOver'); jQuery(row).addClass('trOver'); }); @@ -583,6 +582,71 @@ function open_help() { /* ============================ */ +function get_comparison_list() { + return jQuery.cookie('taginfo_comparison_list') || []; +} + +function set_comparison_list(list) { + jQuery.cookie('taginfo_comparison_list', list, { expires: 1, path: '/' }); +} + +function comparison_list_update() { + var cl = jQuery('#list option:first').html(); + cl = cl.replace(/([0-9]+)/, String(get_comparison_list().length)); + jQuery('#list option:first').html(cl); + jQuery('#list').val('title').change(); +} + +function comparison_list_item_clean(text) { + return text === null || text.match(/^[a-zA-Z:_]+$/) !== null; +} + +function comparison_list_url(list) { + var okay = true; + jQuery.each(list, function(index, item) { + if (!comparison_list_item_clean(item[0]) || + !comparison_list_item_clean(item[1])) { + okay = false; + } + }); + + if (okay) { + return '/comparison/' + jQuery.map(list, function(item, i) { + return item[0] + (item[1] === null ? '' : ('=' + item[1])); + }).join('/'); + } else { + var keys = []; + var values = []; + jQuery.each(list, function(index, item) { + keys.push(item[0]); + values.push(item[1] === null ? '' : item[1]); + }); + return '/comparison/?' + jQuery.param({ 'key': keys, 'value': values }); + } +} + +function comparison_list_change(key, value) { + var list = get_comparison_list(), + command = jQuery('#list').val(); + + if (command == 'title') { + return true; + } else if (command == 'add') { + list.push([key, value]); + set_comparison_list(list); + } else if (command == 'clear') { + set_comparison_list([]); + } else if (command == 'compare') { + window.location = comparison_list_url(list); + } + + comparison_list_update(); + return false; +} + + +/* ============================ */ + jQuery(document).ready(function() { jQuery('#javascriptmsg').remove(); |