Archive for the ‘Javascript’ Category

Javascript / Jquery - Cropping Images

Monday, December 15th, 2008

http://deepliquid.com/content/Jcrop.html

Javascript - Embedding Flash Files / Videos & Flash Detection

Monday, December 15th, 2008

SWFObject - Standard de facto. It takes the file to embed as an input.
If you are in a different situation, you could use:
http://www.featureblend.com/javascript-flash-detection-library.html
http://jquery.lukelutman.com/plugins/flash/

Javascript - Carousel

Monday, December 15th, 2008

http://sorgalla.com/jcarousel/

JQuery: Example of The Structure of a File That Will Manage a Page

Sunday, October 26th, 2008

This is an example of the Structure of a file that will manage a page.
This is also a good example on how to manage dropdown boxes.

$(document).ready(
       function ()
       {
               // shows the tags related to the selected category
               function showTags()
               {
                   var categoryValue = $('#category').val(); // the selected value of the dropdown menu
                   var categoryIds = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11];

                   for (var i in categoryIds)
                   {
                       if ($('#tags_' + categoryIds[i]).css('display') == 'block')
                       {
                           $('#tags_' + categoryIds[i]).slideUp('fast');
                           $('#tags_' + categoryIds[i]).css('display', 'none');
                       }
                   }

                   $('#tags_' + categoryValue).slideDown('fast');
                   $('#tags_' + categoryValue).css('display', 'block');

                   // other examples
                  if ( ($('#smallImage').html() == "") ) // it checkes the actual content of the div
                  {
                    var id = $('#bigImageDiv').children('span').attr('id');
                  }
                  if ($('#featured:checked').val() != null) // it checkes whether the checkbox is ticked
                  {
                    // something
                  }
               }

		// showTags must be shown both when the page is loaded
		// and in the event of a change in the dropdown 'category'
               showTags();
               $('#category').change(function() { showTags() });

               // set up tool tips
               $('label').Tooltip({showURL: false, delay: 0, track: true});

               return false;
       });

Javascript XHTML Complaint

Friday, October 3rd, 2008

<script type=”text/javascript”>
/* < ![CDATA[ */
// content of your Javascript goes here
/* ]]> */
</script>

Javascript: Check / Uncheck All The Checkboxes Of a Certain Group

Thursday, July 3rd, 2008
/*
 * It checks all the checkboxes of a certain group (that shares a name like this: checkboxes[])
 *
 * @param the Javascript Element that contains all the checkboxes of a certain group
 *
 * Example of usage:
 * var checkboxesObj = document.getElementsByName(’checkboxes[]’);
 * selectAllCheckboxes(checkboxesObj);
 */

function checkAllCheckboxes(checkboxesObj)
{
    var checkboxesLength = checkboxesObj.length;
    for(var i = 0; i < checkboxesLength; i++) {
        checkboxesObj[i].checked = true;
    }
}

Fix IE6 Layout Bugs With Javascript

Thursday, July 3rd, 2008

http://sourceforge.net/projects/ie7/
http://dean.edwards.name/IE7/

Javascript - Confirmation Of a Link

Friday, June 27th, 2008

<a href=”#” onClick=”if( confirm(’Are you sure?’) ) document.location=’http://www.google.it/index.php?del={$points[index].pointID}’; return false;”>delete</a>

CSS: Make a Table Row Appear and Disappear (Cross Browsing)

Friday, May 30th, 2008

To make it disappear (as usual):

xxxx.style.display = “none”;

To make it appear:

xxxx.style.display = “”;

The last trick is because, this:

xxxx.style.display = “table-row”;

wouldn’t work in IE6 and IE7

Javascript: Get Emelents By Class

Friday, May 30th, 2008
// Example:
// var els = getElementsByClass(document, 'cool_row', '
‘);
//    var elsLen = els.length;
//    for (i = 0; i < elsLen; i++) {
//        els[i].style.display = ""; // this
//    }
function getElementsByClass(node, searchClass, tag) {
    var classElements = new Array();
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( searchClass == els[i].className) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}