Ajax Request JS

thread: 2 messages  |  last: about 11 months ago  |  started: wednesday, may 23, 2012, 10:32 am pdt


#1  |  Leonardo (Minas Gerais) Brazil
Wednesday, May 23, 2012, 10:32 AM PDT

Hello every one,
So, i build one custom QControl, and this QCUstomControl there is 2 library JS ans 1 file CSS. For include this files  I set the $strJavaScripts ans $strStyleSheets, of course that it is into the class of QCUstomControl, and this QCustomControl work i execute one code  javascript that call a library's function that include.

But when i request ajax event and this ajax event rendered my QCustomControl is execute frist my code javascript that call a library's function and the library is no loaded, so appear error obivoius.

The think the solution if execute javascript that call a library's function after library loaded but i don't get ons solution fot this.

someone suggest me something.

My QCutomControl

<?php

    
class QMarkItUp extends QTextBox {
        
        protected 
$strTextMode QTextMode::MultiLine;
        protected 
$strJavaScripts 'jquery.js, markitup/jquery.markitup.js, markitup/sets/default/set.js';
        protected 
$strStyleSheets 'markitup/sets/default/style.css, markitup/skins/markitup/style.css';
        
        public function 
__construct($objParentObject$strControlId null) {
            
parent::__construct($objParentObject$strControlId);
        }        
        
        
        public function 
GetEndScript() {
            
QApplication::ExecuteJavaScript("$('#".$this->ControlId."').markItUp(mySettings);");
            return 
parent::GetEndScript();

        }                
    
    }

?>
.bc
#2  |  Leonardo (Minas Gerais) Brazil
Thursday, May 24, 2012, 6:08 AM PDT

Hello People, I am a solve this problem i get a code javascript that run after load library, is a kind of $Jquery.ready(), but without Jquery Look

        public function GetEndScript() {
            QApplication::ExecuteJavaScript("  
                function ready(func) {
                    var span = document.createElement('span');
                    var ms = 0;
                    setTimeout(function() {
                        try {
                            document.body.appendChild(span);
                            document.body.removeChild(span);
                            func();
                        } catch(e) {
                            setTimeout(arguments.callee, ms);
                        }
                    }, ms);
                }
                ready( function(){ $('#".$this->ControlId."').markItUp(mySettings);  } );
            "); 
            return parent::GetEndScript();

        }                

But appeared other problem, my QCustom Control call a library Jquery and a plugin Jquery so the order that include each one them is very important, Jquery always load before that JqueryPlugin else happen error javascript.

The question is when QCustomCOntrol Render into a QForm the order that librarys load is one, and when QCustomControl Render from the event Ajax the order librarys load is other, more exaclty is reverse.

my solution is into class QFORMBASE line 370 i chage for this

                   $strJavaScriptToAddArray = array_merge($strJavaScriptToAddArray, array_reverse ($strScriptArray));

put array reverse, but i think that this change could come in the package already Qcodo.
 



Copyright © 2005 - 2013, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.