Posts

Showing posts from February, 2014

Preventing form submission when Enter is pressed

$('input').keydown(function(event){
            if(event.keyCode == 13) {
                event.preventDefault();
                return false;
            }
});

How to detect a click outside an element?

Attach a click event to the document body which closes the window. Attach a separate click event to the window which stops propagation to the document body.

$('html').click(function() { //Hide the menus if visible }); $('#menuele').click(function(event){     event.stopPropagation(); });

How to replay a swf movie on jquery button click

1. Embedded flash movie

<object data="http://wwwimages.adobe.com/www.adobe.com/multimedia/en_us/get/flash/flash_installed_728x170.swf" type="application/x-shockwave-flash" id="flash_99674493" width="680" height="316">     <param name="movie" value="http://wwwimages.adobe.com/www.adobe.com/multimedia/en_us/get/flash/flash_installed_728x170.swf">     <param name="wmode" value="opaque"> </object> <a href="javascript:restart();">Restart swf</a>
2. jQuery

var restart = function() {    var flashObject = jQuery("object");    var flashOriginal = flashObject.html();    var flashSrc = flashObject.attr('data');    flashObject.find('param').remove();    flashObject.attr('data',flashSrc);          flashObject.html(flashOriginal); }
Working Demo

How to build a HTML 5 video playlist

1. HTML
<video id="videoarea" controls="controls" poster="http://html5videoformatconverter.com/data/images/screen.jpg" src="http://html5videoformatconverter.com/data/images/happyfit2.mp4"></video> <ul id="playlist">     <li data-url="http://html5videoformatconverter.com/data/images/happyfit2.mp4" data-poster="http://html5videoformatconverter.com/data/images/screen.jpg">Happy Fit</li>     <li data-url="http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4">Sintel</li>              <li data-url="http://html5example.net/static/video/html5_Video_VP8.webm">Resident Evil</li>          <li data-url="http://www.ioncannon.net/examples/vp8-webm/big_buck_bunny_480p.webm">Big Buck Bunny</li> </ul>
2. CSS

<style type='text/css'>     #playlist {         margin:0;         padding:0;         list-style:non…

HTML5 video loop src change on end play function

1. HTML


<video id="homevideo" width="100%" autoplay onended="run()">     <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" /> </video> <ul>     <li>http://www.w3schools.com/html/mov_bbb.mp4</li>     <li>http://www.w3schools.com/html/movie.mp4</li> </ul>

2. CSS

<style type='text/css'>     ul {         display:none;     }   </style>

3. jQuery

<script type="text/javascript"> video_count = 0; videoPlayer = document.getElementById("homevideo"); function run(){    video_count++;     var countVideo = $('li').length;         if (video_count == countVideo) video_count = 0;        var nextVideo = $('li').eq(video_count).text();         videoPlayer.src = nextVideo;     videoPlayer.play();         }; </script>

Working Demo

Sample HTML5 Page Structure

<!DOCTYPE HTML><html><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>Your Website</title></head><body><header><nav><ul><li>Your menu</li></ul></nav></header><section><article><header><h2>Article title</h2><p>Posted on <timedatetime="2009-09-04T16:31:24+02:00">September 4th 2009</time> by <ahref="#">Writer</a> - <ahref="#comments">6 comments</a></p></header><p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p></article><article><header><h2>Article title</h2><p>Posted on <timedatetime="2009-09-04T16:31:24+02:00">September 4th 2009</time> by <ahref="#">Writer</a> - <ahref="#comments"…

WordPress admin menu slugs

Dashboardremove_menu_page(‘index.php’);Dashboard        remove_submenu_page( ‘index.php’, ‘index.php’ );Updatesremove_submenu_page( ‘index.php’, ‘update-core.php’ );Postsremove_menu_page(‘edit.php’);Postsremove_submenu_page( ‘edit.php’, ‘edit.php’ );Add Newremove_submenu_page( ‘edit.php’, ‘post-new.php’ );Categoriesremove_submenu_page( ‘edit.php’, ‘edit-tags.php?taxonomy=category’ );Post Tagsremove_submenu_page( ‘edit.php’, ‘edit-tags.php?taxonomy=post_tag’ );Mediaremove_menu_page(‘upload.php’);Libraryremove_submenu_page( ‘upload.php’, ‘upload.php’ );Add Newremove_submenu_page( ‘upload.php’, ‘media-new.php’ );Linksremove_menu_page(‘link-manager.php’);Linksremove_submenu_page( ‘link-manager.php’, ‘link-manager.php’ );Add Newremove_submenu_page( ‘link-manager.php’, ‘link-add.php’ );Link Categories  remove_submenu_page( ‘link-manager.php’, ‘edit-tags.php?taxonomy=link_category’ );Pagesremove_menu_page(‘edit.php?post_type=page’);Pagesremove_submenu_page( ‘edit.php?post_type=page’, ‘edit.p…

Removing menu pages from the WordPress admin

In this tutorial, I’ll cover the remove_menu_page() and remove_submenu_page() functions, which were added in WordPress 3.1.

The first thing you need to decide is where you’re putting the code. I’ll assume you’re either dropping this in your theme’s functions.php file or one of your plugin files.

1. Removing top-level menu pagesUsage remove_menu_page( $menu_slug );Examples <?php function remove_menus(){ remove_menu_page( 'index.php' ); //Dashboard remove_menu_page( 'edit.php' ); //Posts remove_menu_page( 'upload.php' ); //Media remove_menu_page( 'edit.php?post_type=page' ); //Pages remove_menu_page( 'edit-comments.php' ); //Comments remove_menu_page( 'themes.php' ); //Appearance remove_menu_page( 'plugins.php' ); //Plugins remove_menu_page( 'users.php' ); //Users remove_menu_page( 'too…