diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bf9dfdc..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.swp -.DS_Store diff --git a/README b/README deleted file mode 100644 index e69de29..0000000 diff --git a/index.html b/index.html new file mode 100644 index 0000000..052dc15 --- /dev/null +++ b/index.html @@ -0,0 +1,77 @@ + + + + + + manji6/jquery.locationHash @ GitHub + + + + + + Fork me on GitHub + +
+ +
+ + + + +
+ +

jquery.locationHash + by manji6

+ +
+ ハッシュフラグメントを利用したWebアプリケーション製作時にlocation.hashを簡単に操作できるようにするライブラリ +
+ +

Authors

+

manji6 (ryosuke.sawada@gmail.com)

+

Contact

+

manji6 (ryosuke.sawada@gmail.com)

+ + +

Download

+

+ You can download this project in either + zip or + tar formats. +

+

You can also clone the project with Git + by running: +

$ git clone git://github.com/manji6/jquery.locationHash
+

+ + + +
+ + + + diff --git a/locationHash.jquery.json b/locationHash.jquery.json deleted file mode 100644 index 64c884c..0000000 --- a/locationHash.jquery.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "locationHash", - "title": "jQuery.locationHash", - "description": "Library to be able to treat like a parameter to get location.hash.", - "keywords": ["location.hash","ajax"], - "version": "1.0.0", - "author": { - "name": "manji6", - "url": "http://manjiro.net/" - }, - "dependencies": { - "jquery": ">=1.4.1" - }, - "licenses": [{ - "type": "MIT", - "url": "http://opensource.org/licenses/mit-license.php" - }], - "docs": "http://manjiro.net/jquery-plugin/jquery-locationhash", - "files": "src/jquery.locationhash.js" -} \ No newline at end of file diff --git a/sample/index.html b/sample/index.html deleted file mode 100644 index 19a50c9..0000000 --- a/sample/index.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - jquery.locationHash test page - - -

jQuery.locationHash sample

-

各区切り文字 -

-

-
-

1.location.hash文字列を分解してパラメーターオブジェクトに変換する

-

[実行]

-

実行コード: $.getParameterFromLocationHash()

-

変換結果: ここに文字列展開(console.logでobject出力もしています)

-

実行コード: $("form").getParameterFromLocationHash({preprocess:function(){location.hash.slice(0,location.hash.indexOf("?"))}}) -

-

変換結果: ここに文字列展開

-
-
-

2.特定要素配下にある要素のinput要素を取得してlocation.hash文字列を生成する

-

- - [実行] -

-

対象フォーム

-
-

実行コード: $("form").getLocationHash()

-

変換結果: ここに文字列展開

