Last mouse-click position and X / Y coordinates

Note to myself: This comes up at least once per project. Time to writes this down and revisit/update it whenever warranted.

Ever needed to get the X / Y coordinates of exactly where that last mouse-click took place on a web page? Happens tome all the time. So here’s a JavaScript code snippet that I’ve been using lately:

 

            var offset, _x, _y;
            $(‘.selector-class’).click(function(e) {
              offset = $(this).offset();
              _x = (e.clientX – offset.left);
              _y = (e.clientY – offset.top);
              console.log(e.clientX – offset.left);
              console.log(e.clientY – offset.top);
            });

 

Please let me know if you run into any problems on a specific platform and within a specific web browser. It would be good to know when this snippet needs to get updated to support more web browsers on different platforms, so please leave a specific comment if you notice any problems with this snippet. Thanks!

Special thanks to Brian McKenna who posted the basis for this post at http://bit.ly/11QY51b.

Dear Recruiter . . .

Dear Recruiter,

From what I gather there seems to be a big demand for people with my skill set at the moment. It is merely an educated guess on my behalf, based on the number of phone calls, tweets, e-mail messages and linked-in messages I receive from recruiters on a daily basis.

Rather than talking about how distracting and time-consuming it is to follow up on every call, tweet and message, may I offer you some gentle advice, well-intentioned and straightforward?

Here is a bit of professional and respectful advice to all those recruiters who have been flooding my in-box, twitter and linked-in accounts:

1.     Be curteous. If you cannot afford the time to look up my name – and address me by name in your e-mail message – be assured that I will automagically delete your message without reading it. To me, such messages come across as BULK SPAM attacks. You have probably sent the same message to dozens of other people with a skill set similar to mine. It may probably be the easiest way for you to get the word out, but it may also be the quickest way for me to discard your e-mail messages.

2.     Act professionally. If we are not connected on LinkedIn, do not send me an invitation to connect, complete with a job description and your phone number. I will certainly not call you, and I will most certainly not want to connect with you. You are using SPAM tactics, and it comes across as immature, annoying and very unprofessional. You seem desperate.

3.     Get organized. If one recruiter from your company has already made contact with me, and if I am working with that recruiter – do not contact me. Especially, do not throw your colleague under the bus by telling me that it was his fault that you did not know somebody from your company is already working with me. When I then tell you, “Thank you very much, but my needs are covered,” please, do not follow up with additional messages. I am done with you.

4.     Change your tone. You may feel tempted to start your 9-point font size e-mail message with, “As you may already know, I’m a professional recruiter with . . . .” However, I am begging you, please do not do that. It comes across as arrogant, especially when the rest of the message seems to have randomly bold words or phrases. Are you screaming at me? Too bad, because I will certainly not read through such a message, because, as you may already know, I have just gotten very annoyed by you.

5.     What’s up with your grammar and spell-checking? Sometimes I wonder whether you actually read what you send out BEFORE you do so. I mean, do you ever read those messages out loud to yourself before hitting the SEND button? It would do you a lot of good to do so. Instead, many (if not most) of your messages have typos all over the place. Are you in such a hurry to meet your daily quota of unsuspecting laborers such as me? By the way, a little punctuation in the right places can do wonders to your message. A lot of punctuation, namely exclamation points, in rapid succession, does not entice me to read your poorly phrased message. I presume that your personality resembles your prose, and for that very reason I will automagically delete such messages.

6.     Having fun with fonts, font sizes and font colors, eh? Pardon my direct approach. To you and your colleagues, it must be marvelous to see a message that contains at least three (3) different fonts (not counting the one you use in your e-mail signature) in several sizes and colors . . . for absolutely no good reason. To me it is annoying. Very annoying. Do not do that, because, as you may already know, I will most certainly abstain from reading something that looks like a high school flyer for a tattoo festival.

7.     If you are a recruiter from India, and you call me, telling me your name is Albert, you might as well call me Raji. I would rather deal with the real you – as long as you have been able to avoid the six aforementioned pitfalls – than having to deal with someone who is blatantly and openly using a fake name. As a matter of fact, if you happen to be an Indian recruiter, please do address me as Raji. No matter what.

