Development

Changeset 20260

You must first sign up to be able to contribute.

Changeset 20260

Show
Ignore:
Timestamp:
07/17/09 21:41:49 (4 years ago)
Author:
Yoda-BZH
Message:

* it can now handle player change
* code comments
* options are sorted

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfJqueryMediaPlugin/trunk/lib/helper/JQueryMediaHelper.php

    r20175 r20260  
    2020 
    2121 
    22  
     22/** 
     23 * The jQuery Media Plugin supports unobtrusive conversion of standard markup into rich media content. 
     24 * It can be used to embed virtually any media type, including Flash, Quicktime, Windows Media Player, Real Player, 
     25 * MP3, Silverlight, PDF and more, into a web page. The plugin converts an element (usually an <a>) 
     26 * into a <div> which holds the object, embed or iframe tags neccessary to render the media content. 
     27 * 
     28 * @author Yoda-BZH, yodabzh@gmail.com 
     29 * @param $pId the id of the link 
     30 * @param $pOptions an array of options 
     31 * @param $pHtmlAttributes unused 
     32 * @return javascript code 
     33 */ 
    2334function jq_media($pId, array $pOptions = array(), array $pHtmlAttributes = array()) { 
     35    /** 
     36     * adding javascript files to the headers 
     37     */ 
    2438    $response = sfContext::getInstance()->getResponse(); 
    2539    $response->addJavascript('/sfJqueryMediaPlugin/js/jquery.media.js'); 
     40    /** 
     41     * apparently jquery media doesn't support on-the-fly by-option player change ... 
     42     */ 
     43    $preferences = ''; 
     44    foreach(array('mp3Player', 'flvPlayer') as $player) { 
     45        if(array_key_exists($player, $pOptions)) { 
     46            $preferences .= '    $.fn.media.defaults.'.$player.' = "'.$pOptions[$player].'"'."\n"; 
     47            unset($pOptions[$player]); 
     48        } 
     49    } 
     50    /** 
     51     * sort the options by *key* name 
     52     */ 
     53    ksort($pOptions); 
    2654    $opts = jq_media_compute_options($pOptions); 
    2755    $code = ' 
    2856jQuery(document).ready(function() { 
     57'.$preferences.' 
    2958    jQuery("#'.$pId.'").media({ 
    3059        '.$opts.' 
     
    3564} 
    3665 
    37  
     66/** 
     67 * return a string for a well formated json array 
     68 * @param $pOptions 
     69 * @return a string with the options 
     70 * @author Yoda-BZH, yodabzh@gmail.com 
     71 */ 
    3872function jq_media_compute_options($pOptions) { 
    3973    /** 
     
    4276    $opts = array(); 
    4377    foreach($pOptions as $k => $v) { 
    44         //if($k == 'height' || $k == 'width') { 
    45         //    $v .= 'px'; 
    46         //} 
    4778        switch(gettype($v)) { 
    4879            case 'int' :