Archive for the ‘Java2Script’ Category

Google Talk Client’s Java SWT Desktop Copy

Wednesday, August 15th, 2007

Actually, Google Talk Client’s Java SWT desktop copy is the original source for Google Talk Client’s JavaScript copy.

And now it is available for download. Please take a trial.

Sources of Java2Script Google Talk will be available in the next week. Keep tuned.

Google Talk Client’s JavaScript Copy

Friday, August 3rd, 2007

http://demo.java2script.org/gtalk/

Here is the screenshot:

Click for Large Screenshot: Google Talk Client’s JavaScript Copy

En, in beta …

Busy Days on Java2Script Google Talk

Sunday, July 29th, 2007

Ya, these days were very busy.

I had spent more than a month on rewriting Java2Script Google Talk. And today, it was almost finished. You can check it out right now.

More works are required to make it robuster and faster. Maybe Java2Script Google Talk will be publicly released in the next week.

And next release of Java2Script is on the way too. It will be a 1.0.0 RC release. Four months was a long long time since last release.

Add Source Highlighting to Wordpress Editor

Saturday, June 9th, 2007

If you are a technical geek, you may want to write some blog articles attaching some sources for discussion. And if you are using Wordpress, you may find a lot of difficulties in struggling with Wordpress’ messy TinyMCE editor in preserving codes format.

Thanks for early Wordpress bloggers, there are some plugins trying to solve this problem. A known plugin is “Preserve Code Formatting“. But that plugin may be not good enough for you, at least not good enough for me.

I modify that plugin a little, and deploy it in my Wordpress 2.2. And I also add my own source syntax highlighting tools.

Here is my modified preserve-code-formatting.php:

<?php
/*
Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

function c2c_prep_code( $text ) {
$use_nbsp_for_spaces = false;

$text = preg_replace("/(\r\n|\n|\r)/", "\n", $text);
$text = preg_replace("/\n\n+/", "\n\n", $text);
$text = str_replace(array("&#36&;", "&#39&;"), array("$", "’"), $text);
//$text = htmlspecialchars($text, ENT_QUOTES);
$text = preg_replace("/\n\s+\n/", "\n&#160;\n", $text);
$text = str_replace("\t", ' ', $text);
if ($use_nbsp_for_spaces) $text = str_replace(' ', '&#160;&#160;', $text);
// Change other special characters before wptexturize() gets to them
$text = c2c_anti_wptexturize($text);
//$text = nl2br($text);
return $text;
} //end c2c_prep_code()

// This short-circuits wptexturize process by making ASCII substitutions before wptexturize sees the text
function c2c_anti_wptexturize( $text ) {
$text = str_replace('—', '&#45;&#45;-', $text);
$text = str_replace('–', '&#45;-', $text);
$text = str_replace('…', '&#46;..', $text);
$text = str_replace('“', '&#96;`', $text);

// This is a hack, look at this more later. It works pretty well though.
$cockney = array("’tain’t","’twere","’twas","’tis","’twill","’til","’bout","’nuff","’round");
$cockneyreplace = array("&#39;tain&#39;t","&#39;twere","&#39;twas","&#39;tis","&#39;twill","&#39;til","&#39;bout","&#39;nuff","&#39;round");
$text = str_replace($cockney, $cockneyreplace, $text);

$text = preg_replace("/’s/", '&#39;s', $text);
$text = preg_replace("/’(\d\d(?:&#8217;|’)?s)/", "&#39;$1", $text);
$text = preg_replace('/(\s|\A|")\'/', '$1&#39;’, $text);
// $text = preg_replace(’/(\d+)”/’, ‘$1"’, $text);
$text = preg_replace("/(\d+)’/", '$1&#39;', $text);
$text = preg_replace("/(\S)’([^’\s])/", "$1&#39;$2", $text);
// $text = preg_replace(’/(\s|\A)”(?!\s)/’, ‘$1"$2′, $text);
// $text = preg_replace(’/”(\s|\S|\Z)/’, ‘"$1′, $text);
$text = preg_replace("/’([\s.]|\Z)/", '&#39;$1', $text);
$text = preg_replace("/ \(tm\)/i", ' &#40;tm)', $text);
$text = str_replace("”", '&#39;&#39;', $text);

$text = preg_replace('/(d+)x(\d+)/', "$1&#120;$2", $text);

$text = str_replace("\n\n", "\n&#160;\n", $text);
return $text;
} //end c2c_anti_wptexturize()

function c2c_preserve_code_formatting( $text ) {
$text = str_replace(array('$', "’"), array('&#36&;', '&#39&;'), $text);
$tags = array('code', 'pre');
foreach ($tags as $tag) {
$text = preg_replace(
"^(<$tag>)\n?([\S|\s]*?)\n?(</$tag>)^ie",
"’<$tag>’ . c2c_prep_code(\"$2\") . ‘</$tag>’",
$text
);
}
$text = str_replace(array('&#36&;', '&#39&;'), array('$', "’"), $text);
return $text;
} //end c2c_preserve_code_formatting()

add_filter('the_content', 'c2c_preserve_code_formatting', 9);
add_filter('the_excerpt', 'c2c_preserve_code_formatting', 9);
// Comment out this next line if you don’t want to allow preserve code formatting for comments.
add_filter('get_comment_text', 'c2c_preserve_code_formatting', 9);

?>

And here is my css style:

.code {
overflow:scroll;
overflow-y:hidden;
background-color:#f0f0f0;
}

code {
white-space: pre;
color: #222;
}

.keyword {
color:blue;
}
.api {
color:navy;
font-weight:bold;
}
.scope {
color:#f0f;
}
.string {
color:green;
}
.comment {
color:#777;
}
.tag {
color:#f70;
}

And here is the instruction to add my source highlighting when editing:
1. Go to visit http://demo.java2script.org/syntaxor/ , and you can highlight your sources there;
2. Copy the link at left upper corner, which started by a blue block;
3. Bookmark any page, and then modify the bookmark’s URL property to the above link location (a “javascript:” link to load source syntax highlighting);
4. Try to write or edit a post in browser, and then click the above bookmarked link, and the same source highlighting application window shows up after a while, try to paste your highlighted HTML source in the wordpress’ TinyMCE editor.

Java2Script ClassLoader’s Loading Modes

Tuesday, May 8th, 2007

There are 3 loading modes in Java2Script ClassLoader.

  1. Loading classes by using <SCRIPT> tag asynchronously (Default mode).
  2. Loading classes by XMLHttpRequest(XHR) asynchronously.
  3. Loading classes by XHR synchronously (May freeze UI when classes are loading).

In order to switch to different loading mode, execute the following line after j2slib.z.js is loaded:

ClazzLoader.setLoadingMode (”xhr.async”); // XHR asynchronously loading

or

ClazzLoader.setLoadingMode (”xhr”); // XHR synchronously loading

or

ClazzLoader.setLoadingMode (”script”); // <SCRIPT> asynchronously loading. No synchronously loading

In asynchronously loading mode, you can specify a time lag between two *.js loading. The time lag may be useful for the browser (Internet Explorer) to update its UI changes. To set time lag as the following examples:

ClazzLoader.setLoadingMode (”xhr.async”, 5); // 5 ms lag

or

ClazzLoader.setLoadingMode (”script”, 5);

But

ClazzLoader.setLoadingMode (”xhr”, 5); // synchronously loading

makes no senses, as there are no time lag in synchronously loading mode.

For more information, please read Java2Script’s ClassLoader source.