Blog

  • Unbind a click event, store it and re-add the event later with jQuery

    My trusty junior developer Sean and I were quite frustrated trying to find a solution online for getting a click event from an element, removing it from the element, then re-adding the event with a condition.

    For example, anything with the css class “remove” should ask “are you sure” before completing the default action. Rather than adding this “are you sure” confirmation script to every remove function on the website, we came up with this following little hack:

    working example:

    <script type="text/javascript"> // the function we want to run when someone clicks a button var myFunction= function() { alert('process button click'); // e.g. ajax call to delete an item }; // bind a click event to our element so the function above runs var obj = $('#obj'); obj.on("click", function(){ myFunction(); } ); </script> This following "post load" script is added to the footer after all other javascript has run <script type="text/javascript"> $(document).ready(function(){ $(".remove").each(function(){ // get all our click events and store them var x = $._data($(this)[0], "events"); var y = {} for(i in x.click) { if(x.click[i].handler) { y[i] = x.click[i].handler; } } // stop our click event from running $(this).off("click") // re-add our click event with a confirmation $(this).click(function(){ if(confirm("Are you sure?")) { // if they click yes, run click events! for(i in y) { y[i]() } return true; } // if they click cancel, return false return false; }) }) }) </script> This may seem a bit weird (why do we store the click events in the variable "y"?) Originally I tried to run the handlers in x.click, but they seem to be destroyed when we call .off("click"). Creating a copy of the handlers in a separate variable "y" worked. I believe this is because the .off("click") method removes the click event from our document, along with the handlers.

  • SMTP Server Windows IIS and PHP (send only)

    1) Adding the SMTP Server

    – Open Server Manager
    – select “Features”
    – click “Add Features” and check “SMTP Server”
    NOTE: The SMTP Server feature might require the installation of additional role services and features. Click Add Required Role Services to proceed with installation.
    – click Next to configure any required role services and features
    – click Install to start the installation.

    2) Setting up SMTP

    – Open IIS
    – click on the server, open the “features view” (at the bottom) – double click “SMTP E-mail” probably under ASP.NET
    – Enter the from address
    – select Deliver to SMTP server
    – check “Use localhost”
    – I recommend putting Authentication settings, specify credentials! (click the ellipsis “…” to enter a username and password)

    3) Configuring SMTP

    – Open command prompt
    – type cd \Windows\System32\inetsrv then hit return
    – type all on one line. This is CASE SENSITIVE. Replace the values for /from (e.g. “you@yourdomain.com”) and the network port, host, userName, and password.

    appcmd set config /commit:WEBROOT /section:smtp /from:you@yourdomain.com /deliveryMethod:Network /network.port:25 /network.defaultCredentials:True /network.host:localhost /network.userName:your_username /network.password:your_password

    I used the from email as the username.

    4)Configure PHP.ini


    SMTP=localhost
    sendmail_from=you@yourdomain.com
    smtp_port=25

    5) Enable Relay for localhost:

    – open iis 6.0 (even if you are on iis7, you should have iis6 on your machine!)
    – right click the virtual server

    Restricting who can send!

    – select the “access” tab
    – click “connection” and Select “Only the list below”
    – add only your server’s i.p. address. The dns lookup can help, type “localhost” or the name of your machine.
    – click “ok” then click “apply”
    – click “Relay…”
    – do the same as above (set to “Only the list below” and add your machine’s i.p. address)
    – I would un-check the ability for remote servers to relay, even if they authenticate… in case some bot brute forces in and then uses your server to send spam.

    6) SEND MAIL WITH PHP!!!

    Test it out. I use PHP mailer.
    (use one of your emails to see if you actually get it. A success does NOT mean it will reach the user!)

    WordWrap = 50; // set word wrap to 50 characters
    $email->isSMTP();
    $email-->Host = 'localhost';
    $email->Port = 25; // 587 and 465 are also common
    $email->Username = 'you@yourdomain.com';
    $email->Password = 'your_password';
    $email->Subject = 'Hello World of SMTP';
    $email->Body = 'This is a test from IIS and PHP';
    $email->AddAddress('your_other_email@genericdomain.com','Your Name');
    $email->From = 'you@yourdomain.com';
    $email->FromName = 'Your Website';

    if($email->send()){
    echo 'ok! I did it! I set up an SMTP server (for sending only)!';
    }
    else
    {
    echo 'Dang... all that work and I\'m still here.
    '.$email->ErrorInfo;
    }

    Good luck! Now make sure you add SPF records for all of your domains. 🙂

    -Frank

  • Mobile First vs Desktop First

    Lately, I have read and heard people talk about mobile first design. This is ridiculous! Even though I like the idea of starting simple and then adding on more features or content, rather than rearranging a large and complex design, so that people can access that content on a smartphone. Sure a growing number of people access the web from their phone more often than from a laptop or desk top computer. This doesn’t mean one should design for mobile first. The audience and the content should dictate the design approach.

    Content first!

    The most effective approach is content first. Sometimes, a mobile landing page should be custom and very targeted. Other times it should have content identical to the desktop website. In either case, the design needs to consider how to present the most important content first, followed by any other content that adds value.

    So, which is it? Design for mobile first or desktop first? There is no right answer, but there are plenty of wrong answers to making content available to desktop and mobile audiences. In either case, the content should be designed to look good on mobile, desktop, and tablet since you never know what device people will use to access your site. Responsive design is one of the best solutions to presenting the same content in different ways.

    One last thing. If you have a different page for mobile, at least give the option to easily go to the desktop site.

    For a design that works well on mobile and desktop, take a look at http://LikeScan.com

  • Your Credit Card Needs a Tin Foil Hat

    I recently discovered something interesting about how PayPass works. I was testing out NFC tags for my website LikeScan.com, when i learned that NFC tags can be read AND written by a smartphone (specific phones that are NFC enabled like the Samsung Galaxy Nexus).

    I was immediately intrigued and decided to do a thought experiment. If I could read the data from a credit card that uses NFC, like those with PayPass, and then write it to a new NFC tag, I could use that NFC tag to pay for things. There is no reason that the copy would not work at a payment terminal! So, i tested it out. I had to try a number of free apps. Some could not understand the protocol, but i found one quickly. Soon after i found one that allows the smartphone to read, then immediately write the data, effectively making a copy. I have yet to test out my new Tag at the grocery store, but i am sure it will work. I wonder if the cashier will give me a funny look.

    Okay, getting past the "scientific" value of what I just discovered, let’s talk about this in practical terms…  this is a huge security concern! If someone wanted to copy your “PayPass” they need to hold the phone right against the card. I tried through my wallet but it did not work. But people have been known to go the extra length to copy credit card magnetic strips, so i don’t see why someone wouldn’t develop a stronger reader that could go through your purse or pocket.

    So how does this all relate to the title of the article?  I am now selling Tin Foil Hats for your credit card. Only $5 plus shipping and handling. Contact me for ordering details.

  • Samsung USB Driver for Galaxy Nexus

    I wanted to load a QR code app onto my new Galaxy Nexus. The Nexus did not appear in Eclipse as a device, and I found that I need to get a USB driver.

    On the Samsung website (http://www.samsung.com/us/support/downloads), they have two options, Verizon (SCH-I515MSAVZW) and Sprint (SPH-L700ZKASPR).

    This is not helpful since I am with Bell. Bell’s version is the Samsung Galaxy Nexus I9250M.

    I chose one at random. The downloads area has a link or tab for software, so the drivers are kind of hidden behind the manuals tab. I had no idea how long it would take to install. It took over an hour on my laptop (Vista, dual core @ 2GHz, 4MB ram).

    Looking into it, there was a folder that appeared and started filling up:
    C:\Program Files\SAMSUNG\USB Drivers
    There were 26 folders in the end!

    If you were expecting to plug in your Galaxy Nexus and run your app within minutes… good luck. I just wanted to give you the right expectation since I didn’t see anyone mention this online yet. I still need to restart my computer, plug in the phone and see if it worked. It’s getting late though. I will update this post once I get a chance.

    In the mean time, take a look at our latest phones:
    Baka Mobile

    P.S. when I say “our latest phones” I mean Baka’s latest phones. That is where I work. They are an independent Bell Mobility dealer.

  • QR Codes and Mobile Pages

    Do you know what a QR code does?  You can create an Einstein-Rosen Bridge (a.k.a. wormhole) by just slapping one on your product packaging. Consumers who scan that code with their smartphone will be instantly transported at light speed through a spooky dimension surrounded in webs of electricity, until they arrive at one of many possible dimensions.

    QR Code for LikeScan.com
    You need to take a look at likescan.com right now. LikeScan will create a safe journey for your customers, where they will land in a world that looks good with videos, social media and more.

    Be careful though. Some people use free QR code generators and create black holes. Customers who scan these codes can land in a dimension where all text is extremely small, forcing them to strain their eyes until they go blind. Poor souls.

    Seriously, you need to create a safe and enjoyable journey for your customers. LikeScan creates a web page optimized for mobile devices. All you need to do is add product information, check a few boxes and BLAMMO, you have a QR code and a QR Page.

    HOLD ON! Click "Like" and "Tweet" below. I have an 11 month old baby to feed and he recently started biting toes.

    So save yourself thousands in development costs. Go to LikeScan and launch your mobile marketing campaign.

    I like how twitter has the large button option.


  • CSS3 Animations

    In the past, we had to use JavaScript to make animations on a page. They would take longer to load and require a lot of extra code and development time.

    With CSS3 you can add an animation with a single line of code! Using progressive enhancement, this can really improve the web experience of your website visitors. (Progressive enhancement means that you take a web design or feature that looks good in an old browser and add modern code, in this case CSS3, which does not affect the appearance in the old browser, but will have an enhanced experience for users that have a browser with support for the modern code.) Take the following links as an example.

    link one
    link two

    Hover over each one. The first will “jump” over with no animation, the second will do the exact same thing, unless you have CSS3 support in your browser. Try it with the latest browser version of Google Chrome or Apple Safari.

    Look at the CSS below. Notice that the “slide” class, a single line of code, gives the second link the CSS3 animation effect.


    <a href="#" class="mover">link one</a>
    <a href="#" class="mover slide">link two</a>

    a.mover{
    display:block;
    padding:0;
    }
    a.mover:hover{
    padding-left:10px;
    }
    a.slide{ -webkit-transition: padding-left 250ms ease-out;}

  • Mobile and Web Technology

    Welcome to my website. I will periodically add posts about web technologies from a business perspective. I hope you will come back to learn about the newest, coolest things happening on the internet along with up and coming technology that can change the way you do business.

    I am a web developer and I can provide you with custom applications to help you be more efficient. My focus is on reaching more people and saving time with web based applications that can integrate with or replace your current systems. Please visit www.frankforte.ca to learn more about Frank.