My Blog

contains PHP and other web related content. (Sometimes there are some off topic things - don't freak out!)

Archive for the ‘Uncategorized’ Category

Printing a small segment of the page using JQuery

Monday, November 23rd, 2009

Using Yahoo’s Grid Tools, I created a pretty decent page layout. After all this was complete, I needed to generate a printable version of only a portion of the site. This was a particular set of instructions. I decided to tackle this with JQuery.

The Setup

The page was created with Yahoo’s Grids.
There were 4 sets of instructions on the site.
Each instruction had its own box containing the content – as well as a ‘print this’ link.
Users were liable to click the wrong link – and have to do it again.

The Code

The following is the JQuery I wrote to solve my problem:

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
	$(".printinstructions").click(function(){
		$('.instructionalli').remove();
		var box = $(this).parent();
		$("<style type='text/css' media='print'>#bd,#ft,#nav,#hd{display: none}a.printinstructions{display:none}.instructionalli{display:block}</style>").appendTo($('head'));
		$(box).clone().insertAfter($('body')).addClass('instructionalli');
		window.print();
		return false;
	});

This is what the content may have looked like:

1
2
3
4
5
6
7
8
<div>
<a href="#" class="printinstructions">Print These</a>
<ol>
<li>Do Step 1</li>
<li>Do Step 2</li>
</ol>
</div>
<!-- three more of these -->

The Explanation

First, any time a link with the class ‘printinstructions’ is clicked, the function launches. The first line in the function is responsible for undoing this process I’m about to describe. This is necessary just in case someone clicked the ‘print’ button earlier on the wrong element by accident.

The first step is to get the parent container. This is the content that we’re going to make our only printed content.

Next, create a new stylesheet that makes everything “display: none” except for the body itself. The media type is print. Finally, it does make the class “instructionalli” “display: block”. (Note: I could have just as easily attached the page in the source… but I needed to only have this activate if the print button was clicked).

The final step is to clone the box (that is inside of something that is ‘display: none’) and add that after the body content. Then, add the “display: block” class to it. Finally the window.print() method is invoked. For the most part, the user will have no idea any of this happened. The final result is a printed version of the instruction’s box content only.

Licensing of Code

Friday, April 24th, 2009

Up until now, I have not licensed my code properly. I’m going to try to do so from now on.

How is this code licensed?

The BSD license is how I’m going to proceed: http://creativecommons.org/licenses/BSD/

Ode to a MySpace Layout

Saturday, October 4th, 2008

*sigh* Things change… and so does MySpace.

I had once written an article about how to create a great MySpace Layout – but it is somewhat out of date. I’m not sure if there is any interest in an updated article. In case there isn’t, and I decide to just remove it, I have a picture of what the original design of mine was here…

 

 

 

 

 

 

 

 

 

 

 

No More “The Triangle”

Friday, June 6th, 2008

Well, I’ve officially resigned from “The Triangle.” Don’t worry, I’ve got a new place to keep bring experience to this blog. I look forward to my new opportunities.

Which Conference Should I go to – Help me in 2008

Tuesday, April 1st, 2008

So, luckily, my current employer will pay and make arrangements for me to attend one major conference each year. Last year I attended Mysqlconf, the year before, Zend Con.

Which should I goto this year? Here are the things to consider:

  • I don’t have a US passport – so it has to be in the US – Unless there is enough lead time to get a passport (how much time does that take anymore these days? Do I need to wear the mark of the beast now? *squints at Real-ID*)
  • It has to be something web related (yah very clear Aaron – thanks. Microsoft makes front page and windows Live search – does that make them web related? *sigh* This means web programming language, analysis or tool based. I don’t know how more broad ones like ‘future of web apps’ types would work…)
  • I’d like it to be focused on open source (oracle fans, be damned!)

So – it’s pretty simple. Any suggestions?

Welcome Facebook User!

Tuesday, January 1st, 2008

facebookI wanted to say thanks for clicking my my home page link from Facebook. I hope we’re friends on Facebook – but if we’re not – go back and visit my page at facebook.com/aaronsaray and click the add friend link.

Now that you’re on my website, you can explore more about me. Check out the open source section to view my most recent open source contributions, the book section to review my published work, the art or music sections to see the more ostentatious side of me, or browse around on this page to read more blog entries. Whatever you choose, make sure to end it with a visit to the contact page to make sure you can keep in touch.

Once again, thanks for taking the time to stop by. Hope to hear from you!

-Aaron

Writing a Spelling Corrector

Tuesday, October 23rd, 2007

Normally I like to post content that I’ve actually written, but I can’t pass up linking to this article: How to write a spelling corrector. Its a great piece that explains the math behind the spelling correcting that Google, Yahoo, etc… do when you’re doing a search and gives code examples on how this is accomplished. Very great read!

Welcome Twitter User!

Monday, January 1st, 2001

twitterI wanted to extend a personal greeting to you and thank you for clicking the home page link on my twitter account. (I hope you are following me now!)

Now that you’re on my website, you can explore more about me. Check out the open source section to view my most recent open source contributions, the book section to review my published work, the art or music sections to see the more ostentatious side of me, or browse around on this page to read more blog entries. Whatever you choose, make sure to end it with a visit to the contact page to make sure you can keep in touch.

Once again, thanks for taking the time to stop by. Hope to hear from you!

-Aaron

  • twitter loader

Follow me on twitter: @aaronsaray

The views on this website are my own and do not reflect the opinions of my employer or clients.
Creative Commons License Home | Open Source | Book | Music | Art | Bio | Resume | Contact
My Baby