<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>javascript &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Sat, 15 Feb 2014 02:35:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>How to scale images responsive with jQuery</title>
		<link>https://blog.blackbam.at/2014/02/15/how-to-scale-images-responsive-with-jquery/</link>
					<comments>https://blog.blackbam.at/2014/02/15/how-to-scale-images-responsive-with-jquery/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Sat, 15 Feb 2014 02:35:38 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2165</guid>

					<description><![CDATA[When coding responsive Web-Designs we usually have images in the content and in various containers with varying dimensions. In these containers, images should never be bigger than the HTML-container itself. In order to solve this problem I have developed this little script which may be helpful for some of you visitors, too. It is just [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>When coding responsive Web-Designs we usually have images in the content and in various containers with varying dimensions. In these containers, images should never be bigger than the HTML-container itself. In order to solve this problem I have developed this little script which may be helpful for some of you visitors, too. It is just required to set a jQuery selector for the container itself (to get the maximum width) and one to select all the images affected.</p>
<pre lang="javascript">

function scale_content_images() {

    $('#my_container img').each(function() {

            var the_image = this;
            var maxAvailableWidth = $('#my_container').width()-20; // Max width for the image
            var ratio = 0;  // Used for aspect ratio
            var width = $(this).width();    // Current image width
            var height = $(this).height();  // Current image height
            var orig_width = parseInt($(this).attr("width")); // the intended width of the image
            var orig_height = parseInt($(this).attr("height")); // the intended height of the image

            // if intended width/height not available, get original image dimensions and set these
            if(isNaN(orig_width)||isNaN(orig_height)) {
                var image = new Image();
                image.src = $(the_image).attr("src");
                orig_width = image.naturalWidth;
                orig_height= image.naturalHeight;
            }

            // Check if the current width is larger than the max
            if(orig_width>maxAvailableWidth) {
                ratio = maxAvailableWidth / width;   // get ratio for scaling image
                $(this).css("width", maxAvailableWidth); // Set new width
                $(this).css("height", height * ratio);  // Scale height based on ratio
                height = height * ratio;    // Reset height to match scaled image
                width = width * ratio;    // Reset width to match scaled image
            } else {
                $(this).css("width",orig_width);
                $(this).css("height",orig_height);
            }
        });
}

$(document).ready(function() {
      scale_content_images();
});

$(document).resize(function() {
      scale_content_images();
});

</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2014%2F02%2F15%2Fhow-to-scale-images-responsive-with-jquery%2F&#038;title=How%20to%20scale%20images%20responsive%20with%20jQuery" data-a2a-url="https://blog.blackbam.at/2014/02/15/how-to-scale-images-responsive-with-jquery/" data-a2a-title="How to scale images responsive with jQuery"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2014/02/15/how-to-scale-images-responsive-with-jquery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>My todays top 10 most useful Javascript Functions</title>
		<link>https://blog.blackbam.at/2011/07/01/my-todays-top-10-most-useful-javascript-functions/</link>
					<comments>https://blog.blackbam.at/2011/07/01/my-todays-top-10-most-useful-javascript-functions/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Thu, 30 Jun 2011 22:21:10 +0000</pubDate>
				<category><![CDATA[JavaScript / Ajax]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript functions]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[top 10 javascript]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1308</guid>

					<description><![CDATA[These are my todays top 10 Javascript functions which I gathered in more than 6 months of casually Javascript Development. Almost each of them helped out of more than one problem, so they deserve to be perpetuated here and help again. Most of these are not written by me, but by some other great programmer on the web, and I really would like to mention all of them here if I would know where I have got all of these great scripts. Have fun an use wisely. [...]]]></description>
										<content:encoded><![CDATA[<p>These are my todays top 10 Javascript functions which I gathered in more than 6 months of casually Javascript Development. Almost each of them helped out of more than one problem, so they deserve to be perpetuated here and help again. Most of these are not written by me, but by some other great programmer on the web, and I really would like to mention all of them here if I would know where I have got all of these great scripts.</p>
<p>&nbsp;</p>
<p>Have fun an use wisely.</p>
<h2>1. Get Elements By Class Name (getElementsByClassName)</h2>
<p>This is maybe one of the most used and most needed custom Javascript functions of all time. It provides a way to get all elements in a page with a certain class attribute.</p>
<pre lang="javascript">
function getElementsByClassName(classname, node){
    if (!node) {
        node = document.getElementsByTagName('body')[0];
    }
 
    var a = [], re = new RegExp('\\b' + classname + '\\b');
    els = node.getElementsByTagName('*');
    for (var i = 0, j = els.length; i < j; i++) {
        if (re.test(els[i].className)) {
            a.push(els[i]);
        }
    }
    return a;
}
</pre>
<h2>2. Test if Internet Explorer is used and get its version number</h2>
<p>I do not know how much functions, CSS selectors or whatever - IE so often acts different or just stupid. It always requires extra work. This after all will help you to detect this nasty browser.</p>
<pre lang="javascript">
// use the class
if(Browser.Version() <8) {
	// make crazy IE shit
}
 
var Browser = {
    Version: function(){
        var version = 999; // we assume a sane browser
        if (navigator.appVersion.indexOf("MSIE") != -1) 
            // bah, IE again, lets downgrade version number
            version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        return version;
    }
}
</pre>
<h2>3. Clear input-field onclick, if value is default</h2>
<p>This is not much of javascript, we actually call it dynamic html. It is just the standard way to present the comfortable input fields to users.</p>
<pre lang="javascript">
<input type="text" name="" value="username" onclick="if(this.value=='username') this.value='';" />
</pre>
<h2>4. Test if a String is not empty</h2>
<p>Can help to avoid a lot of common mistakes with javascript.</p>
<pre lang="javascript">
var bpat    = /\S/;
function isNonblank (s) {
   return String (s).search (bpat) != -1
}
</pre>
<h2>5. Function Exists</h2>
<p>This is a possibility in Javascript to test if a function exists (like function_exists in PHP). This can be useful in cases of debugging or when you are not sure if some required script file is loaded, for example.</p>
<pre lang="javascript">
if(typeof yourFunctionName == 'function') {
     yourFunctionName();
}
</pre>
<h2>6. Get scroll width/height of page visitors' browser window</h2>
<p>A browser-safe way to get the number of pixels, which a user scrolled down the webpage currently.</p>
<pre lang="javascript">
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
 
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}
</pre>
<h2>7. Get current size of page visitors' browser window</h2>
<p>A browser-safe way to get the window height and window width of the current viewers browser in pixels.</p>
<pre lang="javascript">
function getWindowSize() {
    var myWidth = 0, myHeight = 0;
 
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [ myWidth, myHeight ];
}
</pre>
<h2>8. Scale images by setting a maximum width/height</h2>
<p>It is not always the best idea to scale images with javascript. But I came to several applications there this was useful though.</p>
<pre lang="javascript">

var images = document.getElementsByTagName("img"); // get your images somehow
scaleImages(imgs,150,150); // call the function
         
// scales the images to a maximum width/height
function scaleImages(images,maxh,maxw) {
  
for(i=0;i<imgs.length;i++) {
	var ratio = maxh/maxw;
	var img = imgs[i];
	  
	if (img.height/img.width > ratio){
		// height is the problem
		if (img.height > maxh){
			img.width = Math.round(img.width*(maxh/img.height));
			img.height = maxh;
		}
	} else {
		// width is the problem
		if (img.width > maxh){
			img.height = Math.round(img.height*(maxw/img.width));
			img.width = maxw;
		}
	  }
	  img.setAttribute("class","showpreview ready");
  }
}
</pre>
<h2>9. Print Javascript Array (like print_r()-in PHP)</h2>
<p>A really useful function for debugging and developing with javascript. Instead of [object Object] or something similar you will see the whole contents of an array in your output.</p>
<pre lang="javascript">
	function dump(arr,level) {
		var dumped_text = "";
		if(!level) level = 0;
		
		//The padding given at the beginning of the line.
		var level_padding = "";
		for(var j=0;j<level+1;j++) level_padding += "    ";
		
		if(typeof(arr) == 'object') { //Array/Hashes/Objects 
			for(var item in arr) {
				var value = arr[item];
				
				if(typeof(value) == 'object') { //If it is an array,
					dumped_text += level_padding + "'" + item + "' ...\n";
					dumped_text += dump(value,level+1);
				} else {
					dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
				}
			}
		} else { //Stings/Chars/Numbers etc.
			dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
		}
		return dumped_text;
	}
</pre>
<h2>10. XML2Array (parse xml to javascript array)</h2>
<p>For the special case of reading XML with Javascript. But very useful, when it comes to the case. It is much easier to handle a huge array in Javascript than reading lots of data from a complex XML-file. Maybe there is a tiny disadvantage concerning speed, but I think it is worth that.</p>
<pre lang="javascript">
//////////////////////////////////// xml2array() ////////////////////////////////////////
// See http://www.openjs.com/scripts/xml_parser/
var not_whitespace = new RegExp(/[^\s]/); //This can be given inside the funciton - I made it a global variable to make the scipt a little bit faster.
var parent_count;
//Process the xml data
function xml2array(xmlDoc,parent_count) {
	var arr;
	var parent = "";
	parent_count = parent_count || new Object;

	var attribute_inside = 0; /*:CONFIG: Value - 1 or 0
	*	If 1, Value and Attribute will be shown inside the tag - like this...
	*	For the XML string...
	*	<guid isPermaLink="true">http://www.bin-co.com/</guid>
	*	The resulting array will be...
	*	array['guid']['value'] = "http://www.bin-co.com/";
	*	array['guid']['attribute_isPermaLink'] = "true";
	*	
	*	If 0, the value will be inside the tag but the attribute will be outside - like this...	
	*	For the same XML String the resulting array will be...
	*	array['guid'] = "http://www.bin-co.com/";
	*	array['attribute_guid_isPermaLink'] = "true";
	*/

	if(xmlDoc.nodeName && xmlDoc.nodeName.charAt(0) != "#") {
		if(xmlDoc.childNodes.length > 1) { //If its a parent
			arr = new Object;
			parent = xmlDoc.nodeName;
			
		}
	}
	var value = xmlDoc.nodeValue;
	if(xmlDoc.parentNode && xmlDoc.parentNode.nodeName && value) {
		if(not_whitespace.test(value)) {//If its a child
			arr = new Object;
			arr[xmlDoc.parentNode.nodeName] = value;
		}
	}

	if(xmlDoc.childNodes.length) {
		if(xmlDoc.childNodes.length == 1) { //Just one item in this tag.
			arr = xml2array(xmlDoc.childNodes[0],parent_count); //:RECURSION:
		} else { //If there is more than one childNodes, go thru them one by one and get their results.
			var index = 0;

			for(var i=0; i<xmlDoc.childNodes.length; i++) {//Go thru all the child nodes.
				var temp = xml2array(xmlDoc.childNodes[i],parent_count); //:RECURSION:
				if(temp) {
					var assoc = false;
					var arr_count = 0;
					for(key in temp) {
						if(isNaN(key)) assoc = true;
						arr_count++;
						if(arr_count>2) break;//We just need to know wether it is a single value array or not
					}

					if(assoc && arr_count == 1) {
						if(arr[key]) { 	//If another element exists with the same tag name before,
										//		put it in a numeric array.
							//Find out how many time this parent made its appearance
							if(!parent_count || !parent_count[key]) {
								parent_count[key] = 0;

								var temp_arr = arr[key];
								arr[key] = new Object;
								arr[key][0] = temp_arr;
							}
							parent_count[key]++;
							arr[key][parent_count[key]] = temp[key]; //Members of of a numeric array
						} else {
							parent_count[key] = 0;
							arr[key] = temp[key];
							if(xmlDoc.childNodes[i].attributes && xmlDoc.childNodes[i].attributes.length) {
								for(var j=0; j<xmlDoc.childNodes[i].attributes.length; j++) {
									var nname = xmlDoc.childNodes[i].attributes[j].nodeName;
									if(nname) {
										/* Value and Attribute inside the tag */
										if(attribute_inside) {
											var temp_arr = arr[key];
											arr[key] = new Object;
											arr[key]['value'] = temp_arr;
											arr[key]['attribute_'+nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
										} else {
										/* Value in the tag and Attribute otside the tag(in parent) */
											arr['attribute_' + key + '_' + nname] = xmlDoc.childNodes[i].attributes[j].nodeValue;
										}
									}
								} //End of 'for(var j=0; j<xmlDoc. ...'
							} //End of 'if(xmlDoc.childNodes[i] ...'
						}
					} else {
						arr[index] = temp;
						index++;
					}
				} //End of 'if(temp) {'
			} //End of 'for(var i=0; i<xmlDoc. ...'
		}
	}

	if(parent &#038;&#038; arr) {
		var temp = arr;
		arr = new Object;
		
		arr[parent] = temp;
	}
	return arr;
}
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F07%2F01%2Fmy-todays-top-10-most-useful-javascript-functions%2F&#038;title=My%20todays%20top%2010%20most%20useful%20Javascript%20Functions" data-a2a-url="https://blog.blackbam.at/2011/07/01/my-todays-top-10-most-useful-javascript-functions/" data-a2a-title="My todays top 10 most useful Javascript Functions"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/07/01/my-todays-top-10-most-useful-javascript-functions/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>German Country Selector XHTML with javascript for pre-selection of values</title>
		<link>https://blog.blackbam.at/2011/05/08/deutsch-country-selector-xhtml-konform-deutsch-mit-vorauswahl/</link>
					<comments>https://blog.blackbam.at/2011/05/08/deutsch-country-selector-xhtml-konform-deutsch-mit-vorauswahl/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Sun, 08 May 2011 19:50:29 +0000</pubDate>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[JavaScript / Ajax]]></category>
		<category><![CDATA[country selector]]></category>
		<category><![CDATA[iso 3166]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[länderauswahl]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1345</guid>

					<description><![CDATA[Sorry, this entry is only available in Deutsch.]]></description>
										<content:encoded><![CDATA[<p class="qtranxs-available-languages-message qtranxs-available-languages-message-en">Sorry, this entry is only available in <a href="https://blog.blackbam.at/de/tag/javascript/feed/" class="qtranxs-available-language-link qtranxs-available-language-link-de" title="Deutsch">Deutsch</a>.</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F05%2F08%2Fdeutsch-country-selector-xhtml-konform-deutsch-mit-vorauswahl%2F&#038;title=German%20Country%20Selector%20XHTML%20with%20javascript%20for%20pre-selection%20of%20values" data-a2a-url="https://blog.blackbam.at/2011/05/08/deutsch-country-selector-xhtml-konform-deutsch-mit-vorauswahl/" data-a2a-title="German Country Selector XHTML with javascript for pre-selection of values"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/05/08/deutsch-country-selector-xhtml-konform-deutsch-mit-vorauswahl/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
