Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Tuesday, November 25, 2014

Instagram Photo Cycler JavaSscript widget


A while ago I built for the company I work for a nice Dashboard presenting business and operational data on a TV.

I wanted to add to the Dashboard something cool that will drive people to be more creative.

I had an idea of showing on the dashboard Instagram photos of the company by posting photos to a predefined hashtag. For example: #mycompany.

There was one problem: the real-estate on a dashboard TV screen is very expensive and you can not show more then a single photo.

I remembered that I once encountered a cool JavaScript widget that simply cycles photos with nice transition effects. I thought that it will be nice to connect this widget with Instagram and put it on the dashboard.

Back then I didn't know that I can also get the assistance of Instafeed.js in order to get Instagram data easily, so I had to write this part my self.

The result was pretty cool, so I decided to make a jQuery widget from it to allow others to use it as well. You can download the widget and use it for your own photos or for showing photos of some hashtag.

Here is how the widget looks like for the hashtag #love:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://cdn.rawgit.com/malsup/cycle/master/jquery.cycle.lite.js" type="text/javascript"></script>
<script src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4anFQam9reXhyNWc" type="text/javascript"></script>

<br />
<div id="instagramCyclerCoderEyeLove" style="width:320px; height:320px;">
</div>
<script language="JavaScript">
 <!--

  $(document).ready(function() {
   $('#instagramCyclerCoderEyeLove').cycleInstagram({
    'get':   'tagged',
    'tagName':  'love',
    'accessToken': '161840.f92bbd9.e0a09d9b00f746c8b2662a4e784e55b0'
   });
  });

 </script>

And here is the result:

In order to show your own photos you can use the property "get" with the "user" value. Please note that in order to show you own photos, you can simply use for "userId" the word "self". In addition you can see how you can show more than just a photo and even control look of the widget very easily with the "template" property and simple usage of CSS:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://cdn.rawgit.com/malsup/cycle/master/jquery.cycle.lite.js" type="text/javascript"></script>
<script src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4anFQam9reXhyNWc" type="text/javascript"></script>

 <style>
  #instagramCyclerCodeEyerUser {
   background-image: url("https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4a1JVbTNoY0N0T0U"); 
   background-size: cover; 
   width:326px; 
   height:380px;
  }

  #instagramCyclerCodeEyerUser img {
   padding-top:28px;
   padding-left:36px;
  }

  #instagramCaption {
   margin-top:25px;
   padding-left:36px;
   font-size:18px;
   font-family: ‘Lucida Sans Unicode’, ‘Lucida Grande’, sans-serif;
   width: 250px;
   white-space: nowrap;
   overflow: hidden;
   text-overflow: ellipsis;
  }

 </style>

<div id="instagramCyclerCodeEyerUser"></div>
<script language="JavaScript">

  $(document).ready(function() {
   $('#instagramCyclerCodeEyerUser').cycleInstagram({
    'get':   'user',
    'userId':  'self',
    'tagName':  'todacellmon',
    'accessToken': '161840.f92bbd9.e0a09d9b00f746c8b2662a4e784e55b0',
    'template': '<div><a href="{{link}}"><img src="{{image}}" width="250" height="250" /></a><div id="instagramCaption">{{caption}}</div></div>'
   });
  });

 </script>


Here is the result:

PLEASE NOTE: In order to use Instagram API, you should create an access token. You have nothing to worry that others can see your access token as long as you create an access token only for READING. Frankly, creating the access token on Instagram, at least at the time that I did it, was not a simple task. You can find more help on how to do it on Instagram developers section or on this url

DOWNLOAD: Here you can download the widget

Tuesday, March 15, 2011

Getting radio button value from radio group using jQuery

Getting radio button value from a group of radio buttons is an easy task using jQuery. All you have to do is to apply the correct selector. If we have a group of radio buttons named: radioGroup all if we have to do is:
$('input[name=radioGroup]:checked').val();
Let's have a look how it looks on a real HTML page containing 3 radio buttons and a check button. By clicking the “Check Value” button we will open an alert popup showing the selected radio value:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> TEST </title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
</head>
<body>  
  <input type="radio" id="inpSmall" name="radioGroup" value="small" checked><label for="inpSmall">Small</label><br>
  <input type="radio" id="inpMedium" name="radioGroup" value="medium"><label for="inpMedium">Medium</label><br>
  <input type="radio" id="inpLarge" name="radioGroup" value="large"><label for="inpLarge">Large</label><br><br>
  <input value="Check Value" type="button" onclick="alert('Radio group value: ' + $('input[name=radioGroup]:checked').val());">
</body>
</html>

Monday, December 7, 2009

Automatically focus first input field using JQuery

jQuery is a well know JavaScript framework. It has core libraries which contains many useful out of the box functions, that makes JavaScript code writing much better, easier, cleaner and cross browser. On top of jQuery there are many ready to use widgets and components that can be integrated into your web application in relatively short time. jQuery core js can be downloaded from jQuery main site, but it is much easier calling Google CDN (content delivery network) for getting jQuery. For example, if you want to use jQuery version 1.3.2 you can simply request this link:

http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js

or, as a JavaScript tag:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

Google has wide range of jQuery versions for your selection. It also offers additional frameworks and libraries as well (like MooTools, Yahoo UI and more). You can find more material about it in Google AJAX Libraries API.

Automatically focusing the first input field in web page that contains a form is a small but important feature in terms of user experience. Doing it in jQuery is an easy task:

<script type="text/javascript">
  $("input:text:visible:first").focus();
</script>

Of course, this code should be put after your form fields to function properly.

Note that the code is generic and doesn’t relate to any specific element id on the page.

Saturday, November 7, 2009

Using jQuery with JSF

JSF is using its own ids naming convention in order to prevent duplicate ids on the generated HTML page. JSF uses “:” as id separator. When you wish to use jQuery with JSF, this raises a problem: jQuery uses the “:” character in it’s core libraries as a selector of elements. Therefore, suppose we have a field named: someInput, which used in a form named: someForm, JSF will name the field in the resulted HTML as: someForm:someInput. In order to get the filed element in JQuery we should do:

var value = $('#someForm:someInput').val();
But, unfortunately jQuery treats the “:” character as a special character and therefore misunderstands our request. In order to override this problem, jQuery allows escaping the “:” character. escaping is done by putting “\\” before the “:”. In our example it will look like:
var value = $('#someForm\\:someInput').val();