自己的部落格,
在這陣子加入了 博客來書店 網路策略聯盟 博客來AP
由於它需要在撰寫關於博客來的URL時,(博客來說明)
加入exep/assp.php/$BooksAPID 這樣的動作,
其實如果常寫的話,
是挺麻煩的一件事情,
除了要記住要加入什麼樣的字串,
還要確保自己加入的字串是對的。
如果說,可以讓TinyMCE在加入Link URL時,
自動判斷是否為博客來的URL,
且透過您設定的ID自動幫您加入該加入的連結,
這樣子在撰寫時,就方便了許多。

經由上述的原因,因此有了這樣的需求。
其實這樣的功能修改的幅度並不大,
您只需要修改兩個地方
1. 第一個修改的地方 link.htm
首先是tinymce資料夾中的themesadvanced中的 link.htm
以搜尋的方式先找到一個Input 其 name="href"
先複製href那系列的Tr
以Lifetype 1.2.3 中所附的tinymce而言
大約在link.htm的22~30行
接著將所複製的code
在該TR底下貼上,
接著修改所有關於href的變數為booksid
其相關的程式碼如下:
link.htm<table border="0" cellpadding="4" cellspacing="0"> <tr> <td nowrap="nowrap"><label for="href">{$lang_insert_link_url}</label></td> <td><table border="0" cellspacing="0" cellpadding="0"> <tr> <td><input id="href" name="href" type="text" value="" style="width: 200px" /></td> <td id="hrefbrowsercontainer"> </td> </tr> </table></td> </tr> <!-- Books AP --> <tr> <td nowrap="nowrap"><label for="booksid">Books ID</label></td> <td> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td><input id="booksid" name="booksid" type="text" value="" style="width: 200px" /></td> <td id="hrefbrowsercontainer"> </td> </tr> </table> </td> </tr> <!-- Books AP -->
2. 修改相關的javascript code
先找到於themesadvancedjavascripts底下的link.js
接著請搜尋function insertLink()
請先在所有var變數的下方加入
var booksid = document.forms[0].booksid.value;
接著請找到大概在62行的地方
加入關於
判斷booksid是否為空字串
是否存在www.books.com.tw這樣的連結等等的判斷
加入books AP專用連結的程式碼
其修改過後的insertLink() function如下
link.jsfunction insertLink() { var href = document.forms[0].href.value; var target = document.forms[0].target.options[document.forms[0].target.selectedIndex].value; var title = document.forms[0].linktitle.value; var style_class = document.forms[0].styleSelect ? document.forms[0].styleSelect.value : ""; var dummy; // books ID var booksid = document.forms[0].booksid.value; // Make anchors absolute if (href.charAt(0) == '#') href = tinyMCE.settings['document_base_url'] + href; // books AP API if (booksid != '' && href.substring(0,24)=='http://www.books.com.tw/' && href.substring(24,38)!= 'exep/assp.php/'){ var booksurl = href.substring(23,href.length); href = 'http://www.books.com.tw/exep/assp.php/' + booksid + booksurl; //alert(href); } if (target == '_self') target = ''; tinyMCEPopup.restoreSelection(); tinyMCE.themes['advanced']._insertLink(href, target, title, dummy, style_class); tinyMCEPopup.close();}
如此修正後,
就可以看到在輸入連結時,
多了一個Books ID的欄位,
且在您有輸入Books ID時,
且輸入的網址存在http://www.books.com.tw時
自動幫您加入exep/assp.php/$BooksAPID
No related posts.
您好~ 想請問您放置在日誌右側的"博客來–搶眼新書"那部份 怎樣可以像您一樣有tab切換分頁顯示不同類別的書籍呢? 能否大致敎一下…..^^
因博客來AP的查詢網頁中 好像沒看到如何修改?!
hi 小辣椒,
我所使用的是博客來AP官方網站上面的 部落格工具–【博客來搶眼新書】
這一個部落格工具,您可以透過按此取得程式碼
在google的頁面中,就可以取得這個搶眼新書的JavaScript Gadget了
我並沒有作任何的修改。
我自己則是比較需要,輪播,例如將*古典*這一個類別的書籍輪播。用圖片方式或是文字方式都可。不然一個一個產品都要自己去設連結+廣告很累!