Plugin Directory

Changeset 157134


Ignore:
Timestamp:
09/23/2009 01:15:17 AM (17 years ago)
Author:
jwriteclub
Message:
  • #86, implemented compression of javascript files using JSMint (jsmin-1.1.1.php)
  • Added a "debug" option to the options page and class
  • Separated startup into a two step bootstrap to reduce the impact of the "init" file.
  • 0.7 Dev 4
Location:
microaudio/trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • microaudio/trunk/jstemplates/microAudio.init.js

    r157112 r157134  
    33// http://compu.terlicio.us/
    44
    5 // First, implment static vars
     5// First, implment minimum vars
    66var ma = {
    77    url:"{[$location]}",
    88    filekey:"{[$key]}",
    9     sidebar:{[$enable_widget]},
    10     files:{
    11             'jquery':'jquery-1.3.2',
    12             'ui':'jquery-ui-1.7.2.min',
    13             'sidebar':'microAudio.widget',
    14             'ma':'microAudio',
    15             'sm':'soundmanager2',
    16             'jplayer':'jquery.jplayer',
    17             },
    18     loaded:false,
    19     jsloaded:"none"
     9    files:{'bootstrap':'microAudio.bootstrap',},
     10    debug:{[$debug]},
    2011};
     12
     13// Second, set logging based on debugging
    2114ma.log = function(string) {
    22     console.log(string);
    23 }
     15    if(ma.debug) console.log(string);
     16};
    2417
    25 // Third, get the onload event, and start running
     18// Third, get the onload event, and bootstrap
    2619onload = function() {
    27     ma.log("Starting microAudio load sequence . . .");
    28     if (ma.sidebar) {
    29         ma.log("Loading sidebar . . .");
    30         ma.JqueryInit(function() {
    31             ma.loadJs(ma.url + "js/" + ma.files.sidebar + "-" + ma.filekey + ".js",function(){ma.WidgetInit();});
    32         });
    33     }
    34    
    35     // Prepare links (simple)
    36     ma.log("Preparing links . . .");
    37     var links = document.getElementsByTagName("a");
    38     for (var i = 0; i < links.length; i++) {
    39         if(links[i].href.indexOf('mp3') != -1) {
    40             links[i].className = "ma-link";
    41             links[i].onclick = ma.ClickInit;
    42         }
    43     }
    44     ma.log("microAudio setup complete . . .");
    45 }
    46 
    47 ma.JqueryInit = function(callback) {
    48     if(ma.jsloaded == "none") {
    49         ma.jsloaded = "loading";
    50         ma.log("Loading files with key: " + ma.filekey);
    51         ma.loadJs(ma.url + "js/" + ma.files.jquery + "-" + ma.filekey + ".js",function(){
    52             ma.log("Loaded jQuery:" + ma.files.jquery + ". . . ");
    53             ma.loadJs(ma.url + "js/" + ma.files.ui + "-" + ma.filekey + ".js",function(){
    54                 ma.log("Loaded jQuery UI:" + ma.files.ui + ". . . ");
    55                 ma.loadJs(ma.url + "js/" + ma.files.sm + "-" + ma.filekey + ".js",function(){
    56                     ma.log("Loaded Player:" + ma.files.sm + ". . . ");
    57                     ma.jsloaded = "done";
    58                     soundManager.onready(function(oStatus){
    59                         if (oStatus.success) {
    60                             ma.log('Yay, SM2 loaded OK!'); 
    61                         } else {
    62                             ma.log('Oh snap, SM2 could not start.');
    63                         }
    64                         if(callback != null) callback();
    65                     });
    66                     soundManager.flashLoadTimeout = 750;
    67                     soundManager.debugMode = true;
    68                     soundManager.consoleOnly = true;
    69                     soundManager.url = ma.url;
    70                     soundManager.reboot();
    71                 });
    72             });
    73         });
    74     } else if(ma.jsloaded == "loading") {
    75         setTimeout(ma.JqueryInit(callback),100);
    76     } else {
    77         if(callback != null) callback();
    78     }
    79 }
    80 
    81 // Start loading code when we've been clicked
    82 ma.ClickInit = function(e) {
    83     e = e||window.event;
    84     var target = e.target||e.srcElement;
    85     ma.log(target);
    86     if(!ma.loaded) {
    87         ma.JqueryInit(function() {
    88             ma.loadJs(ma.url + "js/" + ma.files.ma + "-" + ma.filekey + ".js",function(){
    89                 ma.PageInit();
    90                 ma.Player(target);
    91             });
    92         });
    93         ma.loaded = true;
    94     } else {
    95         ma.Player(target);
    96     }
    97     return false;
    98 }
     20    ma.log("Loading microAudio bootstrapper . . .");
     21    ma.loadJs(ma.url + "js/" + ma.files.bootstrap + "-" + ma.filekey + ".js",function(){ma.bootstrap();});
     22};
    9923
    10024// Loads a js file
    101 ma.loadJs = function(url,callbackFunction) {
    102     ma.log("Requesting file " + url + " with callback " + callbackFunction);
     25ma.loadJs = function(url,c) {
     26    ma.log("Requesting file " + url + " with callback " + c);
    10327    var s=document.createElement("script");
    10428    s.src=url;
     
    10630    var h = document.getElementsByTagName("head")[0];
    10731    if(h) {
    108         if(callbackFunction != null) {
    109             var loadCallback = function() {
    110                 if(this.readyState == 'complete' || this.readyState == 'loaded') callbackFunction();
     32        if(c !== null) {
     33            var lc = function() {
     34                if(this.readyState == 'complete' || this.readyState == 'loaded') c();
    11135            }
    112                 s.onreadystatechange = loadCallback;
    113                 s.onload = callbackFunction;
     36                s.onreadystatechange = lc;
     37                s.onload = c;
    11438        }
    11539        h.appendChild(s);
    11640    }
    117 }
     41};
  • microaudio/trunk/microAudio.admin.php

    r157112 r157134  
    1515        (isset($_POST['ma_download'])) ? $options->download = true : $options->download = false;
    1616        (isset($_POST['ma_enable_widget'])) ? $options->enable_widget = true : $options->enable_widget = false;
     17        (isset($_POST['ma_debug'])) ? $options->debug = true : $options->debug = false;
    1718        (isset($_POST['ma_clear_errors'])) ? $options->clear_errors() : $a;
    1819    }
     
    8384                    <span class="explanatory-text">Whether to include a link next to the flash player to download the file. Marginally increases the javascript size.</span>                   
    8485                </td>
     86            </tr>
     87            <tr valign="top">
     88                <th scope="row">Debug</th>
     89                <td>
     90                    <input type="checkbox" name="ma_debug" id="ma_debug" <?php if ($options->debug) echo "checked"; ?> />
     91                    <label for="ma_debug">Include dedugging information</label>
     92                    <br />
     93                    <span class="explanatory-text">Whether to include debugging information in the code. Significantly increases the code size and runtime.</span>                 
     94                </td>
    8595            </tr> 
    8696        </tbody>
  • microaudio/trunk/microAudio.jsbuilder.php

    r157112 r157134  
    1010            "microAudio.widget",
    1111            "jquery.jplayer",
    12             "soundmanager2"
     12            "soundmanager2",
     13            "microAudio.bootstrap"
    1314            );
    1415
     
    1920set_error_handler('jsBuilderHandler');
    2021
    21 
     22// Include JSMin
     23require_once(dirname(__FILE__)."/jsmin-1.1.1.php");
    2224
    2325// Builds js files for your installation.
     
    5254    }
    5355   
     56    // Replace template tags
    5457    $contents = preg_replace_callback("|(\\{\\[\\$((?:[a-z][a-z_]+))\\]\\})|",'ma_replace_tokens',$contents);
     58   
     59    // Minify
     60    if(!$options->debug) $contents = JSMin::minify($contents);
    5561   
    5662    // Write output js
  • microaudio/trunk/microAudio.options.php

    r157112 r157134  
    2929                        'key',
    3030                        'location',
     31                        'debug',
    3132                        );
    3233   
  • microaudio/trunk/microAudio.php

    r157087 r157134  
    1313<?php
    1414
    15 $MICROAUDIO_VERSION = "0.7 Dev 3";
     15$MICROAUDIO_VERSION = "0.7 Dev 4";
    1616
    1717// Include classes
Note: See TracChangeset for help on using the changeset viewer.