<style></style> since 2000
min-width works in Firefox and Safari, and even IE 7, but not IE 6 -- big surprise. However, we can fake it fairly well. With a little jQuery fun, we can read the min-width value, and then implement it using javascript fairly nicely.
First off, we know we have to attach this to the resize of the browser. IE seems to execute the resize event many, many times during an actual window resize1 -- almost as if it were trying to execute it once every pixel resized (just a guess).
Enter the wresize jQuery plugin. This plugin tries to catch when the resize starts, and more importantly, when it finishes, and then executes a function. The one downside to this plugin is that we cant execute a function that requires us to pass any variables to it. Luckily, we don't need to for this.
Here are the things we need to do:
min-width.min-width on the first div inside the body element.min-width when the browser window widens. Simple, right? Here's the actual min-width function:
function minwidth() {
if ( (jQuery.browser.msie) && (jQuery.browser.version==6) ) {
var cssprop = jQuery("body div").css("min-width");
if ( cssprop == null ) {
cssprop = 760; //No min-width; default to min-width of 760
} else {
cssprop = parseInt(cssprop); //Convert value to numeric;
};
//get document margin to figure browser width to look for
var margin = parseInt( jQuery("body").css("margin-left") ) + parseInt( jQuery("body").css("margin-right") );
//21px is the width of the scroll bar.
if (clientwidth() < (cssprop + margin + 21)) {
jQuery(document.body).width(cssprop); //Set fixed-width
} else {
jQuery(document.body).width("auto"); //Un-set fixed-width
};
};
};
Now that's just the function; we haven't used it yet. We need to execute this function on page load, and use the wresize plugin to execute the same function on resize. Luckily, that's simple too.
$(document).ready(function(){
minwidth(); //call IE minwidth on page load
$( window ).wresize( minwidth ); //IE Resize event - resize for min-width
});
We didn't cover the clientwidth() function -- that's how we're getting the browser's window size. Check out the example page for the final result.
1http://snook.ca/archives/javascript/ie6_fires_onresize/
Well I know everyone was on the edge of their seats, however, all can relax: the bug has been fixed.
All I did was create a way to manage what ‘view state’ I was in, rather then doing a if/then of the current class name. My only made-up explanation I can come up with for why this works is that on page load, jQuery builds a giant array of your page elements and properties. When I start swapping class names around, that array isn’t being updated. Therefor, I just needed to come up with a method for tracking the state and query that rather then the current class name. Now all is well.
See it in action, or, you can download the .NET project and see it in action. I don’t care for .NET, but it’s what I had at the time—that and I don’t know php (yet).
With a little down time at work, I started to make a few jQuery example pages for some quick documentation. One thing led to another, and I’ve decided to build a light version of the Google Reader interface. Check it out.
I wrote a detailed, albeit probably jumbled, post to on jQuery’s Google Group about my bug. Here’s a quick recap: I have two functions that depend on a wrapper div’s class. When I first load the page, I set that wrapper’s class based on a cookie. From then on, my two functions don’t function based on what the wrapper div currently is, but what it was at page load. Somehow it’s not seeing the current wrapper class. Do you know why? Two gold stars to anyone who solves it!
I started building this interface just to see what I could do with jQuery. Once I get all the bugs worked out, I'd be nice to hook it up to a RSS feed and see it actually function. Perhaps a good excuse to start learning PHP, and maybe even Code Igniter.
Instiki is a light wiki built on Ruby On Rails, however I'm not sure if it is still be maintained. I use it to maintain a lot of ideas and examples, mostly code heavy content. One thing that could make Instiki better would be syntax highlighting -- so lets implement it.
/instiki/app/views/layouts/default.rhtml and start implementing.
I'm not entirely sure how/where all the javascript is being rolled into the main template page of Instiki, so instead of tracking that down we can just put some good ol' fashioned <style></style> links.
Right after <%= javascript_include_tag :defaults %> put:
<link type="text/css" rel="stylesheet" href="/stylesheets/highlighter/SyntaxHighlighter.css"></link> <script type="text/javascript" src="/javascripts/highlighter/shCore.js"></script> <script type="text/javascript" src="/javascripts/highlighter/shBrushCss.js"></script> <script type="text/javascript" src="/javascripts/highlighter/shBrushJScript.js"></script> <script type="text/javascript" src="/javascripts/highlighter/shBrushXml.js"></script> <script type="text/javascript" src="/javascripts/highlighter/shBrushVb.js"></script>Now I only added the few language files that I needed -- You, of course, should link to whichever ones you need. At the bottom of
default.rhtml, right above </body> put:
<script language="javascript">
dp.SyntaxHighlighter.ClipboardSwf = '/flash/highlighter/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
</script>
<pre> tag, set name attribute to code and class attribute to the language of your choosing.
<pre name="code" class="js"> ... some code here ... </pre>For the full run down of it's usage and options, check out the project page.
| Language | Class Name(s) |
|---|---|
| C++ | cpp, c, c++ |
| C# | c#, c-sharp, csharp |
| CSS | css |
| Delphi | delphi, pascal |
| Java | java |
| Java Script | js, jscript, javascript |
| PHP | php |
| Python | py, python |
| Ruby | rb, ruby, rails, ror |
| Sql | sql |
| VB | vb, vb.net |
| XML/HTML | xml, html, xhtml, xslt |
name attribute on a <pre> tag is not valid XHTML.
Howdy. I'm Richard W. Baker - a designer based in Jacksonville, Florida with a passion for information architecture and usable interfaces. At my day job, I work for the City of Jacksonville as a User Interface Designer.
If you still have questions, or you're interested in hiring me for your next project, .
coming soon
coming soon