repertoire-faceting 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f493b2c43797a41070532955122147438ad1fd9
4
- data.tar.gz: 85ae33e1ca933b3e9b527fad304206f1221daf32
3
+ metadata.gz: 0c71410502e44435a35e7cf549dda9c78c20419e
4
+ data.tar.gz: b3f634a720ca6a81836543c9c8dca09a8e108826
5
5
  SHA512:
6
- metadata.gz: 1d01d1e0bbae61f613f20cac4bf604534ff9a48978077b25961df4d8833ab28275092559b7ae0e3144e09cbf53b7ebe7002c305b1ce1ab41eff37f7715af03a6
7
- data.tar.gz: 3a4fa49cd423cd47a8aaf7313d4e83ecf94839958c5ab90c0ff9f07f42bd4140c9d14a72252915c2e16ec4b1860c675817e6a4835c3c9d68f70cf017bc22576f
6
+ metadata.gz: 36b6cf33096262214ed207969c97065c81c2712ed05aed8d944a36689b44ff4ad70ac19549c6a95867fc71f68c98d0d64fadbe8df3f1f1287912442173ed30ca
7
+ data.tar.gz: 50358733e4533681470cfef9f93b12337f639e8c9056e068db302fd4ddbb5b0ab550597188707efff7db5fc47b416f40a47b4197594cfe3aee05ff9b7e54879c
data/ext/Makefile CHANGED
@@ -8,7 +8,7 @@
8
8
  #
9
9
  #-------------------------------------------------------------------------
10
10
 
11
- API_VERSION = 0.6.3
11
+ API_VERSION = 0.7.0
12
12
 
13
13
  MODULES = signature/signature
14
14
  EXTENSION = signature/faceting \
@@ -2,5 +2,5 @@
2
2
 
3
3
  comment = 'API for faceted indexing and queries (based on plv8 + bytea bitmaps)'
4
4
  requires = 'plv8, plpgsql'
5
- default_version = '0.6.3'
5
+ default_version = '0.7.0'
6
6
  schema = 'facet'
@@ -2,5 +2,5 @@
2
2
 
3
3
  comment = 'API for faceted indexing and queries (based on custom C bitmap type)'
4
4
  requires = plpgsql
5
- default_version = '0.6.3'
5
+ default_version = '0.7.0'
6
6
  schema = 'facet'
@@ -3,5 +3,5 @@
3
3
  comment = 'API for faceted indexing and queries (based on builtin VARBIT bit strings)'
4
4
  requires = plpgsql
5
5
  superuser = false
6
- default_version = '0.6.3'
6
+ default_version = '0.7.0'
7
7
  schema = 'facet'
@@ -46,4 +46,5 @@
46
46
  //= require ./rep.faceting/facet
47
47
  //= require ./rep.faceting/facet_widget
48
48
  //= require ./rep.faceting/nested_facet
49
- //= require ./rep.faceting/results
49
+ //= require ./rep.faceting/results
50
+ //= require ./rep.faceting/urls
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Repertoire faceting ajax widgets
3
- *
3
+ *
4
4
  * Copyright (c) 2009 MIT Hyperstudio
5
5
  * Christopher York, 09/2009
6
6
  *
@@ -25,6 +25,8 @@
25
25
 
26
26
  //= require rep.widgets
27
27
 
28
+ //= require deparam
29
+
28
30
  repertoire.facet_context = function(context_name, state_fn, options) {
29
31
  var self = repertoire.model(options);
30
32
 
@@ -51,6 +53,17 @@ repertoire.facet_context = function(context_name, state_fn, options) {
51
53
  }
52
54
  };
53
55
 
56
+ //
57
+ // Update each facet's refinements to the stored values
58
+ //
59
+ // If the stored values have no entry for the facet, it is cleared.
60
+ //
61
+ self.update_refinements = function(state) {
62
+ for (var facet in filter) {
63
+ filter[facet] = state[facet] || [];
64
+ };
65
+ };
66
+
54
67
  //
55
68
  // Calculate facet value counts from webservice
56
69
  //
@@ -61,7 +74,7 @@ repertoire.facet_context = function(context_name, state_fn, options) {
61
74
  // package up the faceting state and send back to results rendering service
62
75
  self.fetch(self.params(), url, 'json', callback, $elem);
63
76
  };
