Wednesday, April 25, 2012

Reintialize TinyMCE after jQuery Load

Bump into the problem of reintializing TinyMCE textbox after replacing the DOM with jQuery load.

The Problem
  1. After saving a form on a page (with multiple forms), I did a jQuery.load() to replace the DOM of the particular section.
  2. Then I run the initialization function to reinitialize all DOMs, including TinyMCE.
  3. I realized TinyMCE contents is not saved after this.

Solution: Initial attempt

After Google-ed for a while, I found this solution from StackOverflow.

tinymce.execCommand('mceRemoveControl', true, 'editor_id');

So, to use it, it would be...

_init = function() {

 /* Some other initialization code here */
 tinymce.execCommand('mceRemoveControl', true, 'editor_id');
tinyMCE.init({
  /* TinyMCE options */
 });
}

Oh, wait...

Some issues:
  1. My 'editor_id' is dynamic... 
  2. I have multiple textboxes

Solution: Second attempt.

Easy. Just use jQuery.each() to loop through all the textbox and remove TinyMCE control from each of them.

_init = function() {
 jQuery('textarea').each(function() {
  try {
   tinymce.execCommand('mceRemoveControl', true, jQuery(this).attr('id'));
  } catch(e) {
  }
 })
 tinyMCE.init({
  /* TinyMCE options */
 });
}

Oh, wait... again...

Some more issues:
  1. Due to asynchronous nature of Javascript, tinyMCE.init() will be executed befure jQuery.each() finishes.


Final Solution

Chain the functions together with jQuery.promise().

jQuery('textarea').each(function() {
 try {
  tinymce.execCommand('mceRemoveControl', true, jQuery(this).attr('id'));
 } catch(e) {
 }
  
}).promise().done( function() {
 tinyMCE.init({
  /* TinyMCE options */
 });
});

:)

Saturday, April 21, 2012

[Guide] Samsung Galaxy S2 ICS

For those of you who are like me - too impatient to wait for Samsung Singapore to release ICS update for i9100 Galaxy S2, can follow the following steps to flash to ICS (and in addition, flash to CM9).

Ice Cream Sandwich 

Android I9100XWLP7 4.0.3 (United Kingdom / Ireland)

1. Download ICS firmware
http://www.hotfile.com/dl/153177481/9861a3a/I9100XWLP7_I9100XEULP5_XEU.zip.html

2. Boot into Download Mode
  1. Turn off phone.
  2. Vol Down + Home + Power


3. Odin Flash Guide
http://forum.xda-developers.com/showthread.php?t=1075278
http://forum.xda-developers.com/showthread.php?t=1406664

ICS is cool, but... the official ROM is still laggy. So I decided to take further steps to mod it to CyanogenMod.
So if you are like me, want a smooth UX, follow the following optional steps :)

Root

3. CF-root by Chainfire.
http://forum.xda-developers.com/showthread.php?t=1103399

4. Remove Yellow Triangle during startup, using TriangleAway from Chainfire.
http://forum.xda-developers.com/showthread.php?t=1494114&highlight=remove+yellow+triangle


CyanogenMod

CyanogenMod Trebuchet. Sweet! :)


5. Download CM Builds
http://download.cyanogenmod.com/?type=nightly&device=galaxys2

6. Boot into ClockworkMod Recovery
  1. Turn off phone.
  2. Vol Up + Home + Power


7. CM9 Flash Guide
http://wiki.cyanogenmod.com/wiki/Samsung_Galaxy_S_II:_Full_Update_Guide

Version Info :)


EXTRA Goodies :p

Install Chrome for Android, which only available on Android 4+
1. Install from Market :)
https://play.google.com/store/apps/details?id=com.android.chrome&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5hbmRyb2lkLmNocm9tZSJd

Chrome to Phone! :]
If you are not in US, follow the follow steps:
1. Download the .APK
http://forum.xda-developers.com/showthread.php?t=756013

2. Install on Chrome
https://chrome.google.com/webstore/search/chrome%20to%20phone