My studying notebook

2008/08/22

Add Star Ratings to your Blogger Blog

8/22/2008 10:15:00 PM Posted by Unknown 1 comment
Blogger in draft support new Star Ratings feature, blog readers can hit rate easily of your post. To enable star ratings, login to
http://draft.blogger.com/ dashboard and go to blog layout page. Click "Edit" botton at Page Elements and selected the "Show Star Ratings".

Modify Blog Template

After enable new Star Rating feature, we must add few code to show star rating where you want.

1.decide a place to show star ratings. For example, to show star ratings in every post footer. Choice one of three paragraph
<div class='post-footer'>
<p class='post-footer-line post-footer-line-1'></p>
<p class='post-footer-line post-footer-line-2'></p>
<p class='post-footer-line post-footer-line-3'></p>
</div>

2.Add following section of codes
<b:if cond='data:blog.pageType == &quot;item&quot;'>
<!-- Add above code, show star rating at single post view, if you don't.
delete it and don't forget </b> tag -->
<span class='star-ratings'>
<b:if cond='data:top.showStars'>
<div expr:g:background-color='data:backgroundColor' expr:g:text-color='data:textColor'
expr:g:url='data:post.absoluteUrl' g:height='42' g:type='RatingPanel' g:width='180'
/>
</b:if>
</span>
</b>

3.Find this line in your template and add following section of code just after this line
<b:include name='nextprev' />
<b:if cond='data:top.showStars'>
<script src='http://www.google.com/jsapi' type='text/javascript' />
<script type='text/javascript'>
google.load("annotations", "1");
function initialize() {
google.annotations.createAll();
google.annotations.fetch();
}
google.setOnLoadCallback(initialize);
</script>
</b:if>


4.you done! Now, after save template and try it.

2008/08/18

ASP.NET 2.0 Content page add Css

8/18/2008 09:51:00 PM Posted by Unknown 1 comment
One of .NET framework 2.0 new important features. Master page, it allow you to create a consistent layout for the pages in your application. You can include Cascading Style Sheets link in master page for you all pages to use the same Cascading Style Sheets easily. But sometimes, you don't want content page to use Cascading Style Sheets inclued of Master page or you want add Cascading Style Sheets to a special page. How can we to do?

We can't add link Cascading Style Sheets syntax in ContentPlaceHolder of content page. So, we can use Htmllink control to add new attribuate.

protected void DynamicAddCss(string csspath) {
// Define an HtmlLink control.
HtmlLink myHtmlLink = new HtmlLink();
myHtmlLink.Href = csspath;
myHtmlLink.Attributes.Add("rel", "stylesheet");
myHtmlLink.Attributes.Add("type", "text/css");

// Add the HtmlLink to the Head section of the page.
Page.Header.Controls.Add(myHtmlLink);
}

// add Cascading Styles Sheet
DynamicAddCss("http://jquery.com/files/social/jquery.tabs-ie.css")

2008/08/15

Your HTML either contains unsafe tags

8/15/2008 10:18:00 PM Posted by Unknown , 2 comments
上一篇文章提到Google即將停止Page Create的服務。而以Google Sites來取代其功能。

因此想說就試一下Google Sites有沒有比較彈性的功能。在頁面編輯的時候加了一最簡單的Javascript語法,如果成功的話,就可以在Google Sites中試一些Google API來玩玩。

document.alert('alert popup message');


不過卻得到以下的訊息


又回去把Google announce的文章看一篇. 驚!!!! 居然沒有看到..

I'm not sure if Google Sites is a good replacement for Page Creator, since the interface is more complicated and there are many limitations: you can't add JavaScript code, embedded objects or iframes, it's more difficult to upload files and to setup a simple site.

URI: Google Page Creator to Be Closed(Google).

Google Page Creator to Be Closed

8/15/2008 09:57:00 PM Posted by Unknown 1 comment
2008/8/9

在Google Reader中收到一個新的消息。繼Browser Sync, Hello, Send to SMS and Send to Phone extension之後,又有一個Google 所提供的服務要停止了→ Page Create。

真是一個壞消息啊 ~~~ Bad Bad Bad.
因為在我擁有的2個Blogger中,尚有些Javascript的程式碼是放在上面。真不知道要把上面的Javascript搬到那去比較好。

具說明的理由是另一個Google提供的服務Google Sites中的功能已可包含Page Create中的功能,因為就會Page Create不再提供服務。喜愛Google服務的我當然在Google Sites一推出的時候就馬上先註冊一下自己的網域了,今天又上去東點點西點點,試試有沒有什麼新的功能。

看來是時候該把Google Sites摸熟一點了!!

2008/08/05

惱人的Google Map Api

8/05/2008 10:39:00 PM Posted by Unknown 1 comment
有使用過Google Map Api的人都知道,想在自己的網頁中嵌入Google Map必須先申請Google Map API Key,在申請的過程中除了要有Google帳號之外,還得輸入欲使用Google Map的網址。完成之後會產出是一組長達86個字元的Key。

上一篇文章(Google AJAX Feed API - AJAX Slide Show Rolling)提及利用Picasa Web Albums Data API 與 jQurey JSON的操作,即可完成Picasa Web Albums的輪播;其它有做用jQuery中 $.getJSON() 的函數來存取逺端的Picasa Web Albums Data。後來又修改了一下程式碼,直接使用javascript中 script.setAttribute 中的方法來指定url及callback function,並加入Google Map來表示地理位置,如下圖。



無奈不知道什麼時候使用過同樣的Google Map API Key,導至出現API已使用的訊息!!


真害!!!
想不出來在那用過了~~~~~~~~殘念!!

ps.此篇純屬mermer,等問題待解決之後,會把作法說明一下!!!
ps.第一個版本請見竹誌picasa Feed區塊