64
-
77
+
65
78
  //
66
79
  // Update query results from webservice
67
80
  //
@@ -72,7 +85,7 @@ repertoire.facet_context = function(context_name, state_fn, options) {
72
85
  // package up the faceting state and send back to results rendering service
73
86
  self.fetch(self.params(), url, type, callback, $elem);
74
87
  };
75
-
88
+
76
89
  //
77
90
  // Convenience function for constructing faceting urls
78
91
  //
@@ -80,9 +93,11 @@ repertoire.facet_context = function(context_name, state_fn, options) {
80
93
  var paths = [context_name, action]
81
94
  if (facet)
82
95
  paths.push(facet)
83
- var url = self.default_url(paths, ext);
84
- if (params)
85
- return url + '?' + self.to_query_string(params);
96
+ var url = self.default_url(paths, ext),
97
+ search = '?' + self.to_query_string(params);
98
+
99
+ if (search != '?')
100
+ return url + search
86
101
  else
87
102
  return url;
88
103
  };
@@ -96,22 +111,6 @@ repertoire.facet_context = function(context_name, state_fn, options) {
96
111
  return $.extend({}, { filter: self.refinements() }, state);
97
112
  };
98
113
 
99
-
100
- //
101
- // Added to allow facet widgets to pass arguments to context.
102
- //
103
- // ( Have to revisit with Christopher, it seems like he had an
104
- // pre_update() function in mind for this kind of behavior,
105
- // But I'm not sure how he envisioned it functioning. )
106
- //
107
- self.update_state = function(new_state) {
108
- var current_state = state_fn ? state_fn() : {};
109
- state_fn = function () {
110
- return $.extend({}, current_state, new_state);
111
- }
112
- };
113
-
114
-
115
114
  //
116
115
  // Return the identifying name for this context (usually the model class, pluralized)
117
116
  //
@@ -134,6 +133,22 @@ repertoire.facet_context = function(context_name, state_fn, options) {
134
133
  return values;
135
134
  };
136
135
 
136
+ //
137
+ // Provide a public url describing refinements
138
+ // (including any additional state defined by client app)
139
+ //
140
+ self.url = function() {
141
+ var url = self.default_url([context_name]),
142
+ params = self.params(),
143
+ search = '?' + self.to_query_string(params);
144
+
145
+ if (search != '?')
146
+ return url + search;
147
+ else
148
+ return url;
149
+ }
150
+
151
+
137
152
  // end of context factory method
138
153
  return self;
