This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //CALCULATES DISTANCE BETWEEN 2 POINTS | |
| function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) { | |
| $theta = $longitude1 - $longitude2; | |
| $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta))); | |
| $miles = acos($miles); | |
| $miles = rad2deg($miles); | |
| $miles = $miles * 60 * 1.1515; | |
| $feet = $miles * 5280; | |
| $yards = $feet / 3; | |
| $kilometers = $miles * 1.609344; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //AUTOPOPULATE SELECT BOX USING AJAX AND JQURY | |
| $(function(){ | |
| $("select#ctlJob").change(function(){ | |
| $.getJSON("/select.php",{id: $(this).val(), ajax: 'true'}, function(j){ | |
| var options = ''; | |
| for (var i = 0; i < j.length; i++) { | |
| options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>'; | |
| } | |
| $("select#ctlPerson").html(options); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //DYNAMICALLY ADD FORM ELEMENTS | |
| //change event on password1 field to prompt new input | |
| $('#password1').change(function() { | |
| //dynamically create new input and insert after password1 | |
| $("#password1").append("<input type='text' name='password2' id='password2' />"); | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //IMAGE PRELOADER | |
| var nextimage = "/images/some-image.jpg"; | |
| $(document).ready(function(){ | |
| window.setTimeout(function(){ | |
| var img = $("<img>").attr("src", nextimage).load(function(){ | |
| //all done | |
| }); | |
| }, 100); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //PARSING JSON WITH JQUERY | |
| function parseJson(){ | |
| //Start by calling the json object, I will be using a | |
| //file from my own site for the tutorial | |
| //Then we declare a callback function to process the data | |
| $.getJSON('hcj.json',getPosts); | |
| //The process function, I am going to get the title, | |
| //url and excerpt for 5 latest posts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //IMAGE RESIZING | |
| $(window).bind("load", function() { | |
| // IMAGE RESIZE | |
| $('#product_cat_list img').each(function() { | |
| var maxWidth = 120; | |
| var maxHeight = 120; | |
| var ratio = 0; | |
| var width = $(this).width(); | |
| var height = $(this).height(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //parse an XML file | |
| function parseXml(xml) { | |
| //find every Tutorial and print the author | |
| $(xml).find("Tutorial").each(function() | |
| { | |
| $("#output").append($(this).attr("author") + " | |
| "); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //get relative mouse position | |
| function rPosition(elementID, mouseX, mouseY) { | |
| var offset = $('#'+elementID).offset(); | |
| var x = mouseX - offset.left; | |
| var y = mouseY - offset.top; | |
| return {'x': x, 'y': y}; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //browser detection | |
| //A. Target Safari | |
| if( $.browser.safari ) $("#menu li a").css("padding", "1em 1.2em" ); | |
| //B. Target anything above IE6 | |
| if ($.browser.msie && $.browser.version > 6 ) $("#menu li a").css("padding", "1em 1.8em" ); | |
| //C. Target IE6 and below | |
| if ($.browser.msie && $.browser.version <= 6 ) $("#menu li a").css("padding", "1em 1.8em" ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //search within text | |
| $.fn.egrep = function(pat) { | |
| var out = []; | |
| var textNodes = function(n) { | |
| if (n.nodeType == Node.TEXT_NODE) { | |
| var t = typeof pat == 'string' ? | |
| n.nodeValue.indexOf(pat) != -1 : | |
| pat.test(n.nodeValue); |