demo2.html?data1=01&data2=02&data3
/* -------------------------------------------------------------------------- */
/*
| LSOperate
*/
/* -------------------------------------------------------------------------- */
/*
* location.searchを扱うライブラリです。
*
* LSOperate( 変数名 )でlocation.searchに含まれる"変数名=値"の"値"を取り出せます。
* 変数が存在しないときはundefined、値がないときはnullが返ります。
*
* var foo = new LSOperate.model()でlocation.searchを編集できます。
* foo.valueには編集後のlocation.hrefが常に保持されます。
* foo.del( 変数名 )とすると指定された変数が削除されます。
* foo.push( 変数名,値 )とすると指定された変数が新たに追加されます。
* foo.change( 変数名,値 )とすると指定された変数の値が変更されます。
* 値を変更したいのにfoo.pushを使うと変数が2重に追加され、読み出し時は最初の変数が優先されるので注意してください。
*/
function LSOperate( name )
{
LSOperate.make();
for( var i=0 ; i<LSOperate.datalist.length ; i++ )
if( LSOperate.datalist[i][0]==name )return LSOperate.datalist[i][1];
return undefined;
}
LSOperate.datalist = null;
LSOperate.baseUri = null;
LSOperate.isMade = false;
LSOperate._date = new Date("Jun 25, 2006");
LSOperate._version = "1.0";
LSOperate.make = function()
{
if( LSOperate.isMade )return;
else LSOperate.isMade = true;
if( location.search.length<2 )
{
LSOperate.datalist = new Array();
return;
}
LSOperate.datalist = location.search.substr(1,location.search.length-1).split("&");
for( var i=0 ; i<LSOperate.datalist.length ; i++ )
if( LSOperate.datalist[i].indexOf("=")>-1 )LSOperate.datalist[i] = LSOperate.datalist[i].split("=");
else LSOperate.datalist[i] = [LSOperate.datalist[i],"null"];
LSOperate.baseUri = location.href.split("?")[0];
}
LSOperate.model = function()
{
LSOperate.make();
this._modelLS = LSOperate.datalist.LSOperateCopy();
this._modelUri = LSOperate.baseUri;
this.value;
this.compose();
}
LSOperate.model.prototype.compose = function()
{
this.value = this._modelUri + "?";
for( var i=0 ; i<this._modelLS.length ; i++ )
{
this.value += this._modelLS[i][0];
if( this._modelLS[i][1] )this.value += "=" + this._modelLS[i][1];
if( i+1<this._modelLS.length )this.value += "&";
}
}
LSOperate.model.prototype.del = function( name )
{
for( var i=0 ; i<this._modelLS.length ; i++ )
if( this._modelLS[i][0]==name )
this._modelLS = this._modelLS.LSOperateDel(i);
this.compose();
}
LSOperate.model.prototype.push = function( name,data )
{
if( !data )data = null;
this._modelLS.LSOperatePush([name,data]);
this.compose();
}
LSOperate.model.prototype.change = function( name,data )
{
if( !data )data = null;
for( var i=0 ; i<this._modelLS.length ; i++ )
if( this._modelLS[i][0]==name )this._modelLS[i][1] = data;
this.compose();
}
Array.prototype.LSOperateCopy = function()
{
var new_array = new Array( this.length );
for( var i=0 ; i<this.length ; i++ )
{
if( typeof this[i] == "object" )var now = this[i].LSOperateCopy();
else var now = this[i];
new_array[i] = now;
}
return new_array;
}
Array.prototype.LSOperateDel = function( point )
{
var first = this.slice(0,point);
var last = this.slice(point+1,this.length);
return first.concat(last);
}
Array.prototype.LSOperatePush = function( data )
{
var plus = this.length;
return this[plus] = data;
}