[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/javascript/ -> dynamic_filters.js (source)

   1  /*
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis is free software: you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19   *
  20   * --------------------------------------------------------
  21   * $Id: dynamic_filters.js,v 1.5.2.1 2007-10-13 22:35:56 giallu Exp $
  22   * --------------------------------------------------------
  23   */
  24  /*
  25  // +----------------------------------------------------------------------+
  26  // | Orginial Code Care Of:                                               |
  27  // +----------------------------------------------------------------------+
  28  // | Copyright (c) 2004 Bitflux GmbH                                      |
  29  // +----------------------------------------------------------------------+
  30  // | Licensed under the Apache License, Version 2.0 (the "License");      |
  31  // | you may not use this file except in compliance with the License.     |
  32  // | You may obtain a copy of the License at                              |
  33  // | http://www.apache.org/licenses/LICENSE-2.0                           |
  34  // | Unless required by applicable law or agreed to in writing, software  |
  35  // | distributed under the License is distributed on an "AS IS" BASIS,    |
  36  // | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or      |
  37  // | implied. See the License for the specific language governing         |
  38  // | permissions and limitations under the License.                       |
  39  // +----------------------------------------------------------------------+
  40  // | Author: Bitflux GmbH <devel@bitflux.ch>                              |
  41  // |         http://blog.bitflux.ch/p1735.html                            |
  42  // +----------------------------------------------------------------------+
  43  //
  44  //
  45  // +----------------------------------------------------------------------+
  46  // | Heavily Modified by Jeff Minard (07/09/04)                           |
  47  // +----------------------------------------------------------------------+
  48  // | Same stuff as above, yo!                                             |
  49  // +----------------------------------------------------------------------+
  50  // | Author: Jeff Minard <jeff-js@creatimation.net>                       |
  51  // |         http://www.creatimation.net                                  |
  52  // |         http://www.creatimation.net/journal/live-request             |
  53  // +----------------------------------------------------------------------+
  54  //
  55  // +----------------------------------------------------------------------+
  56  // | What is this nonsense?? (07/09/04)                                   |
  57  // +----------------------------------------------------------------------+
  58  // | This is a script that, by using XMLHttpRequest javascript objects    |
  59  // | you can quickly add some very click live interactive feed back to    |
  60  // | your pages that reuire server side interaction.                      |
  61  // |                                                                      |
  62  // | For instance, you use this to emulate a "live searching" feature     |
  63  // | wherein users type in key phrases, and once they have stopped typing |
  64  // | the script will automatically search and retrive *without* a page    |
  65  // | reload.
  66  // |                                                                      |
  67  // | In another instance, I use this to product live comments by passing  |
  68  // | the text to a Textile class that parses it to valid HTML. After      |
  69  // | parsing, the html is returned and displayed on the page as the       |
  70  // | user types.                                                          |
  71  // +----------------------------------------------------------------------+
  72  //
  73  //
  74  // +----------------------------------------------------------------------+
  75  // | Modified by Lee O'Mara <lomara@omara.ca>                  12/08/2004 |
  76  // +----------------------------------------------------------------------+
  77  // | Hacked apart Jeff's script for use in Mantis.                        |
  78  // |                                                                      |
  79  // | This script gets filters from the server and displays them without   |
  80  // | reloading the page.                                                  |
  81  // |                                                                      |
  82  // | The script tries to follow the notion of "unobtrusive javascript".   |
  83  // | There are no event handlers in the HTML code. The events are added   |
  84  // | on pageload(based on specific id names).                             |
  85  // +----------------------------------------------------------------------+
  86  //
  87  //
  88  */
  89  
  90  
  91  var processURI    = './return_dynamic_filters.php';
  92  var liveReq = false;
  93  
  94  /**
  95   * Build the XMLHttpRequest and send it
  96   */
  97  function liveReqDoReq() {
  98  
  99      if (liveReq && liveReq.readyState < 4) {
 100          liveReq.abort();
 101      }
 102      
 103      if (window.XMLHttpRequest) {
 104          // branch for IE7, Firefox, Opera, etc.
 105          liveReq = new XMLHttpRequest();
 106      } else if (window.ActiveXObject) {
 107          // branch for IE5, IE6 via ActiveX
 108          liveReq = new ActiveXObject("Microsoft.XMLHTTP");
 109      }
 110  
 111      name = this.id;
 112      liveReq.onreadystatechange = function(){liveReqProcessReqChange(name);};
 113      t_view = document.getElementById('filters_form_open').elements['view_type'].value;
 114      liveReq.open("GET", processURI + "?view_type=" + t_view + "&filter_target=" + this.id);
 115  
 116      // show "Loading..." while waiting
 117      document.getElementById(this.id+'_target').innerHTML = string_loading;
 118  
 119      liveReq.send(null);
 120  
 121      return false;
 122  }
 123  
 124  /**
 125   * Processes the results of the XMLHttpRequest
 126   */
 127  function liveReqProcessReqChange(name) {
 128      if (liveReq.readyState == 4) {
 129          document.getElementById(name+'_target').innerHTML = liveReq.responseText;
 130          replaceWithContent(name);
 131      }
 132  }
 133  
 134  /**
 135   * Strip the tag, leave the content.
 136   */
 137  function replaceWithContent(id){
 138      tag = document.getElementById(id);
 139      if (!tag) return false;
 140      t_parent = tag.parentNode;
 141      if (!t_parent) return false;
 142      for(var i=0; i <tag.childNodes.length; i++){
 143          child = tag.childNodes[i].cloneNode(true);
 144          t_parent.insertBefore(child, tag);
 145      }
 146      t_parent.removeChild(tag);
 147  }
 148  
 149  /**
 150   * Initialise the filter links
 151   */
 152  function labelInit(){
 153      // keep browsers that don't support DOM or
 154      // XMLHttpRequest from getting in trouble
 155      if (document.getElementById &&     (window.XMLHttpRequest || window.ActiveXObject)) {
 156  
 157          t_form = document.getElementById("filters_form_open");
 158          if (!t_form) return false;
 159  
 160          t_links = t_form.getElementsByTagName("a");
 161          if (!t_links) return false;
 162  
 163          for(var i=0; i < t_links.length; i++){
 164              var t_link = t_links[i];
 165              if (t_link.id.substring((t_link.id.length - 7), t_link.id.length) == "_filter"){
 166                  // only attach event handler if a target is found
 167                  if (document.getElementById(t_link.id+'_target')){
 168                      // setup the event handler
 169                      t_link.onclick = liveReqDoReq;
 170                  } else {
 171                      alert("missing target for:" +t_link.id);
 172                  }
 173              }
 174          }
 175      }
 176  }
 177  
 178  addLoadEvent(labelInit);


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics