[Widget] Preloader

A place to share your Plugins and Extensions

[Widget] Preloader

Postby raymond » Mon Jan 03, 2011 12:53 am

Name: Preloader

Description: Use this widget to display a preloader image or text during page post back and Ajax request.

Installation: Copy preloader.php from the attached .zip file to the raxan/ui/widgets folder.

Example:
Code: Select all
<?php

require_once 'raxan/pdi/autostart.php';

// widgets
Raxan::loadWidget('preloader');

// web page
class NewPage extends RaxanWebPage {

    protected function longEvent($e) {
        $this->flashmsg('Message from Long Event');
        sleep(2); // sleep for two seconds
    }

    protected function shortEvent($e) {
        $this->flashmsg('Message from Short Event');
    }
}


?>

<div class="flashmsg"></div>
<form name="form1" action="" method="post">
    <div class="toppnl">
        <input type="submit" name="button1" id="button1" value="Long" xt-bind="#click,longEvent" />
        <input type="submit" name="button2" id="button2" value="Short" xt-bind="#click,shortEvent" />
    </div>
    <div xt-ui="RaxanPreloader" ><img src="views/images/preloader.gif" alt="loader" />&nbsp;Loading...</div>
</form>


In the above example the Preloader should be shown when either the "Long" or "Short" button is clicked.

Widget Source:
Code: Select all
<?php
/**
 * Raxan Preloader Widget
 * Copyright 2010 Raymond Irving
 */
class RaxanPreloader extends RaxanUIWidget {

    protected function _config() {
        $this->properties = array('triggers'=>null);
    }
   
    protected function _prerender() {
        $this->hide();
        $id = $this->elmId;
        $this->page->addScript($this->getScript($id,$this->properties['triggers']));
    }
   
    protected static function getScript($id,$triggers) {
        $fn = $triggers ?
            "Raxan.bind('".Raxan::escapeText($triggers)."','togglecontent'," : "Raxan.togglePreloader(";
        return $fn."function(e,mode){ ".
            "var id = '#$id', ui = Raxan.UI; ".
            "if (!ui.raxPreLoadCnt) ui.raxPreLoadCnt = {}; ".
            "var cnt =  ui.raxPreLoadCnt['$id.']||0; ".
            "if (mode=='on') { cnt++; $(id).show(); } ".
            "else if (mode=='off') { cnt--; if(cnt<=0) $(id).hide(); } ".
            "ui.raxPreLoadCnt['$id.'] = cnt; ".
            "}); ";
    }
}
?>
Attachments
preloader.zip
Preloader (Zip)
(586 Bytes) Downloaded 190 times
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Return to Plugins & Widgets

Who is online

Users browsing this forum: No registered users and 1 guest

cron