MooTools AJAX : Preserve javascript/Script tags

There are two ways that I know of with Request.HTML. By default, evalScripts is set to true. If you set the ‘update’ to $(‘refresh-box’Smilie: ;), it will work.

    function ajaxRequest(){
        new Request.HTML({
            url: 'post.php',
            update: $('refresh-box')
        }).send();
    }

By default, the method is post and you do not have to specify any data. Normally you would add the ‘data’ in the send() method anyway. Now, this works great for the most part. But, if you are like me, you do more then just update the content within an element. For that, something like the following will work:

    function ajaxRequest(){
        new Request.HTML({
            evalScripts: false,
            url: 'post.php',
            onSuccess: function(html, elements, tree, javascript) {
                $('refresh-box').set('text', '');
                $('refresh-box').adopt(html);
                if (javascript) $exec(javascript);
            },
            onFailure: function() { $('refresh-box').set('text', 'The request failed.'); }
        }).send();
    }
 var myRequest = new Request({
     url: '/addmodule',
     method: 'post',
     onRequest: function(){
         myElement.set('text', 'loading...');
     },
     onSuccess: function(responseText){
         myElement.set('html', responseText);
     },
     onFailure: function(){
         myElement.set('text', 'Sorry, your request failed :(');
     }
 });
 
 var myHTMLRequest = new Request.HTML({
     url: '/addmodule',
     evalScripts : false,
     evalResponse : true,
     onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
         alert(responseHTML)
 
         var sc = '<script type="text/javascript">';
         sc+= responseJavaScript + '</script>';
 
         myElement.set('html',responseHTML).highlight();
     }
 });

Posted in Javascript, MooTools

QShortcut , QKeySequence and variable name as SLOT example code

QShortcut , QKeySequence and variable name as SLOT example code

    QShortcut *m_shortcutHiddenFunct = new QShortcut(QKeySequence(tr("Ctrl+M")),this);
//    m_shortcutHiddenFunct->setKey(key);
 
    connect(m_shortcutHiddenFunct,SIGNAL(activated()) ,this, SLOT(on_shortcut_HiddenFunc_triggered()));
 
//    m_shortcutHiddenFunct->setKey( QKeySequence(tr("Ctrl+m")));
 
     QHash< QString, QHash<QString,QString> > mapper;
 
     QHash<qstring , QString> bookmark;
     bookmark.insert("Next","Ctrl+N");
     bookmark.insert("Previous","Ctrl+J");
 
     mapper.insert("bookmark",bookmark);
 
     QHash</qstring><qstring , QString> editor;
     editor.insert("paste","Ctrl+V");
     editor.insert("cut","Ctrl+X");
 
     mapper.insert("editor",editor);
 
     QHashIterator</qstring><qstring , QHash<QString,QString> > i(mapper);
     while (i.hasNext()) {
         i.next();
         qDebug() < < i.key() << ": " << endl;
 
         QHashIterator<QString, QString> k(i.value());
         while (k.hasNext()) {
             k.next();
             qDebug() < < " \t"<< k.key() << ": " << k.value() << endl;
 
 
             QShortcut *m_shortcutHiddenFunct = new QShortcut(QKeySequence(k.value()),this);
         //    m_shortcutHiddenFunct->setKey(key);
 
//             QString m ="1on_shortcut_HiddenFunc_triggered()";
             QString m("SLOT ( %1_%2() )");
             m= m.arg("%1").arg(i.key());
             m= m.arg("%2").arg(k.key());
             m= m.toLower();
//             qDebug() < < m << k.value() << k.key();
             QByteArray ba = m.toLocal8Bit();
             const char *c_str2 = ba.data();
 
             connect(m_shortcutHiddenFunct,SIGNAL(activated()) ,this, c_str2);
         }
 
     }

Posted in Qt Tagged ,

Mootools form submit error

Mootools form submit error : %5Bobject%20Object%5D.

You should set send before sending, like this:

$('form').set('send',{
       onFailure:function(){console.log('Error')},
       onComplete: function() {
               console.log('Data saved sucessfully!')
       }
 
});
 
$('form').send();

Posted in Javascript, MooTools

How to Import export MySQL database from command line

export

mysqldump -u username -p databasename > filename.sql

import

mysql -u username -p databasename < filename.sql

Posted in MySQL

Check for undefined JavaScript variable

The typeof operator

The “typeof” operator in JavaScript allows you to probe the data type of its operand, such as whether a variable is string, numeric, or even undefined. The below simple example alerts the data type of the variable “myvar”

var myvar=5
alert(typeof myvar) //alerts "number"

Here’s a list of possible values returned by the typeof operator:

Evaluates to Indicates
“number” Operand is a number
“string” Operand is a string
“boolean” Operand is a Boolean
“object” Operand is an object
null Operand is null.
“undefined” Operand is not defined.

So, it doesn’t take a rocket scientist to figure out now how to detect whether a variable is defined (exists) in the script:

if (typeof x=="undefined")
alert("Variable x doesn't exist)
else
// continue with script

Ok, now that you know, why should you know? Well, the ability to find out whether a particular variable is defined or not is not only useful, but essential, in some scripting scenarios.

Posted in Javascript

Set html in all elements having same ids using Jquery

 
//sets html in all ids across the page
$('[id^="'+id+'"]').html();

Posted in Javascript, Jquery

My Bookmark links

General

http://adapt.960.gs/
http://speckyboy.com/2011/04/11/50-free-psd-ui-kits-and-templates-for-web-designers/
http://www.designkindle.com/category/graphics/
http://speckyboy.com/
http://javascriptmvc.com/
http://getqualitycontrol.com/
http://code.google.com/p/sigil/
http://code.google.com/p/fop-miniscribus/

HTML5

http://www.whatwg.org/specs/web-apps/current-work/multipage/index.html#contents

XML validator

http://www.validome.org/xml/validate/

Misc

https://github.com/mleibman/SlickGrid/wiki
https://github.com/rnavarro/CakePHP-cPanel-API-Component/
http://www.openfaces.org/demo/treetable/TreeTable_basicFeatures.jsf http://nicolasgallagher.com/css-background-image-hacks/ http://www.smashingmagazine.com/2010/12/09/journalcrunch-wordpress-3-0-theme-free-theme-for-portfolios-and-magazines/ http://www.smashingmagazine.com/2010/12/23/free-icon-set-for-web-developers-coded/ http://procssor.com/process https://github.com/rnavarro/CakePHP-cPanel-API-Component/ https://github.com/mleibman/SlickGrid/wiki http://www.openfaces.org/demo/treetable/TreeTable_basicFeatures.jsf
http://biasecurities.com/blog/2010/have-jquery-autocomplete-behave-like-google-suggest/

Posted in Featured

Get values inside JavaScript object

 
//data is javascript object with unknown ids
 
//This loop with fetch all index name as well as their values
for (var i in data)
{
    alert('theStatus[\''+i+'\'] is ' + data[i])
}

Posted in Javascript

Get multiple arrays values simultaneously in single loop

 $a = array(1,2,4);
 $b = array('a','b','c');
 
foreach (array_map(null, $a, $b) as $v)
 {
       list($v1, $v2) = $v;
       echo $v1 . $v2 ;
}

Posted in PHP, PHP-Tips

Set value in radio using jquery

$(“input:radio[name='name'][value=1]“Smilie: ;).attr(‘checked’, true);

Posted in Javascript, Jquery