<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.1" -->
<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/"
	>

<channel>
	<title>Mo Jebus &#187; Javascript</title>
	<link>http://moronicbajebus.com</link>
	<description>Banana Ice Cream!</description>
	<pubDate>Wed, 06 Aug 2008 14:30:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<item>
		<title>DOM Selectors API</title>
		<link>http://moronicbajebus.com/2006/10/12/dom-selectors-api/</link>
		<comments>http://moronicbajebus.com/2006/10/12/dom-selectors-api/#comments</comments>
		<pubDate>Thu, 12 Oct 2006 14:57:24 +0000</pubDate>
		<dc:creator>Seamus</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Frontpage]]></category>

		<guid isPermaLink="false">http://moronicbajebus.com/2006/10/12/dom-selectors-api/</guid>
		<description><![CDATA[A quick glance at the Selectors API indicates to me that I am not alone in my desire to retrieve DOM elements with CSS selector syntax.  
]]></description>
			<content:encoded><![CDATA[<p>A quick glance at the <a href="http://www.w3.org/TR/2006/WD-selectors-api-20060926/">Selectors API</a> indicates to me that I am not alone in <a href="/2006/08/31/better-javascript/">my desire</a> to retrieve DOM elements with CSS selector syntax.  </p>
]]></content:encoded>
			<wfw:commentRss>http://moronicbajebus.com/2006/10/12/dom-selectors-api/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Better Javascript</title>
		<link>http://moronicbajebus.com/2006/08/31/better-javascript/</link>
		<comments>http://moronicbajebus.com/2006/08/31/better-javascript/#comments</comments>
		<pubDate>Thu, 31 Aug 2006 20:34:53 +0000</pubDate>
		<dc:creator>Seamus</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Frontpage]]></category>

		<guid isPermaLink="false">http://moronicbajebus.com/?p=96</guid>
		<description><![CDATA[Javascript needs to grow.  The Javascript libraries such as Prototype and JQuery should barely exist.  Before you say anything, let me refine the statement. Firstly, I am not discrediting them because they are very usefully libraries.  Why should they barely exist?  Much of their functionality, as I believe, should be provided [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript needs to grow.  <strong>The Javascript libraries such as Prototype and JQuery should barely exist. </strong> Before you say anything, let me refine the statement. Firstly, I am not discrediting them because they are very usefully libraries.  Why should they barely exist?  Much of their functionality, as I believe, should be provided by the semantics of Javascript and its core libraries (DOM, regexp, window, etc).  This functionality is the majority of my use of JQuery and Prototype.  </p>
<h2>My Wish List of Core Functionality</h2>
<ul>
<li>
<h3>Inheritance</h3>
<p>An easy way to inherit a class, call the parent&#8217;s constructor, call a parent&#8217;s version of a method, and to set members as protected, private, or public.  There <a href="http://dean.edwards.name/weblog/2006/05/prototype-and-base/">are</a> <a href="http://truecode.blogspot.com/2006/08/object-oriented-super-class-method.html">examples</a> that go towards achieve this; but, native support is magnitudes of an improvement just for the sake of improved readability.  (It would be really sweet to have reflection.) For what Mozilla is planning for Javascript 2.0, a more <a href="http://www.mozilla.org/js/language/js20/core/classes.html">traditional class</a> support will be added.
  </li>
<li>
<h3>Get Elements with XPath and CSS Syntax</h3>
<p>There are many more ways to specify elements than by tag name and id. For example class name, attribute, relationship placement,  any of the CSS selectors, and any combination of all them.  This is where <a href="http://jquery.com/docs/BaseTraverse/">JQuery shines</a>; it allows for all of these.  <a href="http://www.w3schools.com/xpath/default.asp">XPath</a> allows for much of this and is <a href="http://www-xray.ast.cam.ac.uk/~jgraham/mozilla/xpath-tutorial.html">starting to gain</a> browser support (Mozilla and Opera).  Now I often want to use a CSS style because I have been using it to match elements for several years now. In the end, I just want something that is rich enough to get elements which may be a combination of XPath, XQuery, CSS syntax, and simple new methods such as <a href="http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/">getElementsByClassName</a>.</p>
</li>
<li>
<h3>Add/Remove Class</h3>
<p>Prototype has <a href="http://www.sergiopereira.com/articles/prototype.js.html#Element">it</a>, JQuery has <a href="http://jquery.com/docs/BaseStyle/">it</a>, and YUI has http://developer.yahoo.com/yui/docs/dom/YAHOO.util.Dom.html#addClass. People want it so just add the functionality of adding a class name, removing a class name, retrieving a list of class names, and checking if an element has a class name to the DOM Element.
</li>
<li>
<h3>DOM Aliases for Common Task</h3>
<p>Back in my early programming class, I learned that if you constantly reuse the same few lines of code (even if they are simple task) to save yourself time and wrap them up in a function.   I mention this because it leads me to the fact that a lot of commonly reused DOM code exist.  </p>
<ul>
<li>
<h3>Creating an element with only a text node as child</h3>
<p><code>var elem = document.createElement(&quot;span&quot;);<br />
var text = document.createTextNode(&quot;Some text.&quot;);<br />
elem.appendChild(text);<br />
//OR<br />
var elem = document.createElement(&quot;span&quot;);<br />
elem.appendChild(document.createTextNode(&quot;Some text.&quot;));<br />
</code></p>
<p>I suggest for the addition of <code>document.createElement( &lt;tag name&gt; [, &lt;text for child text node&gt;])</code>.</p>
</li>
<li>
<h3>Insert an element before or after another element</h3>
<p><code><a href="http://developer.mozilla.org/en/docs/DOM:element.insertBefore">Element.insertBefore</a> and Element.insertAfter</code> never seemed intuitive to me.  At first glance I thought it worked as such <code>referenceElement.insertBefore(newElement)</code> instead of <code>parentElement.insertBefore(newElement, referenceElement)</code>.  So what do I do most of the time (well I use JQuery&#8217;s $.before): <code>referenceElement.parentNode.insertBefore(newElement, referenceElement)</code>. To make matters worse, to insert an element after another element I use the following (again not really because I use JQuery&#8217;s $.after): <code>referenceElement.parentNode.insertBefore(newElement, referenceElement.nextSibling)</code>.<br />
My suggestion is overload the method insertBefore so that if only one parameter is passed that it then will act as I how I first thought it did and to likewise add a simlar insertAfter method.
</li>
</ul>
</li>
</ul>
<p>There is plenty more I can add but not today.  In conclusion, I feel that developing in Javascript gets bogged down because of the extra brain power to remember the work around or the extra brain power to deterimne which library to use to mask the laborious details.</p>
]]></content:encoded>
			<wfw:commentRss>http://moronicbajebus.com/2006/08/31/better-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Add A Class Randomly From a Set</title>
		<link>http://moronicbajebus.com/2006/07/30/add-a-class-randomly-from-a-set/</link>
		<comments>http://moronicbajebus.com/2006/07/30/add-a-class-randomly-from-a-set/#comments</comments>
		<pubDate>Sun, 30 Jul 2006 21:11:25 +0000</pubDate>
		<dc:creator>Seamus</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[CSS]]></category>

		<category><![CDATA[Frontpage]]></category>

		<guid isPermaLink="false">http://moronicbajebus.com/?p=94</guid>
		<description><![CDATA[I was recently asked by a friend for information about how to have a random background image. Well not completely random, the background image should be from a set of images.  My idea: add a class, randomly from a set, to the body (or another element) with Javascript. I could just change the style [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently asked by a friend for information about how to have a random background image. Well not completely random, the background image should be from a set of images.  My idea: add a class, randomly from a set, to the body (or another element) with Javascript. I could just change the style attribute for the background image; but, what if the text is white and one of the images happens to be very light in color? So now I have the issue of ensure that there is adequate contrast in color between the background and text.  Plus there could always be other wishes such as being able to change the border color.  So, for me, changing the class gives far greater flexibility for a script. Now I show you my very <a href="/wordpress/wp-content/files/add-a-class-randomly-from-a-set/randomClassName.html">simple example of the code</a>.</p>
<h2>How to use:</h2>
<ol>
<li>Download <a href="http://jquery.com/">JQuery</a></li>
<li>Download <a href="/wordpress/wp-content/files/add-a-class-randomly-from-a-set/AddAClassNameAtRandomToAnElement.js">AddAClassNameAtRandomToAnElement.js</a></li>
<li>Include jquery.js and AddAClassNameAtRandomToAnElement.js in your html: <br />
           <code>&lt;script src=&#34;jquery.js&#34;>&lt;/script><br />
&lt;script src=&#34;AddAClassNameAtRandomToAnElement.js&#34;></code></li>
<li>Create the set of classes to have randomly selected and the query of the element to add the class to: <br />
<code>&lt;script> <br />
var setOfRandomClassNames = new Array(&#34;aa&#34;, &#34;bb&#34;, &#34;cc&#34;); // three classes with the names: aa, bb, and cc<br />
 //var queryForElementsToAddRandomClassTo = &#34;body&#34;; // adds the class name to the body <br />
 var queryForElementsToAddRandomClassTo = &#34;#cow&#34;; // adds the class name to an element with the id of cow<br />
&#8230;</code></li>
<li>Add the call to add the class:<br />
<code>&#8230;<br />$(document).ready(function(){ <br />
&nbsp; &nbsp;$(queryForElementsToAddRandomClassTo).addRandomClass(setOfRandomClassNames);}<br />
});<br />
&#8230;&lt;/script></code></li>
</ol>
<h2>Update</h2>
<p>I changed it from an independent function to a method (<a href="http://jquery.com/docs/Plugin/">JQuery Plugin</a>) of the $ as <a href="/2006/07/30/add-a-class-randomly-from-a-set/#comment-482">John Resig suggested</a>.  Keep up the good work on JQuery John!</p>
]]></content:encoded>
			<wfw:commentRss>http://moronicbajebus.com/2006/07/30/add-a-class-randomly-from-a-set/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
