/* Experimental extension to share name/value pairs directly
This could be done with hidden objects, but the idea was to
be a bit more direct about it.
Example:
var x = mobwrite.shareString("filename",{
onchange: function(v)
{ document.getElementById('click').innerHTML = x.value; },
merge: true,
value: "hello, world"});
// to update x
x.setClientText("new value");
*/
mobwrite.shareStringObj = function(key,vals) {
mobwrite.shareObj.apply(this, [key]);
if (vals){
this.mergeChanged = vals.merge;
this.onchange_ = vals.onchange;
this.value=vals.value;
}
};
mobwrite.shareStringObj.prototype = new mobwrite.shareObj('');
mobwrite.shareStringObj.prototype.getClientText = function() {
return this.value?this.value:"";
};
mobwrite.shareStringObj.prototype.setClientText = function(text) {
this.value = text;
if (this.onchange_)
this.onchange_(this);
};
mobwrite.shareString = function(key,vals) {
if (!mobwrite.syncRunPid_ )
mobwrite.syncRunPid_ = window.setTimeout(mobwrite.syncRun1_,
10);
if (!mobwrite.shared[key])
return this.shared[key] = new
mobwrite.shareStringObj(key,vals);
else
return this.shared[key];
};