2008/07/02

Google AJAX Feed API - AJAX Slide Show Rolling

7/02/2008 07:00:00 PM Posted by Unknown , , , , , 4 comments
AJAX Slide Show 為利用Google AJAX Feed API作出來簡單的應用。允許使用者把 PhotoBucket、 Flickr、Picasa Web Albums的網路相簿以幻燈片的方式嵌在自己的Blog、網站等中。在Slide Show 中Picasa Web Album Feed URL無法動態更改,利用Picasa Web Albums Data API 與 jQurey JSON的操作,即可完成Picasa Web Albums的輪播。


Live Demo
| Download


AJAX Slide Show
<script type="text/javascript">
function load() {
var samples = "http://dlc0421.googlepages.com/gfss.rss";
var options = {
displayTime: 2000,
transistionTime: 600,
linkTarget: google.feeds.LINK_TARGET_BLANK
};
new GFslideShow(samples, "slideshow", options);
}
google.load("feeds", "1");
google.setOnLoadCallback(load);
</script>

var samples 為載入相關的Rss,在Picasa Web Album中都可以訂閱任何一個相簿的Feed。例如訂閱第七屆拼圖馬拉松的Feed(http://picasaweb.google.com/data/feed/base/user/cage.chung/albumid
/5217479087123706369?kind=photo&alt=rss&hl=en_US
)即可將此相簿以Slide Show的方式展示在網頁中。


AJAX Slide Show Advance

scenario
上述的方式,Side Show相簿的Feed為固定的,如果想要展示不同的相簿就必需更改程式碼,這是一件滿煩麻的事情。即然Google公開了Picasa Web Albums Data API,所以我們應該可以使用API搜尋特定user的相簿,以亂數組出Slide Show所需的Feed,達到相簿輪播的效果。

待解決的問題:
  • 選擇Ablum Feed Url
  • 決定Picasa Web Albums Data API回傳資料的格式及接收方式
  • Parser回傳的資料,找出組出Feed最主的資料(Picase Web Album ID)
  • 將亂數選出的Ablum ID帶入AJAX Slide Show

Step1
我們可以要求幾種來自Picase Web Ablum的不同的Feed。依照我們的需求,是搜尋特定user所有公開的相簿,在Picasa Web Albums 搜尋的參數[1]中會使用到kind與access2種參數
  • Kinds指特定類別的參數(ablum、photo、comment、tag、user)在此使用, user
  • Access指定相簿屬性(all、public、private)在此指定user所有公開的相簿, publick
因此,我們Ablum Feed Url則為http://picasaweb.google.com/data/feed/api/user/userID?kind=kinds&Access=publick

Step2
由於 AJAX 程式中的 XMLHttpRequest 只能呼叫同一個 domain 下的 URL,所以呼叫遠端並回傳XML資料型態的資料會以安全性考量被拒絕存取。又因為Picasa Web Albums資料格式提供另一種輕量級的資料交換格式(JSON),只有在Feed Url中指定alt=json即可將XML資料格式轉換成JSON格式並回傳。

選定遠端資料回傳格式為JSON,剩下的就是本機端該如何接收JSON型態資料。在此使用了一個新形態的 JavaScript程式庫(jQuery),程式庫中可以直接使用 jQuery.getJSON( url, [data], [callback][2] 操作JSON並進行AJAX回呼。此時的Ablum Feed Url更改為http://picasaweb.google.com/data/feed/api/user/cage.chung?kind=album&access=public
&alt=json&callback=?


Step3
剩下的部份就是Parser回傳的JSON資料
var numentries = json.feed.entry.length; //每一個相簿都是單獨的entry,numentries則為相簿的數量
var rNum = Math.floor(Math.random() * numentries); //以Random選擇相簿
var item = json.feed.entry[rNum];

var title = item.title.$t; //相簿的標題
var summary = item.summary.$t; //相簿的說明
var id = item.gphoto$id.$t; //最主要的相簿ID


Step4
將亂數選出的Ablum ID帶入AJAX Slide Show var samples 字串中即可




整合之後的Script 如下
<script type="text/javascript">
function load() {
$.getJSON("http://picasaweb.google.com/data/feed/api/user/<span style="
font - weight: bold;
">USERID</span>?kind=album&access=public&alt=json&callback=?", function(json) {

var numentries = json.feed.entry.length;
var rNum = Math.floor(Math.random() * numentries);
var item = json.feed.entry[rNum];

var title = item.title.$t;
var summary = item.summary.$t;
var id = item.gphoto$id.$t;

if (summary.length > 0) $("#msg").html("<h4>" + title + "</h4><p>" + summary + "</p>");
else $("#msg").html("<h4>" + title + "</h4>");

var samples = "http://picasaweb.google.com/data/feed/api/user/<span style="
font - weight: bold;
">USERID</span>/albumid/" + id + "?kind=photo&alt=rss&hl=en_US";

var options = {
displayTime: 2000,
transistionTime: 600,
linkTarget: google.feeds.LINK_TARGET_BLANK,
scaleImages: true
};
new GFslideShow(samples, "slideshow", options);
});
}
google.load("feeds", "1");
google.setOnLoadCallback(load);
</script>




Reference
  1. Interacting with Picasa Web Albums
  2. you can load JSON data located on another domain if you specify a JSONP callback, which can be done like so: "myurl?callback=?". jQuery automatically replaces the ? with the correct method name to call, calling your specified callback. Or, if you set the dataType to "jsonp" a callback will be automatically added to your Ajax request.
  3. Projection values: Feed URL "api" 與 "base"的差別,api參數提供了gphoto相關元素(包括我們需要的album id)
base
api