1/** 2 * @version 1.0 3 * 4 * @copyright Copyright 2011 WnG Solutions Sarl, all rights reserved 5 * @author Ulysse Martinot <ulysse [DOT] martinot [AT] wng [DOT] ch> 6 * @package WnG Solutions 7 */ 8 9// Initialisation de l'objet general "WnG" 10if (typeof WnG != 'object') 11 WnG = {}; 12 13 14WnG.dataquery = { 15 16 // Recherche avancée 17 advancedSearch: true, 18 19 /** 20 * Initialisation 21 * 22 * @param void 23 * @return void 24 */ 25 init: function() { 26 27 // Soumission du formulaire 28 // jQuery('#directorySearchForm').submit(function() { 29 // WnG.dataquery.process(); 30 // return false; 31 // }); 32 33 // Recherche avancée 34 jQuery('#directorySearchForm .searchField').after('<div class="advancedSearch"><a href="#">+</a></div>'); 35 //jQuery('#directorySearchForm .checkboxList').hide(); 36 jQuery('input[type=checkbox].tx_wngdirectory_pi1_categories').prop('checked', false); 37 jQuery('#directorySearchForm .advancedSearch a').click(function(){ 38 if (WnG.dataquery.advancedSearch) { 39 jQuery('#directorySearchForm .checkboxList').slideUp('normal', function(){ 40 WnG.dataquery.advancedSearch = false; 41 }); 42 } else { 43 jQuery('input[type=checkbox].tx_wngdirectory_pi1_categories').prop('checked', false); 44 jQuery('#directorySearchForm .checkboxList').slideDown('normal', function(){ 45 WnG.dataquery.advancedSearch = true; 46 }); 47 } 48 return false; 49 }); 50 51 // // Focus du champ de recherche 52 // jQuery('#tx_wngdirectory_pi1_search').focusin(function(){ 53 // if (jQuery(this).val() == WnG.l10n.search_terms) { 54 // jQuery(this).val(''); 55 // } 56 // }).focusout(function(){ 57 // if (jQuery(this).val() == '') { 58 // jQuery(this).val(WnG.l10n.search_terms); 59 // } 60 // }); 61 }, 62 63 64 65 66 67 /** 68 * Evenement à rappeler (DOM) 69 * 70 * @param void 71 * @return void 72 */ 73 eventsCallback: function() { 74 75 // Cache la pagination si necessaire 76 if (jQuery('.directoryListContainer .pagination').size() != 0) { 77 jQuery('.directoryListContainer .pagination').hide(); 78 } 79 80 // Affiche ou supprime le lien pour en voir plus 81 if (jQuery('.wng_directory a.moreLink').size() == 0 && WnG.l10n.display_more) { 82 jQuery('.directoryListContainer').append('<a class="moreLink" href="#">'+WnG.l10n.more+'</a>'); 83 } else { 84 jQuery('.wng_directory a.moreLink').remove(); 85 } 86 87 // Evenement sur le bouton voir plus 88 jQuery('.wng_directory a.moreLink').one('click', function() { 89 WnG.dataquery.process('nextPage'); 90 return false; 91 }); 92 93 }, 94 95 96 97 98 99 /** 100 * Process de recherche 101 * 102 * @param void 103 * @return void 104 */ 105 process: function(action) { 106 107 // ID du formulaire 108 var form_id = '#directorySearchForm'; 109 110 // Nettoie la zone d'erreur 111 jQuery('.wng_directory .errorHandler').html(''); 112 113 // Récupère la valeur du champ de recherche 114 // if (jQuery('#tx_wngdirectory_pi1_search').val() != WnG.l10n.search_terms) { 115 // var search_terms = jQuery('#tx_wngdirectory_pi1_search').val(); 116 // } else { 117 // var search_terms = ''; 118 // } 119 120 // Récupère les valeurs des catégories 121 if (jQuery('input[type=checkbox].tx_wngdirectory_pi1_categories:checked').size() != 0 && WnG.dataquery.advancedSearch) { 122 var categories = []; 123 jQuery('input[type=checkbox].tx_wngdirectory_pi1_categories:checked').each(function() { 124 categories.push(jQuery(this).val()); 125 }); 126 } 127 128 // Page suivante ou nouvelle recherche 129 if (action == 'nextPage') { 130 // Incrémente le compteur 131 WnG.config_ajax.page += 1; 132 // Affiche les éléments suivants 133 WnG.dataquery.displayNext(search_terms, categories); 134 } else { 135 // Réinitialisation du compteur de page 136 WnG.config_ajax.page = 1; 137 // Lance le processus de filtre 138 WnG.dataquery.displaySearch(search_terms, categories); 139 } 140 141 return false; 142 }, 143 144 145 146 147 148 149 /** 150 * Effectue la recherche et affiche les résultats 151 * 152 * @param string search_terms, array categories 153 * @return void 154 */ 155 displaySearch: function(search_terms, categories) { 156 157 // Show loader 158 WnG.dataquery.playLoading('.directoryListContainer'); 159 160 // Construct Ajax query 161 WnG.ajax.getJSON( 162 {method: 'search', 163 page: WnG.config_ajax.page, 164 q: search_terms, 165 cat: categories}, 166 function(data) { 167 168 // Hide loader 169 WnG.dataquery.stopLoading('.directoryListContainer'); 170 171 // Valid content 172 if (data.success == true) { 173 174 // Content manipulation 175 //var jqObj = jQuery(data.content); 176 177 // Display content 178 jQuery('.directoryListContainer').parent().html(data.content); 179 180 // More button 181 if (data.more) { 182 WnG.l10n.display_more = true; 183 } else { 184 WnG.l10n.display_more = false;
185 } 186 187 // Callback events 188 WnG.dataquery.eventsCallback() 189 190 } else { 191 192 WnG.dataquery.handleError(data.content); 193 194 } 195 } 196 ); 197 }, 198 199 200 201 202 203 /** 204 * Affiche les enregistrements suivants 205 * 206 * @param string search_terms, array categories 207 * @return void 208 */ 209 displayNext: function(search_terms, categories) { 210 211 // Show loader 212 jQuery('.wng_directory a.moreLink').replaceWith('<div class="loadingBox"></div>'); 213 WnG.dataquery.playLoading('.loadingBox'); 214 215 // Construct Ajax query 216 WnG.ajax.getJSON( 217 {method: 'search', 218 page: WnG.config_ajax.page, 219 q: search_terms, 220 cat: categories}, 221 function(data) { 222 223 // Hide loader 224 WnG.dataquery.stopLoading('.loadingBox'); 225 jQuery('.directoryListContainer .loadingBox').remove(); 226 227 if (data.success == true) { 228 229 // Content manipulation 230 var jqObj = jQuery(data.content).find('.list').html(); 231 232 // Display content 233 jQuery('.directoryListContainer .list').append(jqObj); 234 235 // More button 236 if (data.more) { 237 WnG.l10n.display_more = true; 238 } else { 239 WnG.l10n.display_more = false; 240 } 241 242 // Callback events 243 WnG.dataquery.eventsCallback() 244 245 } else { 246 247 WnG.dataquery.handleError(data.content); 248 249 } 250 } 251 ); 252 }, 253 254 255 256 257 258 /** 259 * 260 * MISC 261 * 262 **************************************************** 263 264 265 /** 266 * Gestion general des erreurs 267 * 268 * @param void 269 * @return void 270 */ 271 handleError: function(data) { 272 // Affichage de la fenêtre 273 jQuery('.wng_directory .errorHandler').html(data); 274 }, 275 276 277 278 279 280 /** 281 * Désactive le formulaire 282 * 283 * @return void 284 */ 285 playLoading: function(loaderContainer) { 286 // jQuery('.wng_directory').find('input').attr('disabled', true); 287 // if (jQuery(loaderContainer).find('.loader').size() == 0) { 288 // jQuery(loaderContainer).html('<span class="loader"><span class="hideMe">'+WnG.l10n.loading+'</span></span>'); 289 // } 290 // jQuery(loaderContainer).find('.loader').show(); 291 }, 292 293 294 295 296 297 /** 298 * Active le formulaire 299 * 300 * @return void 301 */ 302 stopLoading: function(loaderContainer) { 303 // jQuery('.wng_directory').find('input').attr('disabled', false); 304 // jQuery(loaderContainer).find('.loader').hide(); 305 }, 306 307 308 309 310 311 /** 312 * Callback : Touche enter textbox 313 * - Lance le processus 314 * 315 * @param obj event The event datas 316 * @return void 317 */ 318 // search_keypress_callback: function(event) { 319 // if (event.which == '13') { 320 // WnG.dataquery.process(); 321 // return false; 322 // } 323 // } 324 325}; 326 327 328 329 330/** 331 * Récupère les variables GET d'une URL 332 * 333 * @return associative array 334 */ 335function getUrlVars() { 336 var vars = [], hash; 337 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 338 339 for(var i = 0; i < hashes.length; i++) { 340 hash = hashes[i].split('='); 341 vars.push(hash[0]); 342 vars[hash[0]] = hash[1]; 343 } 344 return vars; 345} 346 347 348 349 350/** 351 * Affiche le contenu de la variable dans le code HTML 352 * 353 * @param mixed data 354 * @return void 355 */ 356function debug(data, label) { 357 if (jQuery('#debug').size() == 0) { 358 jQuery('body').append( 359 jQuery('<div></div>').attr('id', 'debug') 360 ); 361 } else { 362 jQuery('#debug').append("<br />"); 363 } 364 365 if (typeof data == 'object') { 366 if (label) 367 jQuery('#debug').append(label + '<br />'); 368 369 for (var i in data) { 370 if (typeof data[i] == 'object') { 371 jQuery('#debug').append(i + ': {'); 372 debug(data[i]); 373 jQuery('#debug').append('}'); 374 } else { 375 jQuery('#debug').append(i + ': ' + data[i] + '<br />'); 376 } 377 } 378 } else { 379 if (label) 380 jQuery('#debug').append(label + '<br />'); 381 382 jQuery('#debug').append(data); 383 } 384}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.