Category Archives: HTML5

How-to for HTML5

Resizable YouTube Videos for your Site

Do you have a problem with YouTube videos on your site that don’t resize in your responsive website? This can be a big hassle. You can set up your site using CSS to control the resizing, but, (1) You may have older websites that you don’t want to rewrite, (2) you may be somewhat unfamiliar with CSS or you have other reasons you don’t want to hassle correcting problems of resizing videos on your sites. If you are willing to take just a few minutes to fix the problem, there is a simple solution to your problem. To solve your problem, you’ll add a few lines of code to your file. In the area of all pages that include videos, add the following lines of code:



    <script type="text/javascript" 
       src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
    </script>
    <script type="text/javascript" src="/js/videoSizing.js"></script>

Next, download the file “videoSizing.js. Add the file to the directory /js, and you’re done. This will make all your YouTube videos responsive. If you would prefer to place the videoSizing.js in an alternate directory, insert the file where you like, but, adjust the /js/videoSizing.js path to correctly reflect the directory that you chose to store the videoSizing.js file. Also, the addition of the jquery.min.js is only required for those sites that do not already use the jQuery library. As long as you use a src address that correctly accesses the file and the jQuery library library is included, all your YouTube videos will resize responsively.

By the way, if you would like to add a margin around the video, define the variable YOUTUBE_VIDEO_MARGIN and the video margin will be set. Ex.



    YOUTUBE_VIDEO_MARGIN = 10 ;  /* sets margin to 10 pixels */

If you are curious what is contained in the videoSizing.js file, you’ll find the following:



    /*
     * Youtube video auto-resizer script
     * Created by Skipser.com
    */
     
    jQuery(function($) {
      if(typeof YOUTUBE_VIDEO_MARGIN == 'undefined') {
        YOUTUBE_VIDEO_MARGIN=5;
      }
      $('iframe').each(function(index,item) {
        if($(item).attr('src').match(/(https?:)?\/\/www\.youtube\.com/)) {
          var w = $(item).attr('width');
          var h = $(item).attr('height');
          var ar = h/w*100;
          ar = ar.toFixed(2);
          //Style iframe    
          $(item).css('position','absolute');
          $(item).css('top','0');
          $(item).css('left','0');    
          $(item).css('width','100%');
          $(item).css('height','100%');
          $(item).css('max-width',w+'px');
          $(item).css('max-height', h+'px');        
          $(item).wrap('<div style="max-width:' + w + 'px;margin:0 auto; padding:' + YOUTUBE_VIDEO_MARGIN + 'px;" /> ');
          $(item).wrap('<div style="position: relative;padding-bottom: ' +  ar + '%; height: 0; overflow: hidden;" /> ');
        }
      });
    });

Enjoy the new responsiveness of your YouTube videos. By the way, if you would like more on this topic, see Skipser’s article on the jQuery snippet.

Snippet: Popups

The following is code to create popups. To use this code:

  1. Create a div that contains the pop up content and add an id tag to the div.
  2. Create a div or image that will be used to open the popup, and add a class tag.
  3. Add a div or image to the popup content that may be pressed to close the popup, add a class to the div or image