8.     Do you answer phone calls from numbers you do not recognize? I do not. And if you actually care enough to leave me a voice message, please speck clearly and somewhat well paced. I do not understand you when you are mumbling. I have a hard time grasping what you say when your words fly by me at 100 mph. If you do not know me, make a good first impression. Be courteous on the phone and leave me a clearly spoken message, detailing the reason for your call. As you may have already guessed, I might actually call you back.

9.     Do not send me a message, telling me that you have come in contact with my resume. The resumes I have in public places, such as monster for example, are up-to-date, but then again, you would not know this fact, because you have not actually made time to bother and take a closer look at my resume. How do I know you wonder? Easy. You send me messages about jobs that include technologies, abbreviations and who-the-heck-knows what else, and obviously you would not ask me to be interested in a Rocket Science Engineer position, had you actually read my resume. Furthermore, do not contact me when your goal is to get a live body into your office for a get-to-know-each-other chat. Do you not have enough work to do already? Do you think I have spare time lying around, wondering what to do during normal business hours? I do not have any extra time as it is, and I do not want a log-term personal relationship with you.

10.     The advice given freely and gladly in this piece of writing does not apply to every single recruiter with whom I have contact. As a matter of fact, a very few of you are very polite, professional and forthcoming. So do not feel offended, my dear friend, since I was only talking to the other 99 percent of recruiters.

Thank you for your attention. If you actually made it through this entire piece, then you will now know what to do to get in touch with me about a career changing position. I thank you for your time.

Respectfully,

WebGyver

aka Dee Binggeli

Scope Your CSS (simple version)

Scenario: You’re working on a web application or web site with a number of other developers and designers. Everybody is responsible for her/his modules, but in the end, everyone needs to adhere to the company’s look-and-feel.

If you’re working for a start-up, where nobody has time to write a style guide, and the delivery date was supposed to have been two days ago, that means, everybody is going to run into situations in which certain page elements need to be styled just a little bit differently than they are on all the other pages. Sounds like chaos, but it can happen. For example, your team might have assigned a standard width to <select> elements, but then you end up building the payment page, and you need smaller <select> fields for, say, the expiration month and year.

Even though you may give your <select> elements specific class or ID names, if there’s a “global power CSS” somewhere that sets the styles for <select> elements, you could be hosed.

On top of that, the three other designers/developers on your team need to have the width of the <select> element to be set to auto, of course. So your page looks something likes this:

Chaotic Form Fields

Chaotic Form Fields

There are a number of solutions to address this issue. For example, you could specifically target a <select> element, based on its position in the document, considering the surrounding elements, class names and IDs. Or you could target the form, and then count which nth-elements the <select> elements are and try your luck that way. You could get as specific as possible and precisely define the entire element, class, ID chain leading to the select element (but that’s overkill and can lead to other problems).

Several similar approaches to the ones mentioned above all have one thing in common: What happens if somebody moves the form elements around? Or what would happen if additional form elements got added somewhere before the <select> elements? Then the hierarchy is no longer accurate and you’re back at square one.

Now most seasoned CSS designers would advise you to use classes or IDs for those particular elements, and that makes perfect sense, of course. Actually, I would presume that you’ve done this all along. However, that in and of itself does not always solve your problem. Especially when you’re using a third-party CSS framework, such as bootstrap.css, for example.

At least in my experience, I have found it difficult to “escape” or “override” the confines of bootstrap.css for one-off solutions. Too many CSS definitions for the <select> element. (If you want to check it out yourself, just open up bootstrap.css and search for SELECT, and you’ll see what I mean.)

Of course, I can already hear several readers protest, “But why use bootstrap.css in the first place?” Let’s just say it is there, and you’re ranking very low on the totem pole, so there’s not much you can do, for argument’s sake.

Scope: Most likely however, you will be able to add an opening <div> at the very top of the document (even if you only get to work on a template file that represents the web page’s contents) and a closing </div> at the end of the document. Typically, I simply add a class name to that <div> to represent the page (or the module), like so:

 

