Cestfait.ch

  • Home
  • Drupal
  • PHP 5
  • Jquery
  • Web Dev
  • Sys admin
  • Logiciels libres
  • Videos
  • Divers
  • Nous contacter
  • Mon c'est fait!
Home

[Drupal] créer des functions javascript a la volée!

Submitted by Sir Squall on Wed, 09/16/2009 - 17:12

Sa peut être pratique on sais jamais :)!
Dans mon cas je m'en suis servi car j'avais un petit flash qui renvoi les valeurs a une fonction javascript et ce petit flash apparait pour chaque champs cck de type number, ce qui fait que quand j'en ajoutai 1 bah je devais aller ajouter la fonction javacript a la main! Pas super combo :( !!

Donc je crée des functions automatiquement avec le nom de mon champ cck, ce qui fait que je me retrouve avec des function field_price(){ alert('yeah'); } ect.. et que dans mon flash le nom de la fonction et renseigner automatiquement yeah!

function search_engine_display_block_2(){
  $path = drupal_get_path('module', 'search_engine');
  if(arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))){
    //get type
    $type = search_engine_get_type(arg(2));
    //load cck field
    $content_type = content_types($type);
    $fields = $content_type['fields'];
 
    foreach($fields as $field => $value){
      //add flash for all number and integer
	    switch($value['type']){
        case 'number_integer':
        case 'number_float':
          //load value max
          $sql = "SELECT MAX(".$value['field_name']."_value) AS max FROM {content_type_".$type."} ";
        $data = db_fetch_object(db_query($sql));
        //arrondi a la centaine supérieur
        $data->max = ceil($data->max/100)*100;
 
        //create function javascript to get value
        $js .= " function ".$value['field_name']."(data) {
                  if(typeof json == 'undefined'){
                     var json = new Object();
                  }
                   json.".$value['field_name']." = data; 
                  var encoded = JSON.stringify(json);
                   Drupal_json_form.fields = encoded; 
                  search_engine_ajax_load();
                }\n";
 
        //Affiche le flash
        $out .= '<div id="FlashPrix" class="se_option" style="padding: 5px 0px 0px; width: 210px;">';
        $out .= '<object id="sliderMono1" height="80" align="middle" width="210" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">';
        $out .= '<param value="sameDomain" name="allowScriptAccess"/>';
        $out .= '<param value="'.base_path().$path.'/sliderMonoVente.swf" name="movie"/>';
        $out .= '<param value="high" name="quality"/>';
        $out .= '<param value="#ffffff" name="bgcolor"/>';
        $out .= '<param value="showall" name="scale"/>';
        $out .= '<param value="transparent" name="wmode"/>';
        $out .= '<param value="unitName='.$value['prefix'].'&startPos=0&endPos='.$data->max.'&funcName='.$value['field_name'].'&algorithm=linear&id=1" name="FlashVars"/>';
        $out .= '<embed height="80" align="middle" width="210" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true" type="application/x-shockwave-flash" allowscriptaccess="sameDomain" name="sliderMono1" bgcolor="#ffffff" quality="high" flashvars="unitName='.$value['prefix'].'&startPos=0&endPos='.$data->max.'&funcName='.$value['field_name'].'&algorithm=linear&id=1" src="'.base_path().$path.'/sliderMonoVente.swf"/>';
        $out .= '</object>';
        $out .= '</div>';
        break;
	    }
    }
 
    drupal_add_js($js,'inline');
 
    return $out;
  }
 
  return false;
 
}

C'est fait !!!



http://api.drupal.org/api/function/drupal_add_js
0
Log in to vote
Your rating: None Average: 1 (1 vote)
  • Login or register to post comments
  • Share this
Tags:
  • Drupal
  • jquery

User login

  • Create new account
  • Request new password
  • Sign in with Twitter

Translate

Sondage

Qu'elle version de drupal utilisez-vous ?

Submitted by Sir Squall on Tue, 04/10/2012 - 16:30
  • Login or register to post comments

Recent comments

  • Arf, je suis à l'armée!
    40 weeks 1 day ago
  • hahaha c'est juste! Il n'y a
    46 weeks 4 days ago
  • yeah comme sa fait plaisir de
    46 weeks 6 days ago
  • wouahou merciii :-) !
    50 weeks 5 days ago
  • J'y réponds aujourd'hui ici
    50 weeks 5 days ago
  • Salut, court article mais
    50 weeks 6 days ago
  • Oktoberfest power!!!
    1 year 3 weeks ago
  • yep je vais faire un petit
    1 year 5 weeks ago
  • It's regular approuved
    1 year 5 weeks ago
  • Pas d'exemple????
    1 year 5 weeks ago

Tags

cropping Divers drupal Drupal emacs firefox gmap Google Images Jquery jquery karmic koala La phrase du jour Lausanne Logiciels libres mysql PHP 5 RPG Sys admin ubuntu Web Dev yasnippet youtube Zend
more tags

Popular content

Today's:

  • Squall Beer Challenge '09
  • viportuguese-shop.com
  • 8ème Forum eCulture - ERACOM - 4 septembre 2009
  • Grep afficher les lignes avant et après
  • Emacs Transparent
  • Boxxy likes Drupal
  • Bash scripting MySql
  • Drupal Mollom sa rox!
  • Drupal and Zend, form validate :)
  • Tinymce styles sorted

All time:

  • Drupal 7 effet avec les jquery.ui.dialog sur Drupal 6 !
  • Dries Keynote DrupalCon Paris 2009
  • Drupal bridge zend yeah !!
  • Jquery slider c'est de la bonne !!!
  • Drupal and Zend, form validate :)
  • Jquery JSON en _POST
  • [Drupal] Lightbox avec une gmap! yeah
  • [Drupal] Domain Access & memcache sa donne quoi ?
  • viportuguese-shop.com
  • Node Import et Taxonomy CSV

Last viewed:

  • Drupal, CDN pour les images
  • forcer le téléchargement
  • Star wars jay-z
  • Drupal and Zend, form validate :)
  • Drupal bridge zend yeah !!
  • Drupal 7
  • Drupal solr attachement intégration
  • [Drupal 6] textarea avec wysiwyg
  • Dompter IE7 IE8
  • directory_separator, un truc old-skool a jeter

Twitter

Latest Articles

Derniers liens publiés

  • Get the list of all enabled module
    http://drupal.org/node/440962
  • Cloudflare et Dropbox nommés Technology pioneers
    http://techcrunch.com/2011/09/01/cloudflare-dropbox-palantir-and-kickstarter-named-technology-pioneers-by-the-world-economic-forum/
  • Apprend le javascript en t'amusant
    http://www.codecademy.com
  • EPSACrop sur Drupal 7
    http://www.aswissidea.org/
  • Drupal solr attachement intégration
    http://tika.apache.org/

Pub

Google gadget

Add to Google

Facebook page

jiwa

all good song

Partenaires

Cyber Warfare

Drupal Factory

Dev Factory

I love Smashing Magazine!
Fervens Drupal theme by Leow Kah Thong. Designed by Design Disease and brought to you by Smashing Magazine.