Wednesday, November 20, 2013

jQuery - show only current ul

Here the simple explanations with demo.

STEP 1:
<nav>
    <li><a href="#">1.0.0</a></li>
    <li><a href="#">2.0.0</a>
        <ul class='children'>
            <li><a href="#">2.1.0</a>
                <ul class='children'>
                    <li><a href="#">2.1.1</a></li>
                    <li><a href="#">2.1.2</a></li>
                </ul>
            </li>
            <li><a href="#">2.2.0</a>
                <ul class='children'>
                    <li><a href="#">2.2.1</a></li>
                    <li><a href="#">2.2.2</a></li>
                    <li><a href="#">2.2.3</a></li>
                    <li><a href="#">2.2.4</a></li>
                </ul>
            </li>
        </ul>
    </li>
    <li><a href="#">3.0.0</a></li>
    <li><a href="#">4.0.0</a></li>
    <li><a href="#">5.0.0</a></li>
</nav>

STEP 2:
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.2.js'></script>
<script>
$("nav li").find("ul").hide().end().find("a")
// hide all other ul's in the nav
.click(function(e) {
    $(this).parent().siblings().find('ul').fadeOut('fast');
    $(this).parent().children('ul').delay(200).fadeToggle('fast');
});
</script>

STEP 3:
<style>
body {
    font-size: 12px;
    line-height: 16px;
    font-family: "Helvetica Neue", Arial, sans-serif;
    color: #575757;
}
a, a:active, a:visited {
    color:#575757;
    text-decoration:none;
}
a:hover {
    color:#888888;
}
nav {
    font-size: 14px;
    text-transform:uppercase;
    position:relative;
}
.children {
    width:146px;
    top:0;
    position:absolute;
    margin-left: 160px;
}
.selected { color:blue; }
</style>

Demo url : http://fiddle.jshell.net/866UZ/show/

Thanks to fiddle , its learn and run from that site and thanks to jquery :)

Wednesday, November 13, 2013

Get Ajax respone data from outside of success handler

 You must use async false in ajax

<script type="text/javascript">
var ajaxResponse;
    
    $.ajax({
            type: "POST",
            url: "get_price.php",
            async: false,
            data: "var"+var1,
            cache: false,
            success: function(response){
                ajaxResponse  = response;
            }
        });        

alert(ajaxResponse);
</script>
 

Monday, November 11, 2013

Customize facebook's sharer.php

Facebook Share button, or commonly known as sharer.php is the easiest way to share link on Facebook. It is easy to use. You don't need an App ID, and you don't need to include any Facebook dependencies.

Simply : 
http://www.facebook.com/sharer.php?u=http://yoursite.com&t=Here's my customized title

I could dynamically generate customized og tag, but due to Facebook caching mechanism there's almost no point of doing that.

Customize :
http://www.facebook.com/sharer.php?s=100
&p[url]=http://yoursite.com
&p[images][0]=http://yoursite.com/assets/vote.png
&p[title]=My customized title
&p[summary]=My customized summary


open-graph-protocol-examples:
https://github.com/niallkennedy/open-graph-protocol-examples


Debugger:
Debug your url and check everything fine .
Input URL, Access Token, or Open Graph Action ID

https://developers.facebook.com/tools/debug/

og tags:
<head prefix="og: http://ogp.me/ns#">
<meta charset="utf-8">
<title>Structured audio property</title>
<meta property="og:title" content="Structured audio property">
<meta property="og:site_name" content="Open Graph protocol examples">
<meta property="og:type" content="website">
<meta property="og:locale" content="en_US">
<link rel="canonical" href="http://examples.opengraphprotocol.us/audio-url.html">
<meta property="og:url" content="http://examples.opengraphprotocol.us/audio-url.html">
<meta property="og:image" content="http://examples.opengraphprotocol.us/media/images/50.png">
<meta property="og:image:secure_url" content="https://d72cgtgi6hvvl.cloudfront.net/media/images/50.png">
<meta property="og:image:width" content="50">
<meta property="og:image:height" content="50">
<meta property="og:image:type" content="image/png">
<meta property="og:audio:url" content="http://examples.opengraphprotocol.us/media/audio/250hz.mp3">
<meta property="og:audio:secure_url" content="https://d72cgtgi6hvvl.cloudfront.net/media/audio/250hz.mp3">
<meta property="og:audio:type" content="audio/mpeg">
</head>