Getting root path in Javascript files included in Yii application

A server-side root path in client-side Javascript code? Are you mad? Why would I need this? Well… For example, when referencing image files (placed on server, right?), that are using dynamic paths or for any other reasons can’t be added statically (for example using CSS).

Getting root path in Javascript files is a hard task itself. When do you need to combine this problem with Yii client-assets publishing mechanism, it can become even harder. However, I found nice, clean and simple solution, using HTML5’s data- attributes.

Read More “Getting root path in Javascript files included in Yii application”

Google Loader and ClientLocation object for IP-based geolocation

Google Loader is a convinient way of loading other libraries and APIs.

And, if you know, where to look for you can even find nice examples of now undocumented ClientLocation object, which can give you location of your visitor — less accurate than GPS (navigator.geolocation object), but based on IP address and therefore not requiring user agreement on using this feature.

CSS and JS minifier/beautifier that rocks!

I definitely love and adore Avivo’s CSS/JS Minifier/Beautifier. Mostly for options that similar tools lack. Like: braces on own line, preserve empty lines and ability to select intend character.

It has a small bug in CSS Beautifier. Every : is beautified to : (with space), which breaks pseudo-classes like :hover and and pseudo-objects like ::before. But, this can be easily fixed (manually; simple find-and-replace in text editor).

So, even with this, Avivo’s tool is just fabulous!

Simple element blocker with and without jQuery

If you’re using jQuery the best (the only reasonable?), in my opinion, way to block an element or entire page (for example for updating it contents) is to use blockUI plugin. But, if you only have to block one or two small elements then you may consider writing your own, very simple blocker instad of using blockUI. And if you’re using jQuery only for that purpose (really small project or task), the you may try to do the same without jQuery at all.

Read More “Simple element blocker with and without jQuery”

Free Javascript chess engines and notation board presenters

I had to find a free Javascript based chess engine for one of my projects. I must admit, that I’m a low-level player and much, much lower level chess developer, so I assumed, that there is no chance, you can write such advanced thing like complete chess engine in such simple language like Javascript.

Turned out, I was wrong. I was actually devatated (again and again) with the power and possibilities behind Javascript.

Read More “Free Javascript chess engines and notation board presenters”

Self-adapting images in responsive design

In my humble opinion, responsive design is a future. One layout, carefully designed, will look beautiful and by user-friendly, no matter, which device user will use to view it. Of course, you can craft responsive designed website by hand, but the easiest way is to use some framework. But what about non-framework elements, like for example images? How to style them, what size should they have, to be responsive and look exactly like other, framework elements, on any device?

There are at least few approaches to solve this problem, among which one or two are not that famous.

Read More “Self-adapting images in responsive design”

Catch back button and exit PhoneGap application

This article shows an example, how to respond, when user of your mobile application taps on Back button and how to exit application, after getting user confirmation, that he or she is willing to do so. It also explains, why you shouldn’t do it at all, if you plan to ship your application to multiple platforms, including Apple iOS.

Read More “Catch back button and exit PhoneGap application”

Very simple alternative to jQuery

Often, in many small or very small projects, you include jQuery only to have a conviniend DOM-selectors access via $(selector) and except this, you don’t use jQuery at all. In cases like that using neither jQuery nor smaller Zepto.js isn’t pretty wise.

Here is an example on how to achieve same effect in pure JS with querySelector and querySelectorAll.

Read More “Very simple alternative to jQuery”

Simple way for hiding your email address

They say that SPAM bots are really good these days and can figure out your e-mail out of many “traps”.

I wonder, if they can catch it out of something like this:

<a
    href="mailto:me.nononono@domain.nononono.com"
    onmousedown="this.href=this.href.replace('.nononono','')"
    onkeydown="this.onmousedown()">
contact me</a>

I prefer to think, they don’t and that they’ll crush their ugly spammy teeth on this! :]

JS and PHP or Yii photo manipulation libraries

I was faced with a problem of picking a good photo manipulation library. Either client-side or server-side. Both for working with my newest Yii project. This article is a summary of my quick research in this field.

All JavaScript libraries works on Canvas, so require HTML5 and Canvas-enabled browsers. Most modern browsers supports both of them in newest versions.

The only PHP image manipulation library works mostly on uploaded image.

Read More “JS and PHP or Yii photo manipulation libraries”

A good on-line JS obsfucator for minifying purposes only [updated]

I’ve searched the web for a Javascipt obsfucator for my specific needs — actually a minifier and obsfucator that will minify a code (pretty like BrainJar do) and obsfucate all variables, function names etc. to 1-2 character length (shortest possible). I know that this could be less secure, but due to purpose (internal project), size of the code, not security, is a key here. I also need it as one-click, on-line ready tool.

Since my searches failed, I’ve asked a question on Stack Overflow, but it was closed as off-topic.

Following article is a summary of answers already given on Stack Overflow (before question was closed) plus my some other thoughts and findings.

Read More “A good on-line JS obsfucator for minifying purposes only [updated]”

Changing look of website, if Javascript is disabled

There is a nifty trick, that allows you to change look&feel of your website and even hide certain elements on it, in case user has disabled Javascript in his or her browser.

Facebook is not working, when Javascript is disabled and world collapses, when Facebook is not working, thus no one serious is disabling Javascript nowadays.

Yet, I still think that a good web developer should be prepared for everything. Even for JS turned off…

Read More “Changing look of website, if Javascript is disabled”

Full-featured shooter in 20k of Javascript code!

KhanAcademy showed an example Javascript code on how to write a full-featured space-shooter written in just 1500 lines of code (20k of pure Javascript code after minification).

No matter, whether you are a JS-minification freak or just want to introduce some space shooter on your website to enjoy your visitors — this is certainly worth seeing. Of course, KhanAcademy offers a lot of more nifty Javascript examples.

Non-alphanumeric Javascript?

Ever heard about Brainfuck? It is an esoteric programming language? Designed with only one purpose — to test the boundaries of computer programming… and human brain. It uses only eight single characters ([, ], <, >, +, -, . and ,) as entire set of programming words. Yes, it really fucks your brain!

To mine extreme surprise with proper tools you can turn regular Javascript into very similar brainfucking experience!

Read More “Non-alphanumeric Javascript?”

Using AJAX head-type requests to check size of remote scripts

Checking size for inline scripts is as easy as document.getElementsByTagName('script')[0].text.length (solution taken from here). But, when it comes to measuring size of remote resources things gets a little bit complicated. Mostly due to cross-site restrictions and reducing unnecessary server load. Head-type of AJAX call, not so famous among developers, may help in this case.

Read More “Using AJAX head-type requests to check size of remote scripts”