Jquery Mobile Widgets

I’d like to continue using zii widgets for the full site then add support for mobile devices. Using jQuery mobile seemed to be the most direct path. I have not yet figured out the best way to use jQuery Mobile instead of jQuery UI for zii widgets. Simply changing a widget’s ‘cssFile’ and ‘scriptFile’ is insufficient. The site detects the use of a mobile device and can switch as necessary. I’ve read that jQuery UI and jQuery Mobile should be able to coexist but in my case and others they interfere with each other. I also tried including the jQuery UI stylesheet before the jQuery Mobile stylesheet as recommended but there is still contention between the two. Adding and modifying jQuery UI styles to jQuery Mobile is tedious and just seems to be the wrong way to solve this problem.

Anyone have ideas? Should zii widgets be replaced with something else when mobile?


I’ve started a small experiment once and my idea was to create widgets for jQueryMobile.

This is not exactly a reply to your question which is about co-existance of jQuery-ui and jQuery-mobile, but the idea is sharing about the ‘jQueryMobile’ topic.

I made a PageWidget for instance:

class JM_PageWidget extends CWidget {

    public $header;

    public $footer;

    public $title;

    public function init() {


    public function run() {



        $pageOptions = array('data-role'=>'page','id'=>$this->getId());

        if(isset($this->title)) {



        echo CHtml::openTag('div',$pageOptions);


        echo CHtml::tag('div',array('data-role'=>'content'),$content);


        echo CHtml::closeTag('div');


    public function renderHeader() {

        if(isset($this->header)) {

            echo CHtml::tag('div',array('data-role'=>'header'),$this->header);



    public function renderFooter() {

        if(isset($this->footer)) {

            echo CHtml::tag('div',array('data-role'=>'footer'),$this->footer);



    public function renderContent() {



And I overloaded CHtml to change the button implementation:

class jHtml extends CHtml {

    public static function button($label='button', $htmlOptions=array()) {

        if(!isset($htmlOptions['name'])) {



        if(isset($htmlOptions['icon'])) {



            Yii::app()->clientScript->registerCss($iconref, ".ui-icon-$iconref {background-image:url({$htmlOptions['icon']});}");



        if(isset($htmlOptions['height'])) {





            "a[name='{$htmlOptions['name']}'] .ui-icon {height:{$h}px; margin-top:{$mt}px;}"

            ."a[name='{$htmlOptions['name']}'] .ui-btn-inner {height:{$h}px;}"




        if(isset($htmlOptions['width'])) {





            "a[name='{$htmlOptions['name']}'] .ui-icon {width:{$h};" // margin-top:{$mt}px;}

            ."a[name='{$htmlOptions['name']}'] .ui-btn-inner {width:{$h}px;}"





        return self::tag('a',$htmlOptions,$label);



and ended up with a different layout:

<!DOCTYPE html>



<meta name="viewport" content="width=device-width, initial-scale=1">

<?php Yii::app()->clientScript->registerCoreScript('jquery');



Yii::app()->clientScript->registerScript('jquery-cors', 'jQuery.support.cors=true',CClientScript::POS_READY);


<title><?php echo CHtml::encode($this->pageTitle); ?></title>



<?php echo $content;?>



Maurizio Domba stated in another post here

I believe this is what I’m facing. I was just hoping this had already been done by now to avoid reinventing the wheel.