Anushri Mathur, Author at Codeexecute | Page 2 of 3

Detect Mousewheel events by jQuery

$(function () {
   var isChrome = !!window.chrome && !!window.chrome.webstore; //use to resolve browser compatibilty issue.
   var functionname="mousewheel.focal";
   if(!isChrome)
	functionname="DOMMouseScroll";
   $('Selector').bind(functionname, function{
	var delta = (isChrome) ? e.delta || e.originalEvent.wheelDelta : e.originalEvent.detail;
        if(isChrome && delta < 0){
	     //scroll down in chrome
	 }
        elseif(isChrome && delta > 0){
            //scroll up in chrome
	}
        elseif(!isChrome && delta > 0){
            //scroll down in mozilla
	}
        else{
            //scroll up in mozilla
	}
	return false;
    });
});

 

Grouping of select box options through javascript

Your select box 

<select>
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
<option value="ddd">ddd</option>
<option value="eee">eee</option>
<option value="fff">fff</option>
</select>
<script type="text/javascript">
$(function () {
    var $cont = $('select');
   
    $('select option').each(function () {
        if ($(this).text().indexOf('aaa') === 0 || $(this).text().indexOf('ddd') === 0) {
            $('<optGroup/>').attr('label', $(this).text()).appendTo($cont);
            $(this).remove();
        } else {
            $cont.find('optGroup').last().append($(this));
            $(this).text($(this).text());
        }
    });
    });

</script>
 

LinkedIn Login through Javascript

Requirement- Client Id

// Initialize linkedin API
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
 api_key: CLIENT ID
 authorize: true
 scope: r_basicprofile r_emailaddress
 onLoad: onLinkedInLoad
</script>
<script type="text/javascript">
  // After Authentication of Account
 function onLinkedInLoad() {
 IN.Event.on(IN, "auth", getProfileData);
 }

 //After successfully Login 
 function onSuccess(data) {
 console.log(data);
  
 }

 // Error in API call
 function onError(error) {
 console.log(error);
 }

 // Get the needed Data
 function getProfileData() {
 IN.API.Raw("/people/~:(id,email-address,first-name,last-name,formatted-name)").result(onSuccess).error(onError);
 }
// destroy the session of linkedin
function closeSession(){
 IN.User.logout();
 return true;
}
</script>
<script type="in/Login"></script>

For custom Button

<script type="text/javascript">
//Invoke login window
function liAuth(){
 IN.User.authorize(function(){
 callback();
 });
}
</script>
<input type="button" onclick="liAuth()" value="Login"/>