Showing posts with label Media. Show all posts
Showing posts with label Media. Show all posts

Tuesday, September 28, 2010

AnythingSlider

I've been working on improving the AnythingSlider jQuery plugin by Chris Coyier of CSS-Tricks.com. The project was moved to github, so you can always get the latest version there... My version is up to 1.4 and you can check out a demo of it here - try starting both YouTube videos, then start the slideshow (doesn't work in Internet Explorer properly).

Features include:
  • Panels are HTML Content (can be anything).
  • Multiple AnythingSliders allowable per-page.
  • Infinite/Continuous sliding (always slides in the direction you are going, even at "last" slide).
  • Optionally resize each panel (specified per panel in css).
  • Optional Next / Previous Panel Arrows.
  • Use keyboard navigation or tabs that are built and added dynamically (any number of panels).
  • Link to specific slides or go forward or back one slide from static text links
  • Each panel has a hashtag (can link directly to specific panels).
  • Optional custom function for formatting navigation text.
  • Auto-playing slideshow (optional feature, can start playing or stopped)
  • Pauses playing YouTube videos when not in view and resumes them when in view (only in non-IE browsers & if files are hosted on the web).
  • If slideshow is active, a playing video will complete before the slideshow continues.
  • Pauses slideshow on hover (optional).
  • Optionally play the slideshow once through, stopping on the last page.

Wednesday, June 30, 2010

ImageHighlighter v1.01

ImageHighlighter is an updated version of my original imgHighLighter plugin with lot of improvements! Most are under the hood so you probably won't see too much of a difference on the surface.

This plugin allows you to highlight a portion of an image when you hover over a link. In the image below, the mouse is hovering over the different links and you can see the corresponding portion of the image becomes highlighted (there is an animate gif below, but just click on the image to go to the demo page).
I set up an demo page here.

Download: Uncompressed | Minified | Zipped Demo | Github

I have tested this plugin in IE8, Firefox and Chrome. Please leave me feedback if you any problems with how it works or if it doesn't work in other browsers.

7/6/2010: Updated this post to describe v1.01 where the editor portion of the script was moved into a plugin extension. And support for jCrop was added to allow selecting the entire box instead of just getting the mouse coordinates. Check out the updated demo page!

