summaryrefslogtreecommitdiff
path: root/web/public/js
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2014-05-16 20:08:00 +0200
committerJochen Topf <jochen@topf.org>2014-05-16 20:08:00 +0200
commit19ec1d7e4325df4b802acf1c0b57f6e447601b92 (patch)
tree809dd6b12c85fec398f0e04785370c002675b73a /web/public/js
parentb086da01dccf250ff0ae79a2c309d376c2ba81e5 (diff)
downloadtaginfo-19ec1d7e4325df4b802acf1c0b57f6e447601b92.tar
taginfo-19ec1d7e4325df4b802acf1c0b57f6e447601b92.tar.gz
Add cookie-base comparison list.
Diffstat (limited to 'web/public/js')
-rw-r--r--web/public/js/jquery.cookie-minified.js8
-rw-r--r--web/public/js/jquery.cookie.js117
-rw-r--r--web/public/js/taginfo.js66
3 files changed, 190 insertions, 1 deletions
diff --git a/web/public/js/jquery.cookie-minified.js b/web/public/js/jquery.cookie-minified.js
new file mode 100644
index 0000000..b8b4c70
--- /dev/null
+++ b/web/public/js/jquery.cookie-minified.js
@@ -0,0 +1,8 @@
+/*
+ * jQuery Cookie Plugin v1.4.1
+ * https://github.com/carhartl/jquery-cookie
+ *
+ * Copyright 2013 Klaus Hartl
+ * Released under the MIT license
+ */
+(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a)}else{if(typeof exports==="object"){a(require("jquery"))}else{a(jQuery)}}}(function(f){var a=/\+/g;function d(i){return b.raw?i:encodeURIComponent(i)}function g(i){return b.raw?i:decodeURIComponent(i)}function h(i){return d(b.json?JSON.stringify(i):String(i))}function c(i){if(i.indexOf('"')===0){i=i.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{i=decodeURIComponent(i.replace(a," "));return b.json?JSON.parse(i):i}catch(j){}}function e(j,i){var k=b.raw?j:c(j);return f.isFunction(i)?i(k):k}var b=f.cookie=function(q,p,v){if(p!==undefined&&!f.isFunction(p)){v=f.extend({},b.defaults,v);if(typeof v.expires==="number"){var r=v.expires,u=v.expires=new Date();u.setTime(+u+r*86400000)}return(document.cookie=[d(q),"=",h(p),v.expires?"; expires="+v.expires.toUTCString():"",v.path?"; path="+v.path:"",v.domain?"; domain="+v.domain:"",v.secure?"; secure":""].join(""))}var w=q?undefined:{};var s=document.cookie?document.cookie.split("; "):[];for(var o=0,m=s.length;o<m;o++){var n=s[o].split("=");var j=g(n.shift());var k=n.join("=");if(q&&q===j){w=e(k,p);break}if(!q&&(k=e(k))!==undefined){w[j]=k}}return w};b.defaults={};f.removeCookie=function(j,i){if(f.cookie(j)===undefined){return false}f.cookie(j,"",f.extend({},i,{expires:-1}));return !f.cookie(j)}})); \ No newline at end of file
diff --git a/web/public/js/jquery.cookie.js b/web/public/js/jquery.cookie.js
new file mode 100644
index 0000000..c7f3a59
--- /dev/null
+++ b/web/public/js/jquery.cookie.js
@@ -0,0 +1,117 @@
+/*!
+ * 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);
+ };
+
+}));
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();