FORCÉN

a.k.a. el turista accidental

Archive for enero, 2011

Be kind, be multilingual

  • Filed under: PHP
Martes
ene 18,2011

The problem: we want to have a page in several languages. Without having to create one html file for each page for each language.

The solution can be divided in three parts:

1. how to know in which language we must show the page,

2. how to render the “structure” of the pages and

3. how to get the content of the pages.

In this entry I’ll show how to code, in PHP, the fist part of the solution.

(más…)

Jueves
ene 13,2011

Last night, during our local NSCoders meeting, one of my fellow coders asked me how to replicate some functionality using CSS. It turned out that the functionality required more JavaScript than CSS.

In Twitter the user can slide a twit to show some controls that relate to that twit.  Jorge wanted to imitate this behaviour. After a fast search I explained him how to “bind” some JavaScript to the touchmove and touchend events. This morning, remembering the question I tried to code some fast example implementing a similar functionality.

Basically the user initiates an slide on an element of the list. When the element has been slided past a point it opens completely, revealing the controls beneath.

(más…)

Passing PHP variables to JavaScript

Martes
ene 4,2011

I was involved in a project this December where, in order to simplify the code and due to some ill-conceived piece of code, it was required to pass some variables from PHP to JavaScript. On other projects you may need to pass arrays or localized text to your JavaScript, for example to show messages. Or to fill a dinamic interface.

There are multiple ways to pass data from PHP to JavaScript: populating hidden inputs or writing the JavaScript into the main page. But I wanted to have a more clean approach.

So, I subclassed a class I wrote some time ago as an utility for handling interface configurations to handle those JavaScript globals without having to worry about the problem in each project. As a result now I have a set of three classes to ease the coding of both configuration strings and JavaScript globals. In appearance very disparate problems, but that use the same basis: magic PHP methods.

(más…)