Setup
  • This plugin requires jQuery.
  • HoverIntent is an optional plugin, this plugin will use it's functionality if it is included.
  • Follow this basic template with a quick summary for each image you want to apply imageHighlighter functionality. For more details, go to the specific section.

    HTML
    <div>
    <ul class="imgHL">
    <li>
    <a href="#" rel="sx1,sy1,ex2,ey2">Item #1</a>
    <p>Description for item #1</p>
    </li>
    <li>
    <a href="#" rel="sx1,sy1,ex2,ey2">Item #2</a>
    <p>Description for item #2</p>
    </li>
    <li>
    <a href="#" rel="sx1,sy1,ex2,ey2">Item #3</a>
    <p>Description for item #3</p>
    </li>
    </ul>
    <br>
    <img id="imgHL" src="myimage.jpg" alt="" />
    <div class="description"></div>
    </div>
    • In the HTML above, the highlight links are all wrapped in a div with a class name "imgHL" to make them easier to target.
    • The highlight links (<a>) must contain a rel attribute with the highlight box coordinates (see the Highlights section below for more detail).
    • Each link/description pair is wrapped together (inside an <li> in this case). See the Descriptions section below for more details.
    • The image is the central element. Once the script is initialized, the image will contain all of the plugin information. It is also the target of both the imageHighlighter and imageHighlighterEditor scripts.
    • The highlight description will be placed into the div with class "description". You can target a different class/Id when you modify the script options.

    CSS (basic example)
    /* List link: currently hovered/selected */
    a.current { color: #fff; }
    
    /* Hide & Position Descriptions */
    .imgHL p { display: none; }
    .description { margin: 1em auto; clear: both; width: 450px; height: 2.4em; }
    
    /* General imageHighlighter (overlay and highlight) */
    .imageHighlighter, .imgHLDark, .imgHLLight, .imgHLOverlay { padding: 0; margin: 0; } /* overlay and highlight divs */
    .imgHLOverlay { background: #000; opacity: .5; filter: alpha(opacity=50); } /* overlay color & opacity *
    • When a link is hovered and the image reveals the highlight box, the class "current" is applied to the link. You can use this to style the link and make it stand out.
    • The css definition ".imgHL p" hides the descriptions that appear under the image (in this example). The description is moved into the ".description" element when the highlight link is hovered.
    • The description class can be placed anywhere on the page; but because of this, the class name ".description" must be unique for each imageHighlighter instance on the page. You can easily modify this class name using the plugin options.
    • The general imageHighlighter definitions apply to the div wrapping the image (.imageHighlighter), the overlay (.imgHLOverlay & .imgHLDark) and the highlighted box (.imgHLLight). As you can see, the overlay has a background color and 50% opacity to darken the image behind the highlight. This can be set to transparent here in the CSS or disabled using the script.

    Javascript
    /* window load ensures all images are loaded */
    $(window).load(function(){
    $('#imgHL').imageHighlighter({
    list : '.imgHL a'
    });
    })
    • This script uses "window.load" instead of "document.ready" to ensure that all images have been loaded. This is necessary as the script needs the image dimensions in order to initialize properly.
    • In this basic example, the highlight links are targeted using the ".imgHL" div that wraps the entire list. The default list setting is "a" which is much too general to use, but the script will ignore any link that doesn't contain a rel tag.
    • There are more options that can be set. For a full list and detailed descriptions, look under the customizing/options section!

  • Highlights: The highlight link's "rel" attribute contains all the information needed for the highlights.
    rel="sx1,sy1,ex2,ey2"
    sx1Starting X position of the highlight box } top left corner
    sy1Starting Y position of the highlight box
    ex2 Ending X position of the highlight box} bottom right corner
    ey2Ending Y position of the highlight box
    You can change the highlight properties of each image using: borderColor, borderSize & borderType described in the Customizing/Options section below.

  • Image: The image must be targeted when initializing the script. You could target the class ('.imgHL') in the example above and the script will initialize once it has found the image from that group of selections. The image contains all of the data associated with this plugin, from using the built in methods to targeting custom events.
    $("#imgHL").imageHighlighter();
  • Descriptions: Each link/description pair should be wrapped together. In the demo where the links are in a paragraph, the link/description pairs are wrapped in a span:
    <span><a rel="sx1,sy1,ex2,ey2">Item #1</a><span class="desc">Description for Item #1</span></span>
    In the other example, the pair are wrapped inside of a list (<li>). Make sure that the descriptions are hidden and targeted by the "descrip" plugin option. The script will look inside the link highlight wrapper, so you don't necessarily have to have a specific class assigned to it as long as the element is unique (e.g. don't have two <p>'s inside with the highlight link otherwise the contents of both will be displayed in the description.

    The second part of the description is set using the "descripClass". The descriptions for the highlight will appear inside an element with this class, when hovering over a link. It can be located anywhere on the page, but the class/id needs to be set in the plugin options and unique for each instance of the plugin.

  • Overlay: The overlay covers the image (darkens the background) to make the highlighted portion stand out more. You can adjust the opacity of this overlay in the CSS and you can turn off the overlay functi0nality by setting the overlay option to false.
Customizing / Options
This plugin has the following default options, so you will only need to include the line below if you want to change the default:
$("#imgHL").imageHighlighter({
borderColor : "#fff",         // highlight border color
borderSize  : 4,              // highlight border thickness
borderType  : "solid",        // highlight border type
list        : "a",            // links that contain the highlight coordinates (e.g. "li.imgHL a")
descrip     : "p",            // HTML tag sibling of the link, that contains the description text (hidden) (e.g. "p.desc")
descripClass: ".description", // HTML tag where description text is shown (placeholder)
overlay     : true,           // display an overlay to make the highlight stand out
current     : "current",      // class applied to link currently used to highlight the image
hoverTimeout: 100,            // hoverIntent timeout (only applied if hoverIntent plugin is loaded)
zindex      : 10              // z-index of highlight box, overlay is automatically made 1 less than this number
})
Methods
You can use the following methods to get and set the highlighted content. Note that these methods must target the image.
  • Get: In the following example, the variable current will contain the current link object that has been highlighted. If nothing is currently highlighted, the script will return null.
    var $current = $('#imgHL').data('imageHighlighter').highlight();
  • Set/Get:
  • Use a number (indexed from one: first, second, etc) - if the nth link doesn't exist, it will return null.
    var $current = $('#imgHL').data('imageHighlighter').highlight(1); // select the first link
  • Search for the case-sensitive text within the link (uses the jQuery ":contains()" selector) - if the text is not found, the script will return null.
    var $current = $('#imgHL').data('imageHighlighter').highlight("frames");
  • Search for the link with a class or ID - if the selector is not found, the script will return null.
    var $current = $('#imgHL').data('imageHighlighter').highlight(".box");
