2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.3 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
27 var stregexp = new RegExp;
29 function initFilter( id ) {
31 filterArray = new Array();
32 filterArray = {/literal}{$tokens}{literal};
34 tempArray = new Array();
35 remvdArray = new Array();
38 selObj = document.getElementById("token"+ id);
41 buildOptions(filterArray);
44 document.getElementById("filter"+id).value = "";
46 //clear the last typed value
50 function filter( ob, id ) {
52 //if the length of str is 0, keep original array as option
53 if ( str.length == 0 ) {
54 buildOptions(filterArray);
55 remvdArray.length = 0;
60 //set up temporary array
61 for ( i = 0; i < selObj.options.length; i++ ) {
62 tempArray[selObj.options[i].value] = selObj.options[i].text;
64 //escape the special character
65 str = str.replace(/([\\"'()\]\[])/g, "\\$1");
67 //case-insensitive regexp
68 stregexp = new RegExp( str, "i" );
70 //remove appropriate item(s)
71 if ( lastVal.length < str.length ) {
72 for ( j = selObj.options.length-1; j > -1; j-- ) {
73 if ( selObj.options[j].text.match( stregexp ) == null ) {
74 //delete unwanted option
75 delete tempArray[selObj.options[j].value];
79 //add appropriate item(s)
80 //if a removed item matches the new pattern, add it to the list of names
81 for ( key in remvdArray) {
82 tempName = remvdArray[key].toString();
83 if ( tempName.match(stregexp) != null ) {
84 tempArray[key] = tempName;
88 //sort the names array
92 //build the new select list
93 buildOptions(tempArray);
96 //remember the last value on which we narrowed
100 function buildOptions( arrayName ) {
101 //clear the select list
102 selObj.options.length = 0;
103 //to select only valid tokens in tokens list
104 var tokenRegx = new RegExp (/{(\w+\.\w+)}/);
106 for ( script in arrayName ) {
107 if ( script.match(tokenRegx) != null ) {
108 var option = new Option( arrayName[script], script );
109 selObj.options[i] = option;
116 function buildRemvd( ) {
117 //clear the removed items array
118 remvdArray.length = 0;
120 //build the removed items array
121 for ( key in filterArray ) {
122 //for filtering tokens
123 remToken = filterArray[key].toString();
124 if ( remToken.match(stregexp) == null ) {
125 //remember which item was removed
126 remvdArray[key] = filterArray[key];
131 function getMatches(id) {
132 if ( selObj.options.length == 1 ) {
133 document.getElementById("match"+id).innerHTML = "{/literal}{ts escape='js'}1 match{/ts}{literal}";
135 document.getElementById("match"+id).innerHTML = selObj.options.length +" {/literal}{ts escape='js'}matches{/ts}{literal}";