Permalink
Browse files

esi/csi support for onload event and $(QUERY_STRING)

  • Loading branch information...
1 parent 727028f commit a0f496d62e10e3556f69f21b9e86ba43bb330b30 Edward de Groot committed May 23, 2012
Showing with 32 additions and 4 deletions.
  1. +6 −0 History.md
  2. +7 −2 README.md
  3. +1 −1 package.json
  4. +18 −1 resources/javascript/timbits-csi.js
View
@@ -1,3 +1,9 @@
+0.5.7 / 2012-05-23
+==================
+
+ * Added support for onload event to client side esi/csi processing
+ * Allow for $(QUERY\_STRING{'name'}) syntax in client side esi/csi processing
+
0.5.6 / 2012-05-22
==================
View
@@ -257,8 +257,13 @@ Example:
In the example above, if the page was served through an ESI compatible proxy the first item would be rendered on the client (in the browser) while the second would be rendered within the proxy. If there was no ESI compatible proxy in place, both would be rendered on the client.
-
-This feature is in its early infancy. For example, we do not yet handle the ability to insert query string parameters client side, but that will be coming soon.
+
+To render these tags client side, include the jQuery library and the include /javascript/timbits-csi.js library on your page.
+
+We've also added support for the dynamic insertion of query string values into your client side ESI/CSI calls via the standard $(QUERY\_STRING{'name'}) syntax. For example, the following will grab the query string parameter 'term' from the host page and insert it into the source url prior to making the request.
+
+ <esi:include src="http://mytimbitserver.fake/chocolate/?q=$(QUERY_STRING{'term'})"></esi:include>
+
## Road Map
View
@@ -1,7 +1,7 @@
{
"name": "timbits",
"description": "Widget framework based on Express and CoffeeScript",
- "version": "0.5.6",
+ "version": "0.5.7",
"homepage": "https://github.com/Postmedia/timbits",
"author": "Edward de Groot <edegroot@postmedia.com> (http://mred9.wordpress.com)",
"contributors": [
@@ -1,16 +1,33 @@
+var csi_qs_regex = /[\?\&](\w+)=([^&]*)/g;
+var csi_qs_match;
+var csi_qs_params = {};
+
+while ((csi_qs_match = csi_qs_regex.exec(location.search)) != null) {
+ csi_qs_params[csi_qs_match[1]] = csi_qs_match[2];
+}
+
function processESI(index, element) {
var include = $(element);
var src = include.attr('src');
+ // add callback parameter
if (src.indexOf('?') == -1)
src += '?';
else
src += '&';
-
src += 'callback=?';
+ // dynamic QS insertion
+ var _re = /\$\(QUERY_STRING{'(\w+)'}\)/;
+ var match;
+ while ((match = src.match(_re)) != null) {
+ src = src.replace(match[0], csi_qs_params[match[1]] ? csi_qs_params[match[1]] : '');
+ }
+
$.getJSON(src, function(data) {
include.after(data);
+ var onload = include.attr('onload');
+ if (onload) eval(onload);
include.remove();
});
}

0 comments on commit a0f496d

Please sign in to comment.