Edit Mode
  • Updated in v1.01:
    • The edit mode script was moved into an extension for the plugin. This was done because the edit script is not required once the coordinates are obtained and the script is deployed on your site.
    • Additionally, the script was made to work with the Jcrop plugin (included with the demo file zip) allowing you to use a resizable selection box to more easily get the coordinates.
    • If you click on the coordinates, the coordinates (contained in an input tag) become selected, so you can more easily copy them.

  • Edit mode for this plugin should make it easier to obtain the coordinates of the highlight box - the coordinates added to the highlight link rel attribute.

  • As of v1.01, edit mode can be activated by:

    1. Including the imageHighlighterEditor script & the jCrop plugin script, if desired.
    2. Set up the editor by calling the script on the same image(s) as the imageHighlighter script. You can generalize the call by targeting the ".imageHighlighter" class (applied to a div that wraps the image after the imageHighlighter script is applied to it). There is only one options, seen below:
      // Enable the editor and use the Jcrop plugin, if it is available
      $('div.imageHighlighter img').imageHighlighterEditor();
      
      // Enable the editor, but don't use the Jcrop plugin (even if it has been loaded)
      $('div.imageHighlighter img').imageHighlighterEditor({ useJcrop: false });
    3. Now activate or deactivate edit mode by double clicking on the image. A green bar (styled in the CSS) will appear below the image which will show the mouse coordinates (default editor) or the box coordinates (Jcrop plugin added).

  • With the editor active:

    • Default editor - move the cursor over the image to find the coordinates. Then clicking on the image will lock the coordinate display and make copying these numbers easier.
      Mouse x,y coordinates (click to lock/unlock) : x,y
    • Jcrop plugin installed - single click anywhere on the image to make the a corner of the box, then drag your mouse any direction to create a resizeable box. The coordinates of the upper left and bottom right corners of the box will display under the image:
      Current box coordinates : x1,y1,x2,y2
    • Click on the coordinates (they are inside an input tag). The contents will automatically be selected, but not copied.
    • When you hover over a highlight link, the highlight link name and coordinates from that link is displayed above the coordinate bar.
Bugs / Suggestions
  • When the window is repositioned, the highlights may be off until it is refreshed again when you hover over a link (especially while in edit mode), and sometimes you'll need to reload the page.
  • To make suggestions or report any bugs please email me at wowmotty at g mail dot com.

Saturday, September 26, 2009

imgHighLighter - jQuery Plugin


A newer version of this plugin is now available!

imgHighLighter is a jQuery plugin I wrote (my first!) that allows you to highlight a portion of an image when you hover over a link. In the image below, the mouse is hovering over the "Toolbar" link and you can see the toolbar portion of the image is highlighted (click on the image to go to the demo page).
I set up an example page here.

This is still an early version of this plugin but I know it works with IE8, FF and Chrome. Please leave me feedback if you any problems with how it works.