Add the following JavaScript code …


    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
    <script type="text/javascript">
        $(function() {
            if (!$("#dr_pop_div").length )  $("body").prepend( "<div id='dr_pop_div' ></div>" ) ;
                function dr_pop(config) {
                    var dr_tag    = (config.msg) ? config.msg : "#msg" ;  /* tagged div that will pop up */
                    var dr_open   = (config.open)? config.open : ".info_open"  ;  /* element to click to open    */
                    var dr_close  = (config.close)? config.close : ".info_close"  ;  /* element to click to close   */
                    var dr_toggle = (config.toggle)? config.toggle : ".info_toggle"  ; /* element to click to toggle */

                    $("#dr_pop_div" ).append($(dr_tag));
                    $("#dr_pop_div").addClass("dr_pop_hide") ; 
                    $(dr_tag).addClass("dr_pop_hide") ;

                    $(dr_open).click(function()   {
                        if ($("#dr_pop_div").hasClass("dr_pop_hide"))   $("#dr_pop_div").removeClass("dr_pop_hide") ;
                        if ($(dr_tag).hasClass("dr_pop_hide")) 	        $(dr_tag).removeClass("dr_pop_hide") ;	
                        if (!$("#dr_pop_div").hasClass("dr_pop_show"))  $("#dr_pop_div").addClass("dr_pop_show") ;
                        if (!$(dr_tag).hasClass("dr_pop_show"))         $(dr_tag).addClass("dr_pop_show") ; 
                    }) ;
                    $(dr_close).click(function()  {
                        if ($(dr_tag).hasClass("dr_pop_show"))        $(dr_tag).removeClass("dr_pop_show") ;
                        if ($("#dr_pop_div").hasClass("dr_pop_show")) $("#dr_pop_div").removeClass("dr_pop_show") ;
				
                        if (!$(dr_tag).hasClass("dr_pop_hide"))        $(dr_tag).addClass("dr_pop_hide") ;
                        if (!$("#dr_pop_div").hasClass("dr_pop_hide")) $("#dr_pop_div").addClass("dr_pop_hide") ;
		    }) ;
                    $(dr_toggle).click(function() {
                        if ($("#dr_pop_div").hasClass("dr_pop_hide")) {
                            $("#dr_pop_div").removeClass("dr_pop_hide") ;
                            $(dr_tag).removeClass("dr_pop_hide") ;
                            if (!$("#dr_pop_div").hasClass("dr_pop_show")) { 
                                $("#dr_pop_div").addClass("dr_pop_show") ;
                                $(dr_tag).addClass("dr_pop_show") ;
                            }
                        } else {
                            if ($("#dr_pop_div").hasClass("dr_pop_show")) { 
                                $("#dr_pop_div").removeClass("dr_pop_show") ;
                                $(dr_tag).removeClass("dr_pop_show") ;
                            }
                            if (!$("#dr_pop_div").hasClass("dr_pop_hide")) {
                                $("#dr_pop_div").addClass("dr_pop_hide") ;
                                $(dr_tag).addClass("dr_pop_hide") ;
                            }
                        }		    
                    }) ;
                }
                var popup1 = new dr_pop({ "msg" : "#msg", "open" : ".info_open", "close" : ".info_close"  }) ; 
                /* ... more popup declarations go here */
            }) ;		  
	</script>

For each message popup, declare the popup by defining the labels that will be used for the popups. The definitions of the labels are done in the “dr_pop” statement. The dr_pop(config) is defined as follows:


    var pop = new dr_pop( {
       "msg" :  ,     
       "open" :  ,
       "close" : 
      }) ;
  Where:
      is the quoted id for the div that holds the message, example: "#msg"
      is the quoted id or class of the object to use as the open button. 
                (Example:  .info_open) 
      is the quoted id or class of the object to use as the close button.
                (example: .info_close)

 

WordPress: Changing Maximum Upload Size

Using WordPress to upload videos (or other files), it may turn out that you need to upload a file larger than the maximum limit set by WordPress. This should no be a significant, you can increase the size of the allowed upload file. To increase the upload size, you must adjust some or all the following PHP variables:

  • WP_MEMORY_LIMIT
  • upload_max_filesize
  • post_max_size
  • max_execution_time

Must and may changes are as following. To increase the upload size, you must increase the upload_max_filesize and post_max_size. If the file is large enough, you may need to increase the size for memory_limit, max_execution_time and max_input_time.

The changes may be made in two locations. They may be made in your php.ini file or your .htaccess file. You may not change them by modifying your wp_config.php file adding an ini_set. Using ini_set in wp_config.php might be your first instinct, but, that will not work.

To keep the change more localized, modify the .htaccess file with the following code (changing the upload preference size as needed for your situation)


    <IfModule mod_php5.c>
        php_value memory_limit 64M
        php_value upload_max_filesize 64M
        php_value post_max_size 64M
        php_value max_execution_time 600
        php_value max_input_time 600
    </IfModule>

If you prefer to change php.ini, you can add the following to th php.ini file as needed in your situation


    memory_limit = 64M
    upload_max_filesize = 64M
    post_max_size = 64M
    max_execution_time = 600
    max_input_time = 600

Disconnecting Eclipse Project from SVN Repository

In Eclipse, in the event you have retrieved a project from an SVN repository and you would like to detach from the repository you need to do the following:

  • Open the Package Explore
  • Right Click on the project to be detached, a menu appears
  • Hover over “Team” in menu, options appear
  • Click option Team/Disconnect.
  • You are not detached from the repository

Android Error Message: System UI has stopped

After using Eclipse to develop Android Apps, I suddenly began receiving the error message “Unfortunately, System UI has stopped” when using the emulator. Generally, the configuration seems right and emulator seemed to work, this was a strange surprise after selecting to test against a device I had not used to test against previously. When I ran the emulator for the specific device, it would take to much time loading and an error dialog displayed on screen

Searching the net, I found my solution. To solve the problem:”

  1. Go to the device .avd directory. In Windows 7/x64, the directory is found at:
    C:/Users//.android/avd/.avd/
  2. Open the file config.ini in that directory
  3. Set hw.mainKeys=yes (instead of the current value no)

That seems to solve the problem.