]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Realtime/jquery.getUrlParam.js
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / plugins / Realtime / jquery.getUrlParam.js
1 /* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de)
2  * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
3  * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
4  * 
5  * Version 2.1
6  * 
7  * Thanks to 
8  * Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
9  * Tom Leonard for some improvements
10  * 
11  */
12 jQuery.fn.extend({
13 /**
14 * Returns get parameters.
15 *
16 * If the desired param does not exist, null will be returned
17 *
18 * To get the document params:
19 * @example value = $(document).getUrlParam("paramName");
20
21 * To get the params of a html-attribut (uses src attribute)
22 * @example value = $('#imgLink').getUrlParam("paramName");
23 */ 
24  getUrlParam: function(strParamName){
25           strParamName = escape(unescape(strParamName));
26           
27           var returnVal = new Array();
28           var qString = null;
29           
30           if ($(this).attr("nodeName")=="#document") {
31                 //document-handler
32                 
33                 if (window.location.search.search(strParamName) > -1 ){
34                         
35                         qString = window.location.search.substr(1,window.location.search.length).split("&");
36                 }
37                         
38           } else if ($(this).attr("src")!="undefined") {
39                 
40                 var strHref = $(this).attr("src")
41                 if ( strHref.indexOf("?") > -1 ){
42                 var strQueryString = strHref.substr(strHref.indexOf("?")+1);
43                         qString = strQueryString.split("&");
44                 }
45           } else if ($(this).attr("href")!="undefined") {
46                 
47                 var strHref = $(this).attr("href")
48                 if ( strHref.indexOf("?") > -1 ){
49                 var strQueryString = strHref.substr(strHref.indexOf("?")+1);
50                         qString = strQueryString.split("&");
51                 }
52           } else {
53                 return null;
54           }
55                 
56           
57           if (qString==null) return null;
58           
59           
60           for (var i=0;i<qString.length; i++){
61                         if (escape(unescape(qString[i].split("=")[0])) == strParamName){
62                                 returnVal.push(qString[i].split("=")[1]);
63                         }
64                         
65           }
66           
67           
68           if (returnVal.length==0) return null;
69           else if (returnVal.length==1) return returnVal[0];
70           else return returnVal;
71         }
72 });