Setup
  • This plugin requires jQuery.
  • HoverIntent is an optional plugin, this plugin will use it's functionality if it is included.
  • Follow this basic template for each image you want to apply imgHighLighter functionality.

    CSS
    /* Image & descriptions */
    div.imgHL { width: 500px; margin:0 auto; }
    div.imgHL ul { text-align: center; }
    div.imgHL ul li { margin: 0; padding: 5px; list-style-type: none; float: left; }
    div.imgHL .descriptions { margin-top: 1em; clear: both; width: 450px; height: 2em; }
    div.imgHL .descriptions p {display:none;}
    
    /* General imgHighLight (overlay and highlight) */
    .imgHLOverlay { background: #000; opacity: .6; filter: alpha(opacity=60); }
    .imgHLDark, .imgHLLight, .imgHLOverlay { padding: 0; margin: 0; }
    
    /* imgHighLight Edit Mode CSS */
    .imgHLInfo { margin: 5px auto; }
    .imgHLCoords { margin: 5px auto; }
    
    HTML
    <div class="imgHL">
    <ul>
    <li><a href="#" rel="desc1:sx1,sy1,ex2,ey2">Link 1</a></li>
    <li><a href="#" rel="desc2:sx1,sy1,ex2,ey2">Link 2</a></li>
    <li><a href="#" rel="desc3:sx1,sy1,ex2,ey2">Link 3</a></li>
    </ul>
    <img class="imgHLMain" src="whole.jpg" alt="" />
    <div class="descriptions">
    <p id="desc1">Description for item #1</p>
    <p id="desc2">Description for item #2</p>
    <p id="desc3">Description for item #3</p>
    </div>
    </div>
    
    Javascript
    /* window load ensures all images are loaded */
    $(window).load(function(){
    $(".imgHL").imgHighLight();
    })
    
  • Highlights: The link's "rel" attribute contains all the information needed for the highlights.
    rel="desc1:sx1,sy1,ex2,ey2"
    desc1 = ID of the description that is associated with the highlighted area (do not include the "#")
    sx1 = Starting X position of the highlight box
    sy1 = Starting Y position of the highlight box
    ex2 = Ending X position of the highlight box
    ey2 = Ending Y position of the highlight box
    You can change the highlight properties using: borderColor, borderSize & borderType described below

  • Image: The script is set by default to find any image inside the main wrapper (.imgHL) as set by the function call
    $(".imgHL").imgHighLight();
    You can specify the exact image to modify by adding the imageID option (described below)

  • Descriptions: The wrapper class that contains the image highlight descriptions is set to "descriptions" by default. You can change this default using the descriptionWrapper option (described below). Each description within the wrapper is contained in a paragraph tag with a specific ID that matches the desc1 ID in the rel attribute.

  • Overlay: The overlay covers the image (darkens the background) to make the highlighted portion stand out more. You can adjust the opacity of this overlay in the CSS and you can turn off the overlay functi0nality (as it script does while in edit mode) by setting the overlay option.
Customizing / Options
This plugin has the following options:
$(".imgHL").imgHighLight({
borderColor: '#fff',                  // Color of the highlight border
borderSize: '2',                      // Thickness of highlight border
borderType: 'solid',                  // Type of highlight border
imageID: 'img',                       // Object or ID of the main image (e.g. #myimage or just img - if it's the only img inside the container)
descriptionWrapper: '.descriptions',  // Class wrapping all the descriptions
overlay: true,                        // Activate overlay (default = true)
editMode: false                       // Enable edit mode - on screen display of the image coords so you can get the info you need easier
})
Edit Mode
  • I've included an edit mode for this plugin which should make it easier for you to obtain and add the coordinates of the edges of the highlight box.

  • Edit mode can be activated in two ways:
    1. Using the editMode option when calling the plugin (described in the last section)
    2. Add a link along with the other highligh links. This method is the best as it allows you to activate and deactive edit mode.
      <li><a href="#" class="imgHLEdit">Edit Mode</a></li>
  • While in edit mode, additional information is added into the caption area... it displays the current cursor X and Y position.
    X = 0px, Y = 0px - Click to lock/unlock coordinates
  • If you click on the image while in edit mode, it locks the displayed coordinates so moving the mouse off the image won't change the display. Hopefully this will make it easier to edit your source document with the coordinates.

  • Additionally if you hover over a link, the highlight box will display (with overlay off) to allow better visualization of the highlight box.
Bugs / Suggestions
  • At this time, the options you chose will apply to all the imgHighlighter images on the page (to be fixed in future versions)
  • When the window is repositioned, the highlights may be off until it is refreshed again when you hover over a link (especially while in edit mode), and sometimes you'll need to reload the page.
  • Future versions will allow you to highlight the image from links located anywhere on the page.
  • To make suggestions or report any bugs please email me at wowmotty at g mail dot com. Additonally, this is my first plugin, so if you can help me out with any suggestions or tips on how to improve the code I would greatly appreciate it :)