- - -
- - - - - diff --git a/sample/sample.js b/sample/sample.js deleted file mode 100644 index e1162fe..0000000 --- a/sample/sample.js +++ /dev/null @@ -1,36 +0,0 @@ -$(function(){ - $("#separater_keykey span").text($.locationHash.str_separaterKeyKey); - $("#separater_keyvalue span").text($.locationHash.str_separaterKeyValue); - $("#separater_valuevalue span").text($.locationHash.str_separaterValueValue); - - $("#sample2_textarea").val($("#sample2_form1").html()); - -}); -$("#sample1 a.running").click(function(){ - location.hash = $("#sample1 input.input_param").val(); - $("#sample1 span.result").text($.param($.getParameterFromLocationHash())); - $("#sample1 span.result2").text($.param($.getParameterFromLocationHash({preprocess:function(){ - if(location.hash.indexOf("?") > -1){ - return location.hash.slice(0,location.hash.indexOf("?")); - }else{ - return location.hash; - } - }}))); - console.log($.getParameterFromLocationHash()); - console.log($.getParameterFromLocationHash({preprocess:function(){ - if(location.hash.indexOf("?") > -1){ - return location.hash.slice(0,location.hash.indexOf("?")); - }else{ - return location.hash; - } - }})); -}); - -$("#sample2 a.running").click(function(){ - $("#sample2 span.result").text($("#sample2_form1").getLocationHash()); - -}); - -$("#sample2 #sample2_textarea").keyup(function(){ - $("#sample2_form1").html($("#sample2_textarea").val()); -}); diff --git a/src/jquery.locationhash.js b/src/jquery.locationhash.js deleted file mode 100644 index 56d66d2..0000000 --- a/src/jquery.locationhash.js +++ /dev/null @@ -1,290 +0,0 @@ -/** - * jQuery.locationHash.js - * - * @author Ryosuke Sawada - * @require jQuery - * @licence MIT Licence -*/ - - -/** - * See (http://jquery.com/). - * @name $ - * @class - * See the jQuery Library (http://jquery.com/) for full details. This just - * documents the function and classes that are added to jQuery by this plug-in. -*/ - -/** - * See (http://jquery.com/) - * @name $.fn - * @class - * See the jQuery Library (http://jquery.com/) for full details. This just - * documents the function and classes that are added to jQuery by this plug-in. -*/ - -/** - * - * jQuery.locationHash()の設定を行う - * - * @param {Object} oSetting 設定オブジェクト - **/ -$.locationHash = { - 'str_separaterKeyKey': '&' - ,'str_separaterKeyValue': '=' - ,'str_separaterValueValue': '|' - ,'str_locationhashBefore': "#!" -} - - -/** - * - * jQuery.locationHash()のパラメーターをセットする - * (該当キーが無い場合:追加、ある場合:削除) - * (Value値も設定していたら、該当key&valueが有る場合にのみ削除を行う) - * - * @param {String} sKey キー - * @param {String} sValue 値(null時は登録なし) - **/ -$.locationHashParameter = function(sKey,sValue,option){ - - var oHash = {}; - - // 書き換えパラメーターをオブジェクトで渡された時は変数の入れ替えをする - if($.type(sKey) !== "object"){ - - oHash[sKey] = sValue; - - }else{ - oHash = sKey; - option = sValue; - } - - //設定オブジェクト - option = $.extend(true,{},{ - "forceUpdate":false //Value値が違っていても値を上書きする - },option); - - - // 現在のlocation.hash値配列を取得 - // (不要な文字列を削除して、keyとkeyの区切り記号で分割したものを用意) - var aLocationHash = (function(){ - var sLocationHash = location.hash.slice($.locationHash.str_locationhashBefore.length); - - if(sLocationHash === ""){ - return []; - }else{ - return sLocationHash.split($.locationHash.str_separaterKeyKey); - } - })(); - - - //処理するオブジェクトをループして処理 - for(var keyname in oHash){ - - var sHashKey = keyname; - var sHashValue = oHash[keyname]; - - - //sHashValueが指定されていない場合は処理せず終了 - if(typeof sHashValue === "undefined"){ - return false; - } - //sHashKeyが指定されていない場合は処理せず終了 - if(typeof sHashKey === "undefined"){ - return false; - } - - var iTargetKeyNum = -1; - - - - // 該当keyの状況を取得 - for(var i in aLocationHash){ - var r_regex = new RegExp("^"+sHashKey+"="); - if(aLocationHash[i].toString().match(r_regex) !== null){ - iTargetKeyNum = i; - } - } - - // location.hash内に該当のkey値が有りValue値が同じ場合は削除、無い場合は値を追加 - if(iTargetKeyNum > -1){ - //判定結果:該当するキーがする - // 既にvalueはセットしてあるかしてないかを判定 - aLocationHash = (function(){ - var sHashKeyName = aLocationHash[iTargetKeyNum].substring(0,aLocationHash[iTargetKeyNum].indexOf($.locationHash.str_separaterKeyValue)); - var sTmpValue = aLocationHash[iTargetKeyNum].substring(aLocationHash[iTargetKeyNum].indexOf($.locationHash.str_separaterKeyValue)+1); - var aValue = sTmpValue.split($.locationHash.str_separaterValueValue); - var iTargetValueNum = -1; - - //for(var i in aValue){ - for(var i=0,len=aValue.length;i -1){ - iTargetValueNum = i; - } - } - - if(option.forceUpdate === false){ - - if(iTargetValueNum > -1){ - //既にValue値が存在する=値の削除 - // 値が複数ある場合はValue配列から該当値を削除、単数の場合は配列を初期化 - if(aValue.length === 1){ - aValue = []; - }else{ - aValue.splice(iTargetValueNum,1); - } - }else{ - //Value値が存在しない=同一KeyのValue値追加 - aValue.push(sHashValue.toString()); - } - }else{ - //強制更新モードの場合は値が定義されている=上書き - if(sHashValue === ""){ - aValue = []; - }else{ - aValue = [sHashValue]; - } - } - - // 更新したValue値をセットする - if(aValue.length === 0){ - aLocationHash.splice(iTargetKeyNum,1); - }else{ - aValue.sort(); - aLocationHash[iTargetKeyNum] = sHashKeyName+$.locationHash.str_separaterKeyValue+aValue.join($.locationHash.str_separaterValueValue); - } - return aLocationHash; - })(); - - }else{ - //判定結果:該当するキーが無い - // キーと値の追加を行う - // aLocationHash.splice(iTargetKeyNum,1); - //値が空文字の場合は処理しない - if(sHashValue !== ""){ - aLocationHash.push(sHashKey+$.locationHash.str_separaterKeyValue+sHashValue.toString()); - } - } - } - - aLocationHash.sort(); - - // location.hashに戻す - location.hash = $.locationHash.str_locationhashBefore+aLocationHash.join($.locationHash.str_separaterKeyKey); -} - -/** - * 特定要素配下にある要素のinput要素を取得してLocationHash文字列を生成する - * - * mergeParam:セットしたキー名は値を複数もつことが可能。その際のキー名は"キー名__値"となっていること。 - * - * @param {Object} oOption オプション定義オブジェクト - * @return {String} LocationHash文字列 - **/ -$.fn.getLocationHash = function(oOption){ - - //設定オブジェクト - oOption = $.extend(true,{},{ - mergeParam:[], //@param {Array} 配列内にセットしたキー名は、値を複数持つ事が可能 - ignoreParam:[] //@param {Array} 配列内にセットしたキー名は、処理をしない(値定義をしない)事が可能 - },oOption); - - //リクエスト配列 - var aRequest = $(this).serializeArray(); - //中間処理用リクエストオブジェクト - var oRequest = {}; - //戻り値 - var aHash = []; - - // 1回目は強制的にループ処理をし、マージパラメーター処理が1個以上定義してあれば複数回ループ処理を行う - //for(var j = -1,leng = oOption.mergeParam.length; j < leng; j++){ - var oTmpMergeParam = {}; - if(oOption.mergeParam.length > 0){ - for(var j = 0, leng = oOption.mergeParam.length; j < leng; j++){ - oTmpMergeParam[oOption.mergeParam[j]] = []; - } - } - - for(var i = 0,len = aRequest.length; i < len; i++){ - //ignoreParamに定義されている値の場合は処理しない - if(oOption.ignoreParam.join(",").indexOf(aRequest[i].name) > -1){ - continue; - } - - //Value値がnullの場合は処理しない - if(aRequest[i].value === ""){continue;} - - //マージ対応するパラメーターはここで取り出しておく - if(oOption.mergeParam.length > 0){ - var sExecutedName = ""; - for(var j = 0, leng = oOption.mergeParam.length; j < leng; j++){ - if(aRequest[i].name.indexOf(oOption.mergeParam[j]) > -1){ - oTmpMergeParam[oOption.mergeParam[j]].push(aRequest[i].name.split("__")[1]); - sExecutedName = oOption.mergeParam[j]; - } - } - if(sExecutedName !== ""){ - oRequest[sExecutedName] = []; - continue; - } - } - - //aHash.push(aRequest[i].name+$.locationHash.str_separaterKeyValue+aRequest[i].value); - if(typeof oRequest[aRequest[i].name] === "undefined"){ - oRequest[aRequest[i].name] = []; - } - oRequest[aRequest[i].name].push(aRequest[i].value); - } - - //マージ処理用パラメータを結合してリクエストオブジェクトへ展開 - if(oOption.mergeParam.length > 0){ - for(var name in oTmpMergeParam){ - if(oTmpMergeParam[name].length > 0){ - oRequest[name] = oTmpMergeParam[name]; - } - } - } - - // 値を整理しながら文字列を生成 - for(name in oRequest){ - for(var i = 0,len = oRequest[name].length; i < len; i++){ - oRequest[name][i] = encodeURI(oRequest[name][i]); - } - aHash.push(name+$.locationHash.str_separaterKeyValue+oRequest[name].join($.locationHash.str_separaterValueValue)); - } - - return aHash.join($.locationHash.str_separaterKeyKey); -} - -/** - * locationhashからパラメーターオブジェクトを取得する - * @param {Object} oSetting 設定オブジェクト - * @return {Array} パラメーターオブジェクト(array->object) - **/ -$.getParameterFromLocationHash = function(oSetting){ - - var oSetting = oSetting || {preprocess: function(){return location.hash}}; - var sLocationHash = oSetting.preprocess(); - - // 値の定義 - var aReturn = new Array(); - var oReturn = {}; - var aHashParam = sLocationHash.slice($.locationHash.str_locationhashBefore.length).split($.locationHash.str_separaterKeyKey); - - - for(i = 0,len = aHashParam.length; i < len; i++){ - if(aHashParam[i] === ""){ - continue; - } - var aHashSplitParam = aHashParam[i].split($.locationHash.str_separaterKeyValue); - if(aHashSplitParam[1].indexOf($.locationHash.str_separaterValueValue) > -1){ - aHashSplitParam[1] = aHashSplitParam[1].split($.locationHash.str_separaterValueValue); - } - //aReturn.push({key: aHashSplitParam[0], value: aHashSplitParam[1]}); - oReturn[aHashSplitParam[0]] = aHashSplitParam[1]; - } - return oReturn; -} - - diff --git a/src/jquery.locationhash.min.js b/src/jquery.locationhash.min.js deleted file mode 100644 index 1dad093..0000000 --- a/src/jquery.locationhash.min.js +++ /dev/null @@ -1,7 +0,0 @@ -$.locationHash={str_separaterKeyKey:"&",str_separaterKeyValue:"=",str_separaterValueValue:"|",str_locationhashBefore:"#!"}; -$.locationHashParameter=function(a,f,c){var k={};if($.type(a)!=="object")k[a]=f;else{k=a;c=f}c=$.extend(true,{},{forceUpdate:false},c);var e=function(){var j=location.hash.slice($.locationHash.str_locationhashBefore.length);return j===""?[]:j.split($.locationHash.str_separaterKeyKey)}();for(var g in k){a=g;var h=k[g];if(typeof h==="undefined")return false;if(typeof a==="undefined")return false;var b=-1;for(var l in e){f=new RegExp("^"+a+"=");if(e[l].toString().match(f)!==null)b=l}if(b>-1)e=function(){for(var j= -e[b].substring(0,e[b].indexOf($.locationHash.str_separaterKeyValue)),d=e[b].substring(e[b].indexOf($.locationHash.str_separaterKeyValue)+1).split($.locationHash.str_separaterValueValue),n=-1,m=0,o=d.length;m-1)n=m;if(c.forceUpdate===false)if(n>-1)if(d.length===1)d=[];else d.splice(n,1);else d.push(h.toString());else d=h===""?[]:[h];if(d.length===0)e.splice(b,1);else{d.sort();e[b]=j+$.locationHash.str_separaterKeyValue+d.join($.locationHash.str_separaterValueValue)}return e}(); -else h!==""&&e.push(a+$.locationHash.str_separaterKeyValue+h.toString())}e.sort();location.hash=$.locationHash.str_locationhashBefore+e.join($.locationHash.str_separaterKeyKey)}; -$.fn.getLocationHash=function(a){a=$.extend(true,{},{mergeParam:[],ignoreParam:[]},a);var f=$(this).serializeArray(),c={},k=[],e={};if(a.mergeParam.length>0)for(var g=0,h=a.mergeParam.length;g-1))if(f[b].value!==""){if(a.mergeParam.length>0){var j="";g=0;for(h=a.mergeParam.length;g-1){e[a.mergeParam[g]].push(f[b].name.split("__")[1]);j=a.mergeParam[g]}if(j!== -""){c[j]=[];continue}}if(typeof c[f[b].name]==="undefined")c[f[b].name]=[];c[f[b].name].push(f[b].value)}if(a.mergeParam.length>0)for(var d in e)if(e[d].length>0)c[d]=e[d];for(d in c){b=0;for(l=c[d].length;b-1)c[1]=c[1].split($.locationHash.str_separaterValueValue);f[c[0]]=c[1]}return f}; diff --git a/src/test-jquery.locationhash.js b/src/test-jquery.locationhash.js deleted file mode 100644 index fbf0c26..0000000 --- a/src/test-jquery.locationhash.js +++ /dev/null @@ -1,291 +0,0 @@ -/* - * jquery.locationHash.js - * unittest code (required Qunit) - * - * @author Ryosuke Sawada - * @require jQuery,Qunit - */ - -module("$.locationHashParameter") - - -test("値の追加処理",function(){ - - // location.hashの値をクリアする - location.hash = ""; - - // key => "key" value => "2" を追加処理 - $.locationHashParameter('key',2); - same(location.hash,"#!key=2","key=2を追加"); - - // key => "key" value => "1" を追加処理 - $.locationHashParameter('key',1); - same(location.hash,"#!key=1|2","key=1を追加、値はsort()して順番を整える"); -}); - - -test("値の削除処理",function(){ - - // location.hashの値を定義する - location.hash = "#!key=1|2"; - - // key => "key" value => "1" を追加処理 - $.locationHashParameter('key',1); - same(location.hash,"#!key=2","key=1の削除"); - - // key => "key" value => "2" を追加処理 - $.locationHashParameter('key',2); - same(location.hash,"#!","key自体の削除"); - -}); -test("複数キー値の追加処理",function(){ - - // location.hash の値をクリアする - location.hash = ""; - - // key => "h-spa" value => "1" を追加処理 - $.locationHashParameter('h-spa',1); - same(location.hash,"#!h-spa=1","キー'h-spa'の追加"); - - // key => "h-parking" value => "1" を追加処理 - $.locationHashParameter('h-parking',1); - same(location.hash,"#!h-parking=1&h-spa=1","キー'h-parking'の追加"); - - - // key => "h-big_bath" value => "1" を追加処理 - $.locationHashParameter('h-big_bath',1); - same(location.hash,"#!h-big_bath=1&h-parking=1&h-spa=1","キー'h-big_bath'の追加"); - - -}); - - -test("複数キー値が設定してある状態での削除処理",function(){ - - location.hash = "#!h-big_bath=1&h-parking=1&h-spa=1"; - - // key => "h-parking" value => "1" を追加処理 - $.locationHashParameter('h-parking',1); - same(location.hash,"#!h-big_bath=1&h-spa=1","キー'h-parking'の削除"); - - // key => "h-big_bath" value => "1" を追加処理 - $.locationHashParameter('h-big_bath',1); - same(location.hash,"#!h-spa=1","キー'h-big_bath'の削除"); - - // key => "h-spa" value => "1" を追加処理 - $.locationHashParameter('h-spa',1); - same(location.hash,"#!","キー'h-spa'の削除"); - -}); - -test("エラー処理",function(){ - - // 一旦パラメーターを削除 - location.hash = ""; - - var sReturn = ""; - - // location.hashが"#"のみの場合、IE系は"#",それ以外は""となるので、対応させる - - if(!jQuery.support.noCloneEvent){ - sReturn = "#"; - } - - // key => "h-spa" value => undefined を追加処理 - $.locationHashParameter('h-spa'); - same(location.hash,sReturn,"valueがundefined時は処理せず終了"); - - // 一旦パラメーターを削除 - location.hash = ""; - - - // key => "h-spa" value => "" を追加処理 - $.locationHashParameter('h-spa',''); - same(location.hash,"#!","valueが空文字時は値の削除処理をしてデフォルトパラメータを付けて終了"); - - // 一旦パラメーターを削除 - location.hash = ""; - - // key => undefined value => undefined を追加処理 - $.locationHashParameter(); - same(location.hash,sReturn,"keyがundefined時は処理せず終了"); - - // 一旦パラメーターを削除 - location.hash = ""; - - // key => "" value => undefined を追加処理 - $.locationHashParameter(""); - same(location.hash,sReturn,"keyが空文字時は処理せず終了"); - -}); - - -module("$.locationHash"); - -test("区切り文字列などの定義値変更処理",function(){ - - // 区切り値を変更する - $.locationHash = { - "str_separaterKeyKey": '&', - "str_separaterKeyValue": '=', - "str_separaterValueValue": ',', - "str_locationhashBefore": '#' - }; - - same($.locationHash.str_separaterKeyKey,"&","key値とkey値の区切り文字列を'&'へ変更"); - same($.locationHash.str_separaterKeyValue,"=","key値とvalue値の区切り文字列を'='へ変更"); - same($.locationHash.str_separaterValueValue,",","value値とvalue値の区切り文字列を','へ変更"); - same($.locationHash.str_locationhashBefore,"#","location.hashの先頭文字列からパラメータ値までにある不要な文字列を'#'へ変更"); - - //値の追加を行う - - location.hash = ""; - - // key => "key" value => "1" を追加処理 - $.locationHashParameter('key',1); - same(location.hash,"#key=1","key=1を追加"); - - // key => "key" value => "2" を追加処理 - $.locationHashParameter('key',2); - same(location.hash,"#key=1,2","key=2を追加"); - - // key => "key2" value => "ok" を追加処理 - $.locationHashParameter('key2',"ok"); - same(location.hash,"#key2=ok&key=1,2","key2=okを追加"); - - // key => "key" value => "2" を追加処理 - $.locationHashParameter('key',2); - same(location.hash,"#key2=ok&key=1","key=2を削除"); - - // 値の名称完全一致 - $.locationHashParameter("keykey","fuga"); - same(location.hash,"#key2=ok&key=1&keykey=fuga","keykeyを追加"); - - -}); - -//最後に余計なハッシュフラグメントを取っておく -location.hash = ""; - - -module("$.getLocationHash",{ - setup: function(){ - - // 区切り文字指定を初期化 - $.locationHash = { - 'str_separaterKeyKey': '&' - ,'str_separaterKeyValue': '=' - ,'str_separaterValueValue': '|' - ,'str_locationhashBefore': "#!" - } - - } -}); - - -test("正常系の実行",function(){ - - // テスト用のHTMLを生成する - var aHtml = []; - aHtml.push("
"); - aHtml.push(""); - aHtml.push("
"); - $("body").append( - $("
").append(aHtml.join("\n")) - ); - - same($("#testForm").getLocationHash(),"text1=yes","単体input値を判定"); - - //複数パラメーターをセットした場合 - $("#testForm").append(""); - same($("#testForm").getLocationHash(),"text1=yes&text2=hogehoge","複数input値を判定"); - - // radioボタンを追加 - $("#testForm").append(""); - same($("#testForm").getLocationHash(),"text1=yes&text2=hogehoge&radio1=1","radioパラメーター追加"); - - // checkboxを追加 - $("#testForm").append(""); - same($("#testForm").getLocationHash(),"text1=yes&text2=hogehoge&radio1=1&checkbox1=1","checkbox追加"); - - // checkboxを追加 - $("#testForm").append(""); - same($("#testForm").getLocationHash(),"text1=yes&text2=hogehoge&radio1=1&checkbox1=1|3","checkbox複数選択状態"); - - // マージパラメーター処理を付与し、該当パラメーターを増やす - - $("#testForm").append(""); - same($("#testForm").getLocationHash({mergeParam: ["checkbox2"]}),"text1=yes&text2=hogehoge&radio1=1&checkbox1=1|3&checkbox2=1|2","パラメーターのマージ処理付与"); - - // selectboxを追加 - $("#testForm").append(""); - same($("#testForm").getLocationHash({mergeParam: ["checkbox2"]}),"text1=yes&text2=hogehoge&radio1=1&checkbox1=1|3&checkbox2=1|2&select1=2","セレクトボックス処理"); - -}); - - -test("オプションパラメーター",function(){ - - // location.hashの値をクリアする - location.hash = "#!"; - - $.locationHashParameter('key',2); - same(location.hash,"#!key=2","key=2を追加"); - - $.locationHashParameter('key',3,{"forceUpdate": true}); - same(location.hash,"#!key=3","forceUpdateモードなので値は書き換えられて3になる"); - - $.locationHashParameter('key',"",{"forceUpdate": true}); - same(location.hash,"#!","値が消える"); - - $.locationHashParameter('key',3,{"forceUpdate": true}); - same(location.hash,"#!key=3","forceUpdateモードなので値は書き換えられて3になる"); - - $.locationHashParameter('key',1,{"forceUpdate": false}); - same(location.hash,"#!key=1|3","値の追加"); - - $.locationHashParameter('key',"",{"forceUpdate": true}); - same(location.hash,"#!","値が消えるべき"); - - $.locationHashParameter('key',2); - same(location.hash,"#!key=2","key=2を追加"); - - $.locationHashParameter('hoge',1); - same(location.hash,"#!hoge=1&key=2","hoge=2を追加"); - - $.locationHashParameter('hoge',""); - same(location.hash,"#!key=2","hoge=2を削除"); - -}); - - -test("値の複数処理",function(){ - - location.hash = "#!"; - - $.locationHashParameter({"key":2,"hoge":"fuga"}); - same(location.hash,"#!hoge=fuga&key=2","オブジェクト型で値をセット"); - - - $.locationHashParameter({"key":"3","hoge":"mogmog"},{"forceUpdate":true}); - same(location.hash,"#!hoge=mogmog&key=3","forceupdate処理に対応"); - - $.locationHashParameter({"key":"","hoge":""},{"forceUpdate":true}); - same(location.hash,"#!","値の削除処理"); - - $.locationHashParameter({"key":"3","keykey":"mogmog"},{"forceUpdate":true}); - same(location.hash,"#!key=3&keykey=mogmog","forceupdate処理に対応"); - - - - -}); - -test("おかしいパターン",function(){ - - location.hash = "#!kwd=aaa&kwd_type=1"; - - $.locationHashParameter({kwd: "bbb",kwd_type: "3"}, {forceUpdate:true}); - same(location.hash,"#!kwd=bbb&kwd_type=3","forceupdate処理に対応"); - -});