Day Dreaming

Lord, Change me

jQuery : Error: $(document).ready is not a function

leave a comment

Yes it bloody is!

Quite often when I’m mucking about with WordPress firebug will throw the following error:

jQuery : Error: $(document).ready is not a function

If you see this error it’s because another framework is in conflict with jQuery – most usually in my case it’s mootools or scriptaculous, anyway here’s the work-around.

The people who developed jQuery had the foresight to include a function which makes jQuery play nicely with other frameworks which all use the $ sign as a staple part of their code. Introducing the jQuery.noConflict(); function.

The jQuery.noConflict(); command you can replace the $ sign with the word jQuery throughout your code.

So, for example, instead of using the normal dom ready function: $(document).ready(function() you would use: jQuery(document).ready(function() just don’t forget to call the .noConflict function before this, so the whole shebang would look like this:

<script src=”mootools.js”></script> // this is the conflicting framework

<script src=”jquery.min.js”></script> // this is your jQuery

<script>

jQuery.noConflict(); // start substituting $ for jQuery

jQuery(document).ready(function(){

jQuery.yourjQueryfunctions();

});

</script>

instead of:

<script src=”mootools.js”></script>

<script src=”jquery.min.js”></script>

<script>

$(document).ready(function(){

$.yourjQueryfunctions();

});

</script>

  1. <script src=“prototype.js”></script>
  2. <script src=“jquery.js”></script>
  3. <script>
  4. jQuery.noConflict();
  5. jQuery(document).ready(function(){
  6. jQuery(‘div’).stuff();
  7. //notice, that the $sign has been replaced with the word jQuery
  8. });
  9. // And you can use Prototype with $(…)
  10. $(‘id’).hide();
  11. </script>


    Written by admin

    September 26th, 2011 at 7:11 am

    [for work] newsletter and poster design -v-

    leave a comment

    very girlish~

    Written by admin

    September 15th, 2011 at 2:07 pm

    a replacement for file_get_contents

    leave a comment

    The newer versions of PHP has disallowed the use of file_get_contents(especially when you are using a hosted environment). here’s a quick work around for this issue, include the following class in your code

    <?php
    class CA_HTTP {

    public static function get_contents($url) {
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    ob_start();
    curl_exec ($ch);
    curl_close ($ch);
    return ob_get_clean();
    }

    }
    ?>

    and use it like the following:

    <?php
    class CA_HTTP {

    public static function get_contents($url) {
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    ob_start();
    curl_exec ($ch);
    curl_close ($ch);
    return ob_get_clean();
    }

    }
    ?>

    Written by admin

    August 15th, 2011 at 10:34 am

    Newletter design

    leave a comment

    for work ^^

    Written by admin

    August 12th, 2011 at 11:57 am

    [facebook code]Check if the user liked your page…

    leave a comment

    function parsePageSignedRequest() {
    if (isset($_REQUEST['signed_request'])) {
    $encoded_sig = null;
    $payload = null;
    list($encoded_sig, $payload) = explode(‘.’, $_REQUEST['signed_request'], 2);
    $sig = base64_decode(strtr($encoded_sig, ‘-_’, ‘+/’));
    $data = json_decode(base64_decode(strtr($payload, ‘-_’, ‘+/’), true));
    return $data;
    }
    return false;
    }
    if($signed_request = parsePageSignedRequest()) {
    if($signed_request->page->liked) {
    echo “This content is for Fans only!you can see this message:)”;

    } else {
    echo “Please click on the Like button to view this tab!”;
    }
    }
    ?>

    Written by admin

    August 5th, 2011 at 1:38 pm

    can connect to localhost but not phpmyadmin(socket configuration)

    leave a comment

    Error description:user can use 127.0.0.1 to get into the default page but while connect to 127.0.0.1/mysqladmin, user will encounter a “socket configuration wrong” error.
    to solve this, just find the following file,
    wamp->apps->phpmyadmin3.3.5->config.inc.php
    change
    $cfg['Servers'][$i]['verbose'] = ‘localhost’;
    $cfg['Servers'][$i]['host'] = ‘localhost’;
    to
    $cfg['Servers'][$i]['verbose'] = ‘127.0.0.1′;
    $cfg['Servers'][$i]['host'] = ‘127.0.0.1′;

    Written by admin

    August 2nd, 2011 at 1:43 pm

    UTF8 encoding not displaying properly?

    with 68 comments

    Open the web page file in notepad, click “save as”, choose “utf-8″ as its encoding instead of ANSI, “save as” file type set to “all files”
    –Done!

    Written by admin

    July 18th, 2011 at 1:59 pm

    PHP mail sending encoding problem

    with one comment

    While using PHP mail() function, if the mail contains non-alphabetical characters, use the following function for a correct display of characters.

    <?php

    function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') {
    $header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";
    mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
    }

    ?>

    Written by admin

    July 14th, 2011 at 12:40 pm

    Faith

    with 25 comments

    I used to think, Faith means “I believe that God will do something for me(something I want)”.

    But actually faith means,”believe in what God will do for you”.

    The real faith will never fail, because it makes you accept whatever you face.

    It sounds like “im a dead pig anyway so boil me” kind of speech, but I believe our attitude should be more like “since it happened already, let us not be discouraged and strive for something better to come”.

    I was thinking about this when I was on the bus.

    Written by admin

    July 13th, 2011 at 2:05 pm

    Some design works

    leave a comment

    Book cover design done for a friend a while ago.

    Tokyo sunshine chinese church I used to go when I was in Japan is recently planning an inhouse camp, Here’s a poster I designed for this event. Wanna join lol.

    Written by admin

    July 9th, 2011 at 12:39 pm