<?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>tmtbox &#187; Javascript</title>
	<atom:link href="http://www.tmtbox.com/tag/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tmtbox.com</link>
	<description>technology media and telecomm</description>
	<lastBuildDate>Sun, 01 Jan 2012 17:38:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to redirect URL with Javascript</title>
		<link>http://www.tmtbox.com/how-to-redirect-url-with-javascript</link>
		<comments>http://www.tmtbox.com/how-to-redirect-url-with-javascript#comments</comments>
		<pubDate>Thu, 26 Nov 2009 11:31:59 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://www.tmtbox.com/?p=910</guid>
		<description><![CDATA[&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;1.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#60;script language=”javascript” type=”text/javascript”&#62; window.location.href=”login.php?backurl=”+window.location.href; &#60;/script&#62; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;2.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#60;script language=”javascript”&#62; alert(”back”); window.history.back(-1); &#60;/script&#62; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;3.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#60;script language=”javascript”&#62; window.navigate(”tmtbox.php”); &#60;/script&#62; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;4.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#60;script language=”JavaScript”&#62; self.location=”tmtbox.htm”; &#60;/script&#62; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;5.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#60;script language=”javascript”&#62; alert(”Access Violation”); top.location=”error.php”; &#60;/script&#62;]]></description>
			<content:encoded><![CDATA[<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;1.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&lt;script language=”javascript” type=”text/javascript”&gt;<br />
window.location.href=”login.php?backurl=”+window.location.href;<br />
&lt;/script&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;2.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&lt;script language=”javascript”&gt;<br />
alert(”back”);<br />
window.history.back(-1);<br />
&lt;/script&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;3.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&lt;script language=”javascript”&gt;<br />
window.navigate(”tmtbox.php”);<br />
&lt;/script&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;4.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&lt;script language=”JavaScript”&gt;<br />
self.location=”tmtbox.htm”;<br />
&lt;/script&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;5.&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&lt;script language=”javascript”&gt;<br />
alert(”Access Violation”);<br />
top.location=”error.php”;<br />
&lt;/script&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmtbox.com/how-to-redirect-url-with-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yet Another Image Replacement Method</title>
		<link>http://www.tmtbox.com/yet-another-image-replacement-method</link>
		<comments>http://www.tmtbox.com/yet-another-image-replacement-method#comments</comments>
		<pubDate>Thu, 09 Jul 2009 17:39:53 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.tmtbox.com/?p=825</guid>
		<description><![CDATA[Semantic CSS Image Replacement Yes, &#8220;YAIRM&#8221; (&#8220;Yet Another Image Replacement Method&#8221;) is a crappy acronym. Anyhow…. There have been several image replacement suggestions made over the past 5 years. Semantically, some just don’t make sense. Of course, the accessibility of your image replacement method and the semantic &#8220;correctness&#8221; has to do with how you code [...]]]></description>
			<content:encoded><![CDATA[<h2>Semantic CSS Image Replacement</h2>
<p>Yes,  &#8220;YAIRM&#8221; (&#8220;Yet Another Image Replacement Method&#8221;) is a crappy acronym.  Anyhow….</p>
<p>There have been several image replacement suggestions made over the past 5 years. Semantically, some just don’t make sense. Of course, the accessibility of your image replacement method and the semantic &#8220;correctness&#8221; has to do with how you code your HTML.</p>
<p>Pros</p>
<ul>
<li>This method works for both in-line and block style elements.</li>
<li>Accessible to screen readers and non-image/non-screen media.</li>
<li>Does not add extra elements only for styling (no extra <code>span</code>).</li>
<li>Works cross browser</li>
</ul>
<p>Cons</p>
<ul>
<li>Using images for text does not allow for text resizing (like all <code>IR</code> methods).</li>
<li>Does not handle &#8220;images off/CSS on&#8221; scenario; but neither do most layouts with background images, such as the sidebar on this blog.</li>
</ul>
<p>When I need to replace a header or some other text with an image, I simply give the <code>element</code> my  image replacement class (<code>&lt;h1 class="imgreplacement"&gt;</code>), and declare the background image, height and width I want to use either by providing an ID and defining the background image in the #id selector, or by targeting the <code>element</code> through specific/unique cascade. I place all of my image replacement css in a media=&#8221;screen&#8221;. Even though the media attribute is not heeded by all browsers, it is heeded by devices that are not screens. If your user than prints your webpage, the text that was replaced by an image in the browser will print as it semantically should.<br />
button.imgreplacement {    display:-moz-inline-box;   display:inline-block;   background:transparent none 0 0 no-repeat;   text-indent:-3000px;   font:0/0 Arial;   overflow:hidden;    color:rgba(255,255,255,0);   vertical-align:bottom;   background-image:url(http://www.evotech.net/articles/images/redx.gif);   width: 18px;   height: 18px;   border:none;   cursor: pointer, hand; }<br />
<span id="more-825"></span></p>
<h4>The CSS for the Image Replacement class:</h4>
<pre>.imgreplacement {
  display:-moz-inline-box;
  display:inline-block;
  background:transparent none 0 0 no-repeat;
  text-indent:-3000px;
  font:0/0 Arial;
  overflow:hidden;
  color:rgba(255,255,255,0);
  vertical-align:bottom;
}</pre>
<h4>XHTML markup and CSS Overrides:</h4>
<p>With my image replacement class, the image replacement method is reusable.</p>
<pre>&lt;h1 class="imgreplacment" title="Tool Tip Text here"&gt;Semantic Text&lt;/h1&gt;
&lt;a href="link.html" class="imgreplacement"&gt;Text that makes sense for this link&lt;/a&gt;
&lt;button class="imgreplacement" title="Close"&gt;Close Module&lt;/button&gt;

h1.imgreplacement {
  background-image: url(path/headerimage.jpg);
  height: 60px;
  width: 540px;
	 background-position: 20px 10px;
}

a.imgreplacement {
  background-image: url(path/linkimage.jpg);
  width: 120px;
  height: 60px;
}

button {
  background-image:url(images/redx.gif);
  width: 18px;
  height: 18px;
  border: none; // overwrite default border
  cursor: pointer;
}</pre>
<p>This is the button: <button class="imgreplacement" title="close">Close Module</button>. Note that is has layout, but it’s inline, and it has a tool-tip</p>
<h4>Explanation of the Image Replacement Class:</h4>
<p>The imgreplacement class does the following:</p>
<ul>
<li><code> display:-moz-inline-box;</code><br />
and <code>display:inline-block;</code> displays the element as an inline block. <code>inline-block</code> is not part of the CSS specifications, but it is supported by IE and all other grade-A browsers other than Firefox. This enables the image replacement to work on inline elements by enabling them to have width and height. The first line, <code>-moz-inline-box</code>, is for mozilla based browsers that don’t render <code>inline-block</code>. The second line is for IE, Safari 3 and Opera, though IE does not render <code>inline-block</code> truly inline.</li>
<li><code>background: transparent none 0 0 no-repeat;</code> sets a default to non-repeated background image placed at the top-left of the element block, but does not declare a background image, enabling you to overwrite the <code>none</code> with an image via a second, more precise, CSS declaration</li>
<li><code>text-indent:-3000px;</code> Text indent only applies to block elements. <code>text-indent</code>, when implemented, moves the start of the first line of text to the left or right depending on whether the property is assigned a negative or positive value. The <code>text-indent</code> is applied to <code>inline-block</code> elements, but not to <code>-moz-inline-box</code>. Note that IE does not render text-indent correctly, so generally I override the text-indent property for IE, but in this case the disappearing text quirk is to our benefit.</li>
<li><code>font:0/0 Arial;</code> Makes the font tiny or invisible for browsers. There are a few quirks: Opera doesn’t render this shorthand, and renders <code>font-size: 0;</code> at about 7px; IE6 and IE7 both render the font at about 1px and Safari doesn’t render font at size 0, but does intermittently underline the non-visible character at about 1px width per character.</li>
<li><code>overflow:hidden</code> hides anything that might be wider than the space provided. IE6 has the bad habit of deciding to grow elements to fit the content even if the size of the element is defined.</li>
<li><code>color:rgba(255,255,255,0);</code> Makes the font color transparent (opacity of 0) for those browsers that understand opacity via RGBA, which is a feature of CSS3 (Safari 3 and pre-alpha version of Firefox 3, but not IE6, IE7 or Firefox 2 for Windows).</li>
<li><code>vertical-align:bottom;</code> is required for the inline elements &#8211; it places them at the same level vertically with respect to the text around it across all grade-A browsers.</li>
</ul>
<h4>Additional tidbits</h4>
<ul>
<li>You have to define the width, height and background image of your element.</li>
<li>If needed, you can set the background position of the replacement image. It causes fewer cross browser issues to place the background image rather than setting margins due to differences in browsers interpretations of the box-model.</li>
<li>Remember to use sematic markup. If the image is an area header, use <code>h1-h6</code>. If it’s a link going somewhere, use <code>&lt;a&gt;</code>. If it isn’t linking anywhere, it’s not a link!</li>
<li>You can enhance the image replacement with a title. The title will display in some browsers as a tool tip. This may enhance the accessibility for those who use tooltips regularly.</li>
<li>You can declare a different background image using the <code>:hover</code> pseudoclass, so when the user hovers over the element with the mouse pointer, the image changes.</li>
</ul>
<p>While I just showed you a method of doing image replacement, I must caution against it. Using images for text is not optimum for accessibility. This method enables assistive devices to read your text with the semantic meaning defined by the encompassing element(s). This method enables users of alternative devices, such as cell phones, and text-only browsers to read your content. It also meets web standards in terms of separating content from presentation. However, when you use images to render text, your visitor is unable to control the font-size; which makes your site less than accessible. If you are required to use images instead of text to render content, and you can’t convince your client (boss, designer or contractee, or even yourself) of the stupidity (there, i said it) of using images for text, then this is the best method of making your inaccessible page accessible to the most people. Just try to make the text in your image large enough to be read by a user.(Via evotech.net)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmtbox.com/yet-another-image-replacement-method/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>About the drag and drop</title>
		<link>http://www.tmtbox.com/about-the-drag-and-drop</link>
		<comments>http://www.tmtbox.com/about-the-drag-and-drop#comments</comments>
		<pubDate>Tue, 05 May 2009 17:31:33 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[drag and drop]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.tmtbox.com/?p=776</guid>
		<description><![CDATA[Visual development environments typically let you manipulate objects in an application by selecting them with a mouse and moving them around the screen. Drag and drop lets you select an object, such as an item in a List control, or a Flex control such as an Image control, and then drag it over another component to add it [...]]]></description>
			<content:encoded><![CDATA[<p>Visual development environments typically let you manipulate objects in an application by selecting them with a mouse and moving them around the screen. Drag and drop lets you select an object, such as an item in a List control, or a Flex control such as an Image control, and then drag it over another component to add it to that component. You can add support for drag and drop to all Flex components. Flex also includes built-in support for the drag-and-drop operation for certain controls such as List, Tr e e, and DataGrid, that automate much of the processing required to support drag and drop.</p>
<p>The drag-and-drop operation has three main stages: initiation, dragging, and dropping:</p>
<p><strong>Initiation </strong>A user initiates a drag-and-drop operation by using the mouse to select a Flex component, or an item in a Flex component, and then moving the component or item while holding down the mouse button. For example, a user selects an item in a List control with the mouse and, while holding down the mouse button, moves the mouse several pixels. The selected component, the List control in this example, is the drag initiator.</p>
<p><strong>Dragging </strong>While still holding down the mouse button, the user moves the mouse around the Flex application. Flex displays an image during the drag, called the drag proxy. A drag source object (an object of type DragSource) contains the data being dragged.</p>
<p><strong>Dropping </strong>When the user moves the drag proxy over another Flex component, that component becomes a possible drop target. The drop target inspects the drag source object to determine whether the data is in a format that the target accepts and, if so, allows the user drop the data onto it. If the drop target determines that the data is not in an acceptable format, the drop target disallows the drop.</p>
<p>A drag-and-drop operation either copies or moves data from the drag initiator to the drop target. Upon a successful drop, Flex adds the data to the drop target and, optionally, deletes it from the drag initiator in the case of a move.</p>
<p>The following figure shows one List control functioning as the drag initiator and a second List control functioning as the drop target. In this example, you use drag and drop to move the ’Television’ list item from the drag initiator to the drop target:</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/asuge/EntryImages/20090225/drag_01.jpg" alt="" width="438" height="191" /></p>
<p>A single Flex component can function as both the drag initiator and the drop target. This lets you move the data within the component. The following example shows a List control functioning as both the drag initiator and the drop target:</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/asuge/EntryImages/20090225/drag_02.jpg" alt="" width="291" height="155" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmtbox.com/about-the-drag-and-drop/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powering Javascript UI with CSS</title>
		<link>http://www.tmtbox.com/powering-javascript-ui-with-css</link>
		<comments>http://www.tmtbox.com/powering-javascript-ui-with-css#comments</comments>
		<pubDate>Fri, 16 Nov 2007 10:08:35 +0000</pubDate>
		<dc:creator>kevin</dc:creator>
				<category><![CDATA[resource]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.tmtbox.com/archives/powering-javascript-ui-with-css</guid>
		<description><![CDATA[If you have been doing any Javscript coding during the current Javascript renaissance, you will have noticed that a lot of the user interface functionality you build is hiding and showing things. After a while of this you might find yourself coding up toggle functions, which find elements and toggle their visibility. togglePair, toggleVisibilityById, there [...]]]></description>
			<content:encoded><![CDATA[<p class="entry-body">If you have been doing any Javscript coding during the current Javascript renaissance, you will have noticed that a lot of the user interface functionality you build is hiding and showing things.</p>
<p>After a while of this you might find yourself coding up toggle functions, which find elements and toggle their visibility. togglePair, toggleVisibilityById, there are lots of these types of functions in javascript apps today.</p>
<p>I&#8217;ve been trying out a different way of dealing with the need to change the UI based on user inputs or asynchronous data events: CSS.</p>
<p id="more" class="entry-more">With CSS, you can use the DOM as a data model and then use declarative rules to establish the display. It&#8217;s cleaner, because you limit your javascript code to changing the DOM&#8217;s data instead of it&#8217;s UI, and then you use the extensive abilities of CSS to handle the visual representation of that data.</p>
<p>Here&#8217;s an example. A common thing to do with javascript seems to be expanding out a form to fill out. <a href="http://livejournal.com/">Livejournal</a> does this with their login form, or 37Signal&#8217;s <a href="http://tadalist.com/">tadalist</a> uses this when you want to add an item to your todo list.</p>
<p>here&#8217;s the just javascript way to do this:</p>
<pre>&lt;div&gt;
  &lt;span onClick='document.getElementById("form1").style.display="block";'&gt;click me to add a comment&lt;/span&gt;
&lt;/div&gt;
 ...
&lt;form id='form1'&gt;
&lt;textarea&gt;add your comment&lt;/textarea&gt;
&lt;/form&gt;</pre>
<p>But here&#8217;s the CSS + Javascript way to do it.<br />
CSS Rules</p>
<p>form#addComment {</p>
<p>display:none;</p>
<pre>}

form#addComment.editing {
  display:block;
}</pre>
<p>Javascript + HTML</p>
<pre>&lt;div&gt;
  &lt;span onClick='document.getElementById("addComment").setAttribute("class","editing");'&gt;click me to show form&lt;/span&gt;
&lt;/div&gt;
 ...
&lt;form id='addComment'&gt;
&lt;textarea&gt;fill in some data here&lt;/textarea&gt;
&lt;/form&gt;</pre>
<p>This can prove really advantageous when you are radically changing the visual presentation of the page. Instead of finding and changing the style of tons of elements by id, you can change 1 element&#8217;s class and then use the inheritance of CSS to style all the sub-elements.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmtbox.com/powering-javascript-ui-with-css/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

