|
14 | 14 |
|
15 | 15 | <script type="text/javascript">
|
16 | 16 |
|
17 |
| -jQuery('#<?php echo $name?>_selector').autocomplete( { source: "<?php echo $baseurl?>/pages/edit_fields/9_ajax/suggest_keywords.php?field=<?php echo $field["ref"] ?>&readonly=<?php echo $readonly ?>", |
18 |
| - select : selectKeyword_<?php echo $name ?> |
19 |
| - }); |
20 |
| - |
21 |
| -var Keywords_<?php echo $name ?>= new Array(); |
22 |
| -var KeywordCounter_<?php echo $name ?>=0; |
23 |
| -var KeywordsTranslated_<?php echo $name ?>= new Array(); |
24 |
| - |
25 |
| -function selectKeyword_<?php echo $name ?>(event, ui) |
26 |
| - { |
27 |
| - // var keyword=document.getElementById("<?php echo $name ?>_selector").value; |
28 |
| - var keyword=ui.item.value; |
29 |
| - |
30 |
| - if (keyword.substring(0,<?php echo strlen($lang["createnewentryfor"]) ?>)=="<?php echo $lang["createnewentryfor"] ?>") |
31 |
| - { |
32 |
| - keyword=keyword.substring(<?php echo strlen($lang["createnewentryfor"])+1 ?>); |
| 17 | +jQuery(document).ready(function () { |
| 18 | + jQuery('#<?php echo $name?>_selector').autocomplete( { source: "<?php echo $baseurl?>/pages/edit_fields/9_ajax/suggest_keywords.php?field=<?php echo $field["ref"] ?>&readonly=<?php echo $readonly ?>", |
| 19 | + select : selectKeyword_<?php echo $name ?> |
| 20 | + }); |
33 | 21 |
|
34 |
| - // Add the word. |
35 |
| - jQuery.post("<?php echo $baseurl?>/pages/edit_fields/9_ajax/add_keyword.php?field=<?php echo $field["ref"] ?>&keyword=" + encodeURI(keyword)); |
36 |
| - } |
| 22 | + var Keywords_<?php echo $name ?>= new Array(); |
| 23 | + var KeywordCounter_<?php echo $name ?>=0; |
| 24 | + var KeywordsTranslated_<?php echo $name ?>= new Array(); |
37 | 25 |
|
38 |
| - addKeyword_<?php echo $name ?>(keyword); |
39 |
| - updateSelectedKeywords_<?php echo $name ?>(true); |
40 |
| - document.getElementById('<?php echo $name ?>_selector').value=''; |
41 |
| - return false; |
42 |
| - } |
43 |
| - |
44 |
| -function addKeyword_<?php echo $name ?>(keyword) |
45 |
| - { |
46 |
| - removeKeyword_<?php echo $name ?>(keyword,false); // remove any existing match in the list. |
47 |
| - Keywords_<?php echo $name ?>[KeywordCounter_<?php echo $name ?>]=keyword; |
48 |
| - KeywordCounter_<?php echo $name ?>++; |
49 |
| - } |
50 |
| - |
51 |
| -function removeKeyword_<?php echo $name ?>(keyword,user_action) |
52 |
| - { |
53 |
| - var replacement=Keywords_<?php echo $name ?>; |
54 |
| - counter=0; |
55 |
| - for (var n=0;n<KeywordCounter_<?php echo $name ?>;n++) |
| 26 | + function selectKeyword_<?php echo $name ?>(event, ui) |
56 | 27 | {
|
57 |
| - if (keyword!=Keywords_<?php echo $name ?>[n]) {replacement[counter]=Keywords_<?php echo $name ?>[n];counter++;} |
| 28 | + // var keyword=document.getElementById("<?php echo $name ?>_selector").value; |
| 29 | + var keyword=ui.item.value; |
| 30 | + |
| 31 | + if (keyword.substring(0,<?php echo strlen($lang["createnewentryfor"]) ?>)=="<?php echo $lang["createnewentryfor"] ?>") |
| 32 | + { |
| 33 | + keyword=keyword.substring(<?php echo strlen($lang["createnewentryfor"])+1 ?>); |
| 34 | + |
| 35 | + // Add the word. |
| 36 | + jQuery.post("<?php echo $baseurl?>/pages/edit_fields/9_ajax/add_keyword.php?field=<?php echo $field["ref"] ?>&keyword=" + encodeURI(keyword)); |
| 37 | + } |
| 38 | + |
| 39 | + addKeyword_<?php echo $name ?>(keyword); |
| 40 | + updateSelectedKeywords_<?php echo $name ?>(true); |
| 41 | + document.getElementById('<?php echo $name ?>_selector').value=''; |
| 42 | + return false; |
58 | 43 | }
|
59 |
| - Keywords_<?php echo $name ?> = replacement; |
60 |
| - KeywordCounter_<?php echo $name ?> =counter; |
61 |
| - updateSelectedKeywords_<?php echo $name ?>(user_action); |
62 |
| - } |
63 |
| - |
64 |
| -function updateSelectedKeywords_<?php echo $name ?>(user_action) |
65 |
| - { |
66 |
| - var html=""; |
67 |
| - var value=""; |
68 |
| - for (var n=0;n<KeywordCounter_<?php echo $name ?>;n++) |
| 44 | + |
| 45 | + function addKeyword_<?php echo $name ?>(keyword) |
69 | 46 | {
|
70 |
| - html+='<a href="#" onClick="removeKeyword_<?php echo $name ?>(\'' + Keywords_<?php echo $name ?>[n] +'\',true);return false;">[ x ]</a> ' + Keywords_<?php echo $name ?>[n] + '<br/>'; |
71 |
| - value+="," + resolveTranslated_<?php echo $name ?>(Keywords_<?php echo $name ?>[n]); |
| 47 | + removeKeyword_<?php echo $name ?>(keyword,false); // remove any existing match in the list. |
| 48 | + Keywords_<?php echo $name ?>[KeywordCounter_<?php echo $name ?>]=keyword; |
| 49 | + KeywordCounter_<?php echo $name ?>++; |
72 | 50 | }
|
73 |
| - document.getElementById('<?php echo $name?>_selected').innerHTML=html; |
74 |
| - document.getElementById('<?php echo $name?>').value=value; |
75 |
| - |
76 |
| - // Update the result counter, if the function is available (e.g. on Advanced Search). |
77 |
| - if( typeof( UpdateResultCount ) == 'function' ) |
| 51 | + |
| 52 | + function removeKeyword_<?php echo $name ?>(keyword,user_action) |
78 | 53 | {
|
79 |
| - UpdateResultCount(); |
| 54 | + var replacement=Keywords_<?php echo $name ?>; |
| 55 | + counter=0; |
| 56 | + for (var n=0;n<KeywordCounter_<?php echo $name ?>;n++) |
| 57 | + { |
| 58 | + if (keyword!=Keywords_<?php echo $name ?>[n]) {replacement[counter]=Keywords_<?php echo $name ?>[n];counter++;} |
| 59 | + } |
| 60 | + Keywords_<?php echo $name ?> = replacement; |
| 61 | + KeywordCounter_<?php echo $name ?> =counter; |
| 62 | + updateSelectedKeywords_<?php echo $name ?>(user_action); |
80 | 63 | }
|
81 |
| - <?php if ($edit_autosave) {?>if (user_action) {AutoSave('<?php echo $fields[$n]["ref"] ?>');}<?php } ?> |
82 |
| - } |
83 |
| - |
84 |
| -function resolveTranslated_<?php echo $name ?>(keyword) |
85 |
| - { |
86 |
| - if (typeof KeywordsTranslated_<?php echo $name ?>[keyword]=='undefined') |
| 64 | + |
| 65 | + function updateSelectedKeywords_<?php echo $name ?>(user_action) |
87 | 66 | {
|
88 |
| - return keyword; |
| 67 | + var html=""; |
| 68 | + var value=""; |
| 69 | + for (var n=0;n<KeywordCounter_<?php echo $name ?>;n++) |
| 70 | + { |
| 71 | + html+='<a href="#" onClick="removeKeyword_<?php echo $name ?>(\'' + Keywords_<?php echo $name ?>[n] +'\',true);return false;">[ x ]</a> ' + Keywords_<?php echo $name ?>[n] + '<br/>'; |
| 72 | + value+="," + resolveTranslated_<?php echo $name ?>(Keywords_<?php echo $name ?>[n]); |
| 73 | + } |
| 74 | + document.getElementById('<?php echo $name?>_selected').innerHTML=html; |
| 75 | + document.getElementById('<?php echo $name?>').value=value; |
| 76 | + |
| 77 | + // Update the result counter, if the function is available (e.g. on Advanced Search). |
| 78 | + if( typeof( UpdateResultCount ) == 'function' ) |
| 79 | + { |
| 80 | + UpdateResultCount(); |
| 81 | + } |
| 82 | + <?php if ($edit_autosave) {?>if (user_action) {AutoSave('<?php echo $fields[$n]["ref"] ?>');}<?php } ?> |
89 | 83 | }
|
90 |
| - else |
| 84 | + |
| 85 | + function resolveTranslated_<?php echo $name ?>(keyword) |
91 | 86 | {
|
92 |
| - return KeywordsTranslated_<?php echo $name ?>[keyword]; |
| 87 | + if (typeof KeywordsTranslated_<?php echo $name ?>[keyword]=='undefined') |
| 88 | + { |
| 89 | + return keyword; |
| 90 | + } |
| 91 | + else |
| 92 | + { |
| 93 | + return KeywordsTranslated_<?php echo $name ?>[keyword]; |
| 94 | + } |
93 | 95 | }
|
94 |
| - } |
95 |
| - |
96 |
| -<?php |
97 |
| -# Load translations - store original untranslated strings for each keyword, as this is what is actually set. |
98 |
| -$options=trim_array(explode(",",$field["options"])); |
99 |
| -for ($m=0;$m<count($options);$m++) |
100 |
| - { |
101 |
| - $trans=i18n_get_translated($options[$m]); |
102 |
| - if ($trans!="" && $trans!=$options[$m]) # Only add if actually different (i.e., an i18n string) |
| 96 | + |
| 97 | + <?php |
| 98 | + # Load translations - store original untranslated strings for each keyword, as this is what is actually set. |
| 99 | + $options=trim_array(explode(",",$field["options"])); |
| 100 | + for ($m=0;$m<count($options);$m++) |
103 | 101 | {
|
104 |
| - ?> |
105 |
| - KeywordsTranslated_<?php echo $name ?>["<?php echo $trans ?>"]="<?php echo $options[$m] ?>"; |
106 |
| - <?php |
| 102 | + $trans=i18n_get_translated($options[$m]); |
| 103 | + if ($trans!="" && $trans!=$options[$m]) # Only add if actually different (i.e., an i18n string) |
| 104 | + { |
| 105 | + ?> |
| 106 | + KeywordsTranslated_<?php echo $name ?>["<?php echo $trans ?>"]="<?php echo $options[$m] ?>"; |
| 107 | + <?php |
| 108 | + } |
107 | 109 | }
|
108 |
| - } |
109 | 110 |
|
110 | 111 |
|
111 |
| -# Select all selected options |
112 |
| -$options=trim_array(explode(",",$value)); |
113 |
| -for ($m=0;$m<count($options);$m++) |
114 |
| - { |
115 |
| - $trans=i18n_get_translated($options[$m]); |
116 |
| - if ($trans!="") |
| 112 | + # Select all selected options |
| 113 | + $options=trim_array(explode(",",$value)); |
| 114 | + for ($m=0;$m<count($options);$m++) |
117 | 115 | {
|
118 |
| - ?> |
119 |
| - addKeyword_<?php echo $name ?>("<?php echo $trans ?>"); |
120 |
| - <?php |
| 116 | + $trans=i18n_get_translated($options[$m]); |
| 117 | + if ($trans!="") |
| 118 | + { |
| 119 | + ?> |
| 120 | + addKeyword_<?php echo $name ?>("<?php echo $trans ?>"); |
| 121 | + <?php |
| 122 | + } |
121 | 123 | }
|
122 |
| - } |
123 |
| -?> |
124 |
| -updateSelectedKeywords_<?php echo $name ?>(false); |
125 |
| - |
| 124 | + ?> |
| 125 | + updateSelectedKeywords_<?php echo $name ?>(false); |
126 | 126 |
|
| 127 | +}) |
127 | 128 | </script>
|
128 | 129 | <?php
|
129 | 130 | /* include dirname(__FILE__) . "/../../include/user_select.php";
|
|
0 commit comments