Permalink
Browse files

Text rendering

core.js introduced
Rules.html and About.html using text rendering and core.js
  • Loading branch information...
1 parent 99b494c commit 7253b4b98388c649e32352d905f3484780ddf21e @tomburger committed Sep 27, 2011
Showing with 121 additions and 119 deletions.
  1. +4 −50 assets/www/about.html
  2. +13 −0 assets/www/about_cz.txt
  3. +13 −0 assets/www/about_en.txt
  4. +86 −0 assets/www/core.js
  5. +1 −16 assets/www/lang.js
  6. +3 −52 assets/www/rules.html
  7. +1 −1 support/test/testframe.html
View
@@ -8,48 +8,12 @@
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="lang.js"></script>
<script type="text/javascript" charset="utf-8" src="webintent.js"></script>
+ <script type="text/javascript" charset="utf-8" src="core.js"></script>
<script type="text/javascript">
$(document).ready(function() {
- parseQueryString();
- loadColors();
- $('.translate').map(function() {
- $(this).text(t($(this).text()));
- });
- $('div#app_rating').click(function() {
- window.plugins.webintent.startActivity(
- {
- action: WebIntent.ACTION_VIEW,
- url: 'https://market.android.com/details?id=cz.burger.android.phonegap.mobileprsi'
- },
- function() {},
- function() { alert('Failed to open Android Market'); }
- )
- });
+ initCore();
+ loadText('about', 'about_text');
});
- function parseQueryString() {
- var qs = window.location.search.substring(1);
- var parts = qs.split("&");
- window.prsi_color_scheme = parts[0];
- window.prsi_language = parts[1];
- }
- function loadColors() {
- var link = $('<link>');
- link.attr({
- type: 'text/css',
- rel: 'stylesheet',
- href: 'colors_' + window.prsi_color_scheme + '.css'
- });
- $('head').append(link);
- }
- function t(txt) {
- var text = texts[txt];
- if (!text) alert(txt);
- var formatted = text[window.prsi_language];
- for(arg in arguments) {
- if (arg > 0) formatted = formatted.replace("{" + arg + "}", arguments[arg]);
- }
- return formatted;
- }
</script>
</head>
<body>
@@ -60,17 +24,7 @@
</h1>
</div>
<div id="about" class="view">
- <div class="about_title translate">about_contact</div>
-
- <div class="about_ref"><span class="translate">facebook_homepage</span><br/>
- <a href="http://www.facebook.com/pages/mobile-prsi/166452220085020">facebook.com/mobile-prsi</a></div>
-
- <div class="about_ref"><span class="translate">twitter_contact</span><br/>
- <a href="http://twitter.com/#!/tomasburger">@tomasburger</a></div>
-
- <div class="about_ref"><span class="translate">app_rating_text</span><br/>
- <div id="app_rating" class="button translate">app_rating_button</div>
-
+ <div id="about_text"></div>
</div>
</body>
</html>
View
@@ -0,0 +1,13 @@
+= Kontakt
+
+Hra má vlastní stránku na Facebooku
+[facebook.com/mobile-prsi|http://www.facebook.com/pages/mobile-prsi/166452220085020]
+
+Nebo můžete kontaktovat autora přes Twitter
+[@tomasburger|http://twitter.com/#!/tomasburger]
+
+Aplikace, která má lepší hodnoceni, zaujme víc uživatelů.
+Víc uživatelů znamená další vývoj a další funkce.
+Pomozte zlepšit hodnocení aplikace a ohodnoťte jí na Marketu.
+[Go to Market and provide rating|https://market.android.com/details?id=cz.burger.android.phonegap.mobileprsi]
+
View
@@ -0,0 +1,13 @@
+= Contact
+
+Game has homepage on Facebook
+[facebook.com/mobile-prsi|http://www.facebook.com/pages/mobile-prsi/166452220085020]
+
+You can also contact author on Twitter
+[@tomasburger|http://twitter.com/#!/tomasburger]
+
+If application gets a better rating, it gets better traction too.
+Better traction means development and more features.
+So help to improve the app by getting good rating on Market.
+[Go to Market and provide rating|https://market.android.com/details?id=cz.burger.android.phonegap.mobileprsi]
+
View
@@ -0,0 +1,86 @@
+function initCore() {
+ parseQueryString();
+ loadColors();
+ $('.translate').map(function() {
+ $(this).text(t($(this).text()));
+ });
+}
+function parseQueryString() {
+ var qs = window.location.search.substring(1);
+ var parts = qs.split("&");
+ window.prsi_color_scheme = parts[0];
+ window.prsi_language = parts[1];
+}
+function loadColors() {
+ var link = $('<link>');
+ link.attr({
+ type: 'text/css',
+ rel: 'stylesheet',
+ href: 'colors_' + window.prsi_color_scheme + '.css'
+ });
+ $('head').append(link);
+}
+function t(txt) {
+ var text = texts[txt];
+ if (!text) alert(txt);
+ var formatted = text[window.prsi_language];
+ for(arg in arguments) {
+ if (arg > 0) formatted = formatted.replace("{" + arg + "}", arguments[arg]);
+ }
+ return formatted;
+}
+function buttonIntent(button_id, intent_url) {
+ $('div#' + button_id).click(function() {
+ window.plugins.webintent.startActivity(
+ {
+ action: WebIntent.ACTION_VIEW,
+ url: intent_url
+ },
+ function() {},
+ function() { alert('Failed to navigate to intent'); }
+ )
+ });
+}
+function loadText(file_name, div_ID) {
+ var filename = file_name + '_' + window.prsi_language + '.txt';
+ $.get(filename.toLowerCase(), function(data) {
+ var lines = data.split('\r\n');
+ var txt = '';
+ var div = '';
+ var title = false;
+ for (ix in lines) {
+ var line = lines[ix];
+ if (/^=\s/.test(line)) {
+ title = true;
+ div += line.replace(/^=\s+(.*)/, '$1');
+ continue;
+ }
+ if (!/^$/.test(line)) {
+ if (/^\[.*\]$/.test(line)) {
+ line = line.replace(/^\[(.*)\|(.*)\]$/,
+ '<div class="button" id="button_' + ix +'">$1</div>' +
+ '<script>buttonIntent("button_' + ix + '", "$2");</script>');
+ }
+ if (div != '') div += '<br/>';
+ div += line;
+ continue;
+ }
+ if (div != '') {
+ txt = txt
+ + '<div class="'
+ + (title ? 'about_title' : 'about_ref')
+ + '">' + div + '</div>';
+ }
+ title = false;
+ div = '';
+ };
+ if (div != '') {
+ txt = txt
+ + '<div class="'
+ + (title ? 'about_title' : 'about_ref')
+ + '">' + div + '</div>';
+ }
+ $('div#' + div_ID).html(txt);
+ }, 'text');
+}
+
View
@@ -32,20 +32,5 @@ var texts = {
'and_winner_is': { EN: 'WINNER', CZ: 'VÍTĚZ' },
'celebrate_hint': { EN: 'Celebrate a bit and start another game', CZ: 'Trochu to oslavte, a šup na odvetu' },
'new_game_button': { EN: 'New game', CZ: 'Nová hra' },
-
- 'about_contact': { EN: 'Contact', CZ: 'Kontakt' },
- 'facebook_homepage': { EN: 'Game has homepage on Facebook', CZ: 'Hra má stránku na Facebooku' },
- 'twitter_contact': { EN: 'You can also contact author on Twitter', CZ: 'S autorem se také můžete spojit přes Twitter' },
- 'app_rating_text': {
- EN: 'If application gets a better rating, it gets better traction too. '
- + 'Better traction means development and more features. '
- + 'So help to improve the app by getting good rating on Market.',
- CZ: 'Aplikace, která má lepší hodnoceni, zaujme víc uživatelů. '
- + 'Víc uživatelů znamená další vývoj a další funkce. '
- + 'Pomozte zlepšit hodnocení aplikace a ohodnoťte jí na Marketu.'},
- 'app_rating_button': { EN: 'Go to Market and provide rating', CZ: 'Ohodnoť aplikaci na Marketu' },
- 'app_rating_thanks': { EN: 'Thank You!!', CZ: 'Děkujeme!!' },
-
- 'rules_title': { EN: 'Rules', CZ: 'Pravidla' },
-
+
};
View
@@ -8,61 +8,12 @@
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="lang.js"></script>
<script type="text/javascript" charset="utf-8" src="webintent.js"></script>
+ <script type="text/javascript" charset="utf-8" src="core.js"></script>
<script type="text/javascript">
$(document).ready(function() {
- parseQueryString();
- loadColors();
- $('.translate').map(function() {
- $(this).text(t($(this).text()));
- });
- loadRulesText();
+ initCore();
+ loadText('rules', 'rules_text');
});
- function parseQueryString() {
- var qs = window.location.search.substring(1);
- var parts = qs.split("&");
- window.prsi_color_scheme = parts[0];
- window.prsi_language = parts[1];
- }
- function loadColors() {
- var link = $('<link>');
- link.attr({
- type: 'text/css',
- rel: 'stylesheet',
- href: 'colors_' + window.prsi_color_scheme + '.css'
- });
- $('head').append(link);
- }
- function t(txt) {
- var text = texts[txt];
- if (!text) alert(txt);
- var formatted = text[window.prsi_language];
- for(arg in arguments) {
- if (arg > 0) formatted = formatted.replace("{" + arg + "}", arguments[arg]);
- }
- return formatted;
- }
- function loadRulesText() {
- var filename = 'rules_' + window.prsi_language + '.txt';
- $.get(filename.toLowerCase(), function(data) {
- var lines = data.split('\r\n');
- var txt = '';
- for (ix in lines) {
- var line = lines[ix];
- if (/^=\s/.test(line)) {
- txt += line.replace(/^=\s+(.*)/, '<div class="about_title">$1</div>');
- continue;
- }
- if (!/^$/.test(line)) {
- txt += '<div class="about_ref">' + line + '</div>';
- }
- };
- $('div#rules_text').html(txt);
- }, 'text');
- }
- function textify(txt_in) {
- var txt_out = 'AAAAA' + txt_in;
- return txt_out;
- }
</script>
</head>
<body>
@@ -1,7 +1,7 @@
<html><head><title>Test frame - mobile-prsi</title></head>
<body><center>
- <iframe scrolling="no" width="600" height="800" src="../../assets/www/about.html?blue&EN"></iframe>
+ <iframe scrolling="no" width="400" height="800" src="../../assets/www/about.html?blue&EN"></iframe>
<!-- iframe scrolling="no" width="600" height="600" src="../../assets/www/about.html?blue&EN"></iframe -->
</center></body></html>

0 comments on commit 7253b4b

Please sign in to comment.