Injecting inline formated xml in javascript

Sometimes is good tho have some code like this:

1
2
3
4
var html =
<form>
    <input type="text">
</form>;

But for now is not posible to do until E4X is adopted by all the browsers…

A tricky way to do it is to use the javascript /*! comments */ inside a function definition, to store the real formated xml.

How to define a variable in comments:

1
2
3
4
5
6
7
    /*!
    {"embed":{ "id":"form" } }
    <form>
        <input type="text" name="user"/>
        <input type="text" name="password"/>
    </form>
    */

First line begins with a normal multiline comment /* and the ! simbol, ATTENTION, that way, starting width /*! we tell some javascripts mimimizers that this is a special comment and they must left the comments as is in the source code.
Second line tells the parser the variable asignation name of the content.
The declaration must end width the close comment tag */ in a new line.

Full example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var data = function()
{
    /*!
    {"embed":{ "id":"form" } }
    <form>
        <input type="text" name="user"/>
        <input type="text" name="password"/>
    </form>
    */


    /*!
    {"embed":{ "id":"button"} }
        <button value="Send">
    */
                 
}
var parsedData = window.parseEmbeds(data);
alert( parsedData.form )
alert( parsedData.button );

The main parseEmbeds function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(function(window)
{
    window.parseEmbeds = function( fn, opt )
    {  
        var dataObj = {}
        var regex_comments = /\*(.|[\r\n])*?\*/gi;
        var code = fn.toString().match( regex_comments );
        var comment;
        var lines;
        var outputString;
        var trim11 =function(str){str = str.replace(/^\s+/, '');for (var i = str.length - 1; i >= 0; i--) {if (/\S/.test(str.charAt(i))) {str = str.substring(0, i + 1);break;}}return str;};
        for( var i=0; i<code.length; i++ )
        {  
            comment = code[ i ];
            if( comment.indexOf('{"embed":')!=-1 )
            {
                lines = comment.split('\n');
                outputString = "";
                for( var e=2; e
    <lines.length-1; e++ )
                {
                   outputString+=trim11(lines[e]);
                }
                dataObj[ JSON.parse( lines[ 1 ] ).embed.id ] = outputString;
            }
        }
        return dataObj;
    }
})(window);

Testing Iphone Webapps in iPad

How to use my iPad to verify sites developed for iphone …

To carry out the process, we need a Jailbroken iPad, iFile and OpenSSH installed.

The process is very simple, enter the terminal and access your ipad through ssh using root and alpine as username / password:
[cc lang = "xml"]
ssh root@ip.de.nuestro.ipad
[/ cc]

Once we have accessed use the following commands to make a copy of MobileSafari:
[cc lang = "xml"]
cd / Applications /
cp-R MobileSafari.app / MobileSafariIphone.app
[/ cc]

After the copy process is done, use iFile to navigate the next directory:
[cc lang = "xml"]
Disk -> Applications -> MobileSafariIphone.app
[/ cc]

Edit the info.plist file, look for an entry called CFBundleIdentifier and change its value to com.apple.mobilesafariiphone. This tells the system recognize the executable as an independent application from the original safari.
After that change the value of UIDeviceFamily entry removing the line 2 .

With this we have a copy of Safari, version iPhone.

Respring for the changes to take effect.

OSX 5005:Unknown error optimizing byte code

Working in a large AIR project, the flash compiler give me this strange error:

1
5005:Unknown error optimizing byte code

To avoid it , we must increase the memory of the compilator by creating a file in:

1
~/.MacOSX/environment.plist

and put this text in it:

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>JAVA_TOOL_OPTIONS</key>
<string>-Xmx512m</string>
</dict>
</plist>

If you use flash CS5 also edit this file:

1
~/Library/Application Support/Adobe/Flash CS5/en_US/Configuration/ActionScript3.0/jvm.ini

Then change -Xmx128m to -Xmx512m