And that’s it. You won’t do anything else with that <div>. No style assignments or anything. Just let it sit there. (If a <div> causes any kind of a problem, use a <span> tag instead.)

Now you can specify your <select> elements like so, for example:

 

 

Or use your own preferred measurement unit (rem, em, px, etc.).

What this does is apply a specific width to the <select> element with a class of .expiry-month that is located between the opening and closing  <div> with a class of .pg-credit-card.

Now in some cases, you might still encounter problems, and the width of the <select> element won’t budge. In that case, I would first check and see if somebody has hard-coded the width of the <select> element, using inline style attributes. You can use Firebug (or any equivalent web developer tool) to find out stuff like that.

Occasionally, somewhere somebody is running a piece of JavaScript code to set the styles of specific elements. If that’s the case, go put an end to that. If you need to work this out with a co-worker, be tactful and explain to her/him that setting styles should take place in CSS (or LESS/SASS) files. It’s simply impractical to define styles in JavaScript, and in most cases that I have been involved in, that only leads to maintenance and scalability nightmares.

Let’s say you have exhausted all your resources, and the <select> element still won’t budge. In that case, try the following:

 

 

Yes, yes, yes . . . I know! Nobody who wears an I HEART CSS button would ever do anything like that, leave alone suggest it to the readers of a web design & development BLOG. However, if that works for you and solves your problem, go for it. It is valid CSS and has been established for a reason – just don’t overdo it with the !important attribute.

Most importantly: Whatever you do, make sure it only affects the page elements on the page on which you are working. You don’t want to cause anyone else the same kinds of problems you have just resolved. Right?

The alternative, of course, would be to have a CSS / Style technical lead, who would reign in all those codewranglerss to come up with a living style guide and a master CSS file that would 1) address the overall CSS and 2) provide special sections for page-specific (or purpose-specific) CSS.

At any rate, if you’re in start-up mode, or if you’re working on the third proof-of-concept design for a project, give the CSS Page Scope a try and see whether that might help resolve some specific CSS issues.

Be well, do good work, and keep in touch!

 

 

 

HTML5 code snippets to take your website to the next level

HTML5 code snippets to take your website to the next level

from Cats Who Code at http://www.catswhocode.com/blog/html5-code-snippets-to-take-your-website-to-the-next-level.

Html5 Code Snippets

This is a great collection of HTML5 code snippets that will speed up your front-end web development. From URL and e-mail input types, to RegEx patterns for form validation, to Context Menus with HTML5 (only in Firefox at the moment), to Auto-Completion and HTML5 prefetching.

Tags: html5, code snippets, Jean-Baptiste Jung, web design, web development, frontend web design, frontend web development

It’s Accordion (not accordiAn) . . .

Just quickly, for the benefit of those of us who get hung up by typos, or are otherwise obsessive about the right terminology for the right thing:

The UI element that collapses and expands one group of HTML elements at a time is called an accordion.

Chances are that the majority of the post-Lawrence-Welk generation may have never seen an accordion. This is an accordion:

hohner-accordion

See, the accordion is an instrument that produces sound with wind. You generate the wind by pulling the accordion apart with your hands (while you’re playing), and by pushing it back together again. So sometimes you see the “unfolded” part (expanded), and sometimes you don’t see any of it (collapsed).

 

 

Back again

It has been a few months since my previous blog fell victim to some ruthless injection attacks. No matter what I tried to secure that thing, I just couldn’t keep up with the amount of “bad JavaScript” that messed up many of my files and eventually got me a bad rap with Google. (You know, that red screen that states that visiting this web site might be harmful.)

What baffles me is, why would anyone in their right mind care to vandalize my web site? Considering the blogosphere, I’m a nobody. This blog has been intended to jot down stuff that I probably need to remember for some other time when I’m building web apps, web sites and all that goes along with it.

So in essence, this blog is my extended notebook. If any of the mistakes I’ve made and then corrected – and blogged about it – could help someone else figure out their similar dilemmas, that would really be awesome. And that’s what WebGyver is all about.