139
154
  }
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Repertoire faceting ajax widgets
3
+ *
4
+ * Copyright (c) 2014 MIT Hyperstudio
5
+ * Christopher York, 05/2014
6
+ *
7
+ * Requires jquery 1.3.2+
8
+ * Support: Firefox 3+ & Safari 4+. IE emphatically not supported.
9
+ *
10
+ *
11
+ * Register a faceting context to control the browser's url bar.
12
+ *
13
+ * Handles:
14
+ * - updating url bar when context changes
15
+ * - updating context from url bar when user goes back / forward
16
+ * - updating context from url on initial page load
17
+ *
18
+ * Usage:
19
+ * - attach this plugin to your faceting context *after* declaring
20
+ * all facets etc:
21
+ *
22
+ * $('#nobelists').facet_context(function() {
23
+ * return { search: $("#search").val() } }
24
+ * $('.facet').facet();
25
+ * ...
26
+ *
27
+ * $('#nobelists').urls(function(json) {
28
+ * $("#search").val(json.search); }
29
+ *
30
+ */
31
+
32
+ //= require deparam
33
+
34
+ //
35
+ // Set up history tracking
36
+ //
37
+
38
+ repertoire.urls = function(context, update_state_fn, options) {
39
+
40
+ // navigate to a new url whenever facet refinements change
41
+ context.bind('changed', function(data) {
42
+ if (!data.rerouting) {
43
+ history.pushState({}, '', context.url());
44
+ }
45
+ });
46
+
47
+ // copy refinements out of url when user travels in history
48
+ window.onpopstate = function (event) {
49
+ reroute();
50
+ };
51
+
52
+ // bootstrap refinements on page load
53
+ reroute();
54
+
55
+
56
+ function reroute() {
57
+ // parse search string
58
+ var search_string = location.search.substring(1),
59
+ params = $.deparam(search_string);
60
+ filter = params.filter || {};
61
+
62
+ // copy values into the declared facets
63
+ context.update_refinements(filter);
64
+
65
+ // allow client to update any fields it uses
66
+ if (update_state_fn)
67
+ update_state_fn(params);
68
+
69
+ // inform views of state change
70
+ context.trigger('changed', { rerouting : true });
71
+ }
72
+ }
73
+
74
+
75
+ // Urls plugin
76
+
77
+ $.fn.urls = function(update_state_fn, options) {
78
+ return this.each(function() {
79
+ // add locator css class to element, and store faceting context data model in it
80
+ var $elem = $(this);
81
+ var context = $elem.data('context');
82
+ repertoire.urls(context, update_state_fn, $.extend({}, repertoire.defaults, options));
83
+ });
84
+ };
@@ -40,9 +40,10 @@ repertoire.events = function(self, $proxy) {
40
40
 
41
41
  // wrap jquery's event trigger
42
42
  self.trigger = function(type, data) {
43
+ data = data || {};
43
44
  if (handlers[type]) {
44
45
  jQuery.each(handlers[type], function() {
45
- this.call(self);
46
+ this.call(self, data);
46
47
  })
47
48
  }
48
49
  };
@@ -126,9 +126,9 @@ repertoire.model = function(options) {
126
126
  vs.push(self.to_query_string(v, (prefix.length > 0) ? (prefix + '[' + encodeURIComponent(k) + ']') : encodeURIComponent(k)));
127
127
  });
128
128
  // minor addition to merb: discard empty value lists { e.g. discipline: [] }
129
- vs = array_filter(vs, function(x) { return x !== ""; });
129
+ vs = array_filter(vs, function(x) { return (x !== "") && (x != undefined); });
130
130
  return vs.join('&');
131
- } else {
131
+ } else if (value) {
132
132
  return prefix + '=' + encodeURIComponent(value);
133
133
  }
134
134
  };