Friday, September 11, 2009

Chained Video Selection Box

This video box does two things.
(1) Videos are grouped and can be selected from a drop down menu.
(2) You can change the video size on the fly.

Click on the image below to see the demo page, view source for the full code.


Customizing

Setting up Groups
  1. To add a new group, you'll need to first add it to the group selector box - it looks like the example below. Add the new group option in whatever order you desire.

    <!-- Add New Groups below -->
    <!-- ******************** -->


    <option value="group1">The Guild</option>
    <option value="group2">Muppets</option>
    <option value="group3">Misc Videos</option>

    <!-- Add New Groups Above -->
    <!-- ******************** -->
    Add this for a new group:

    <option value="group#">GROUP NAME</option>
    Now replace the "group#" with the next number and the text in yellow with the group name.
  2. Now you'll need to add the group's box, follow this template:

    <div id="group#"><!--
    <option value="VIDEO #1 URL or Embed code">VIDEO #1 TITLE</option>
    <option value="VIDEO #2 URL or Embed code">VIDEO #2 TITLE</option>
    --></div>
    • Make sure the group# matches the number in the selector box
    • Replace the URL in orange with the video's URL or Embed code (*Note* read the "Video URL" section below before adding the URL)
    • Replace the text in purple with your Video's title.
  3. If you want to change the displayed text from "Select a group", "Select a video" or "<- select". I highlighted the text in teal so you can find it easier. *Note* < is the HTML code for the left bracket "<".
Video URL or Embed Code
  • Only certain sites have support for the URL shortcut versus using the entire embed code provided by the site, I could add more but it'll just make the code that much longer:


  • DailyMotion:

    <option value='http://www.dailymotion.com/video/x1bxhu_tunak-tunak-tun_fun'>Tunak Tunak (DailyMotion 4:3)</option>
  • Google Video:

    <option value='http://video.google.com/videoplay?docid=3034123062262825045'>Final Fantasy X-2 Intro (Google 4:3)</option>
  • Vimeo:

    SD: <option value='http://www.vimeo.com/5336440'>Blip (Vimeo 4:3)</option>
    HD:<option value='http://www.vimeo.com/hd#6235286'>The Forest (Vimeo 16:9)</option>
    <option title='hd' value='http://www.vimeo.com/6235286'>The Forest (Vimeo 16:9)</option>
    <option title='1.78' value='http://www.vimeo.com/6235286'>The Forest (Vimeo 16:9)</option>

    • All three of the HD examples are equivalent.
    • Note the "hd#" in the URL is specific for HD videos - so you could manually add this, but you may not get the HD version if it doesn't exist)
  • Yahoo:

    <option value='http://video.yahoo.com/watch/5292856/13959401'>Skateboarding Bulldog! (Yahoo 4:3)</option>
  • You Tube:

    SD: <option value='http://www.youtube.com/watch?v=qNfDzfhRgkU&fmt='>Alizee - I'm Fed Up! (YouTube 4:3)</option>
    HD: <option title='hd' value='http://www.youtube.com/watch?v=cKg6CVki5hk&fmt='>Wet - Trailer (YouTube 16:9)</option>
  • All other Video sites: I'm using Yahoo here, but it applies to any site that provides an embed code... make sure there are no single quotes (apostrophes) in the code... Replace these with a \' (backslash + apostrophe) if you have to.

    <option value='<div><object width="512" height="322"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" /><param name="allowFullScreen" value="true" /><param name="AllowScriptAccess" VALUE="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="id=13959401&vid=5292856&lang=en-us&intl=us&thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/video06/5292856_rnd9461b9a5_19.jpg&embed=1&ap=10513021" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=13959401&vid=5292856&lang=en-us&intl=us&thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/video06/5292856_rnd9461b9a5_19.jpg&embed=1&ap=10513021" ></embed></object>'>Skateboarding Bulldog (using full embed code)</option>