Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

each metadata space gets its own dictionary

  • Loading branch information...
commit d674a590571335cc0377a0a4bbf0ee5b0cd35676 1 parent 6dca9e8
Craig Fratrik fratrik authored
4 example/minimal.html
View
@@ -11,6 +11,6 @@
</body>
<script src="../pkg/javelin.dev.js" type="text/javascript"></script>
<script type="text/javascript">
- JX.Stratcom.mergeData({});
+ JX.Stratcom.mergeData(0, {});
</script>
-</html>
+</html>
6 example/simple.html
View
@@ -15,14 +15,14 @@
</body>
<script src="../pkg/javelin.min.js" type="text/javascript"></script>
<script type="text/javascript">
- JX.Stratcom.mergeData({});
+ JX.Stratcom.mergeData(0, {});
JX.onload(function() {
JX.Stratcom.listen('click', 'dog', function(e) {
alert('Woof!');
});
JX.Stratcom.listen('click', 'cat', function(e) {
alert('Meow!');
- });
+ });
});
</script>
-</html>
+</html>
44 pkg/javelin.dev.js
View
@@ -978,15 +978,12 @@ JX.install('Stratcom', {
_handlers : [],
_need : {},
_matchName : /\bFN_([^ ]+)/,
- _matchData : /\bFD_([^ ]+)/,
+ _matchData : /\bFD_([^ ]+)_([^ ]+)/,
_auto : '*',
_data : {},
_execContext : [],
-
- /**
- * It's over nine THOUSSAANNND!!!!
- */
- _dataref : 9000,
+ _dataref : 0,
+ _dataBlock : 2,
/**
@@ -1336,12 +1333,13 @@ JX.install('Stratcom', {
* Merge metadata. You must call this (even if you have no metadata) to
* start the Stratcom queue.
*
+ * @param int The block of this metadata
* @param dict Dictionary of metadata.
* @return void
* @task internal
*/
- mergeData : function(data) {
- JX.copy(this._data, data);
+ mergeData : function(block, data) {
+ this._data[block] = data;
JX.Stratcom.ready = true;
JX.__rawEventQueue({type: 'start-queue'});
},
@@ -1423,12 +1421,25 @@ JX.install('Stratcom', {
}
}
- var idx = ((node.className || '').match(this._matchData) || [])[1];
- return (idx && this._data[idx]) || JX.Stratcom._setData(node, {});
+ var matches = ((node.className || '').match(this._matchData) || []);
+ var block = matches[1];
+ var idx = matches[2];
+ return
+ (idx && this._data[block] && this._data[block][idx]) ||
+ JX.Stratcom._setData(node, {});
},
/**
+ * Allocate a metadata block, normally for the purpose of passing it to an
+ * ajax request.
+ */
+ allocateMetadataBlock : function() {
+ return this._dataBlock++;
+ }
+
+
+ /**
* Attach metadata to a node. This data can later be retrieved through
* @{JX.Stratcom.getData()}, or @{JX.Event.getData()}.
*
@@ -1439,8 +1450,11 @@ JX.install('Stratcom', {
* @task internal
*/
_setData : function(node, data) {
- this._data[this._dataref] = data;
- node.className = 'FD_' + (this._dataref++) + ' ' + node.className;
+ if (!this._data[1]) { // data block 1 is reserved for javascript
+ this._data[1] = [];
+ }
+ this._data[1][this._dataref] = data;
+ node.className = 'FD_1_' + (this._dataref++) + ' ' + node.className;
return data;
}
}
@@ -1531,6 +1545,7 @@ JX.install('Request', {
_xhrkey : null,
_transport : null,
_finished : false,
+ _block : null,
send : function() {
var xport = null;
@@ -1554,6 +1569,9 @@ JX.install('Request', {
var q = [];
var data = this.getData() || {};
data.__async__ = true;
+
+ this._block = JX.Stratcom.allocateMetadataBlock();
+ data.__metablock__ = this._block;
for (var k in data) {
q.push(encodeURIComponent(k)+'='+encodeURIComponent(data[k]));
}
@@ -1635,7 +1653,7 @@ JX.install('Request', {
if (response.error) {
this._fail(response.error);
} else {
- JX.Stratcom.mergeData(response.javelin_metadata || {});
+ JX.Stratcom.mergeData(this._block, response.javelin_metadata || {});
this._done(response);
JX.initBehaviors(response.javelin_behaviors || {});
}
6 src/Request.js
View
@@ -25,6 +25,7 @@ JX.install('Request', {
_xhrkey : null,
_transport : null,
_finished : false,
+ _block : null,
send : function() {
var xport = null;
@@ -48,6 +49,9 @@ JX.install('Request', {
var q = [];
var data = this.getData() || {};
data.__async__ = true;
+
+ this._block = JX.Stratcom.allocateMetadataBlock();
+ data.__metablock__ = this._block;
for (var k in data) {
q.push(encodeURIComponent(k)+'='+encodeURIComponent(data[k]));
}
@@ -129,7 +133,7 @@ JX.install('Request', {
if (response.error) {
this._fail(response.error);
} else {
- JX.Stratcom.mergeData(response.javelin_metadata || {});
+ JX.Stratcom.mergeData(this._block, response.javelin_metadata || {});
this._done(response);
JX.initBehaviors(response.javelin_behaviors || {});
}
38 src/Stratcom.js
View
@@ -40,15 +40,12 @@ JX.install('Stratcom', {
_handlers : [],
_need : {},
_matchName : /\bFN_([^ ]+)/,
- _matchData : /\bFD_([^ ]+)/,
+ _matchData : /\bFD_([^ ]+)_([^ ]+)/,
_auto : '*',
_data : {},
_execContext : [],
-
- /**
- * It's over nine THOUSSAANNND!!!!
- */
- _dataref : 9000,
+ _dataref : 0,
+ _dataBlock : 2,
/**
@@ -398,12 +395,13 @@ JX.install('Stratcom', {
* Merge metadata. You must call this (even if you have no metadata) to
* start the Stratcom queue.
*
+ * @param int The block of this metadata
* @param dict Dictionary of metadata.
* @return void
* @task internal
*/
- mergeData : function(data) {
- JX.copy(this._data, data);
+ mergeData : function(block, data) {
+ this._data[block] = data;
JX.Stratcom.ready = true;
JX.__rawEventQueue({type: 'start-queue'});
},
@@ -485,12 +483,25 @@ JX.install('Stratcom', {
}
}
- var idx = ((node.className || '').match(this._matchData) || [])[1];
- return (idx && this._data[idx]) || JX.Stratcom._setData(node, {});
+ var matches = ((node.className || '').match(this._matchData) || []);
+ var block = matches[1];
+ var idx = matches[2];
+ return
+ (idx && this._data[block] && this._data[block][idx]) ||
+ JX.Stratcom._setData(node, {});
},
/**
+ * Allocate a metadata block, normally for the purpose of passing it to an
+ * ajax request.
+ */
+ allocateMetadataBlock : function() {
+ return this._dataBlock++;
+ }
+
+
+ /**
* Attach metadata to a node. This data can later be retrieved through
* @{JX.Stratcom.getData()}, or @{JX.Event.getData()}.
*
@@ -501,8 +512,11 @@ JX.install('Stratcom', {
* @task internal
*/
_setData : function(node, data) {
- this._data[this._dataref] = data;
- node.className = 'FD_' + (this._dataref++) + ' ' + node.className;
+ if (!this._data[1]) { // data block 1 is reserved for javascript
+ this._data[1] = [];
+ }
+ this._data[1][this._dataref] = data;
+ node.className = 'FD_1_' + (this._dataref++) + ' ' + node.className;
return data;
}
}
10 support/php/Javelin.php
View
@@ -13,6 +13,7 @@ class Javelin {
protected $onload = array();
protected $behavior = array();
protected $dirty = true;
+ protected $block = 0;
public static function renderTag($tag, $content, $attributes = array()) {
$javelin = self::getInstance();
@@ -27,7 +28,7 @@ public static function renderTag($tag, $content, $attributes = array()) {
case 'meta':
$id = count($javelin->metadata);
$javelin->metadata[$id] = $v;
- $classes[] = 'FD_'.$id;
+ $classes[] = 'FD_'.$this->block.'_'.$id;
unset($attributes[$k]);
break;
case 'mustcapture':
@@ -74,7 +75,8 @@ public static function renderHTMLFooter() {
$data = array();
if ($javelin->metadata) {
- $data[] = 'JX.Stratcom.mergeData('.json_encode($javelin->metadata).');';
+ $json_metadata = json_encode($javelin->metadata);
+ $data[] = 'JX.Stratcom.mergeData('.$this->block.', '.$json_metadata.');';
$javelin->metadata = array();
}
@@ -132,7 +134,9 @@ public static function renderAjaxResponse($payload, $error = null) {
}
protected function __construct() {
- // Protected constructor.
+ if (isset($_REQUEST['__metablock__'])) {
+ $this->block = $_REQUEST['__metablock__'];
+ }
}
public function __destruct() {
Please sign in to comment.
Something went wrong with that request. Please try again.