@@ -136,21 +136,21 @@ repertoire.model = function(options) {
136
136
  // Apparently IE doesn't support the filter function? -DD via Brett
137
137
  var array_filter = function (thisArray, fun) {
138
138
  var len = thisArray.length;
139
- if (typeof fun != "function")
140
- throw new TypeError();
139
+ if (typeof fun != "function")
140
+ throw new TypeError();
141
141
 
142
- var res = new Array();
143
- var thisp = arguments[1];
142
+ var res = new Array();
143
+ var thisp = arguments[1];
144
144
 
145
- for (var i = 0; i < len; i++) {
146
- if (i in thisArray) {
147
- var val = thisArray[i]; // in case fun mutates this
148
- if (fun.call(thisp, val, i, thisArray))
149
- res.push(val);
150
- }
151
- }
145
+ for (var i = 0; i < len; i++) {
146
+ if (i in thisArray) {
147
+ var val = thisArray[i]; // in case fun mutates this
148
+ if (fun.call(thisp, val, i, thisArray))
149
+ res.push(val);
150
+ }
151
+ }
152
152
 
153
- return res;
153
+ return res;
154
154
  };
155
155
 
156
156
 
@@ -1,5 +1,5 @@
1
1
  module Repertoire
2
2
  module Faceting #:nodoc:
3
- VERSION = "0.6.3"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
@@ -0,0 +1,97 @@
1
+ /*
2
+ jQuery deparam is an extraction of the deparam method from Ben Alman's jQuery BBQ
3
+ http://benalman.com/projects/jquery-bbq-plugin/
4
+ */
5
+ (function ($) {
6
+ $.deparam = function (params, coerce) {
7
+ var obj = {},
8
+ coerce_types = { 'true': !0, 'false': !1, 'null': null };
9
+
10
+ // Iterate over all name=value pairs.
11
+ $.each(params.replace(/\+/g, ' ').split('&'), function (j,v) {
12
+ var param = v.split('='),
13
+ key = decodeURIComponent(param[0]),
14
+ val,
15
+ cur = obj,
16
+ i = 0,
17
+
18
+ // If key is more complex than 'foo', like 'a[]' or 'a[b][c]', split it
19
+ // into its component parts.
20
+ keys = key.split(']['),
21
+ keys_last = keys.length - 1;
22
+
23
+ // If the first keys part contains [ and the last ends with ], then []
24
+ // are correctly balanced.
25
+ if (/\[/.test(keys[0]) && /\]$/.test(keys[keys_last])) {
26
+ // Remove the trailing ] from the last keys part.
27
+ keys[keys_last] = keys[keys_last].replace(/\]$/, '');
28
+
29
+ // Split first keys part into two parts on the [ and add them back onto
30
+ // the beginning of the keys array.
31
+ keys = keys.shift().split('[').concat(keys);
32
+
33
+ keys_last = keys.length - 1;
34
+ } else {
35
+ // Basic 'foo' style key.
36
+ keys_last = 0;
37
+ }
38
+
39
+ // Are we dealing with a name=value pair, or just a name?
40
+ if (param.length === 2) {
41
+ val = decodeURIComponent(param[1]);
42
+
43
+ // Coerce values.
44
+ if (coerce) {
45
+ val = val && !isNaN(val) ? +val // number
46
+ : val === 'undefined' ? undefined // undefined
47
+ : coerce_types[val] !== undefined ? coerce_types[val] // true, false, null
48
+ : val; // string
49
+ }
50
+
51
+ if ( keys_last ) {
52
+ // Complex key, build deep object structure based on a few rules:
53
+ // * The 'cur' pointer starts at the object top-level.
54
+ // * [] = array push (n is set to array length), [n] = array if n is
55
+ // numeric, otherwise object.
56
+ // * If at the last keys part, set the value.
57
+ // * For each keys part, if the current level is undefined create an
58
+ // object or array based on the type of the next keys part.
59
+ // * Move the 'cur' pointer to the next level.
60
+ // * Rinse & repeat.
61
+ for (; i <= keys_last; i++) {
62
+ key = keys[i] === '' ? cur.length : keys[i];
63
+ cur = cur[key] = i < keys_last
64
+ ? cur[key] || (keys[i+1] && isNaN(keys[i+1]) ? {} : [])
65
+ : val;
66
+ }
67
+
68
+ } else {
69
+ // Simple key, even simpler rules, since only scalars and shallow
70
+ // arrays are allowed.
71
+
72
+ if ($.isArray(obj[key])) {
73
+ // val is already an array, so push on the next value.
74
+ obj[key].push( val );
75
+
76
+ } else if (obj[key] !== undefined) {
77
+ // val isn't an array, but since a second value has been specified,
78
+ // convert val into an array.
79
+ obj[key] = [obj[key], val];
80
+
81
+ } else {
82
+ // val is a scalar.
83
+ obj[key] = val;
84
+ }
85
+ }
86
+
87
+ } else if (key) {
88
+ // No value was defined, so set something meaningful.
89
+ obj[key] = coerce
90
+ ? undefined
91
+ : '';
92
+ }
93
+ });
94
+
95
+ return obj;
96
+ };
97
+ })(jQuery);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repertoire-faceting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher York
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -97,6 +97,7 @@ files:
97
97
  - lib/assets/javascripts/rep.faceting/facet_widget.js
98
98
  - lib/assets/javascripts/rep.faceting/nested_facet.js
99
99
  - lib/assets/javascripts/rep.faceting/results.js
100
+ - lib/assets/javascripts/rep.faceting/urls.js
100
101
  - lib/assets/javascripts/rep.protovis-facets.js
101
102
  - lib/assets/javascripts/rep.widgets.js
102
103
  - lib/assets/javascripts/rep.widgets/events.js
@@ -123,6 +124,7 @@ files:
123
124
  - lib/repertoire-faceting/tasks/all.rake
124
125
  - lib/repertoire-faceting/tasks/client.rake
125
126
  - lib/repertoire-faceting/version.rb
127
+ - vendor/assets/javascripts/deparam.js
126
128
  - vendor/assets/javascripts/google-earth-extensions.js
127
129
  - vendor/assets/javascripts/protovis.js
128
130
  homepage: http://github.com/repertoire/repertoire-faceting