2012 年 1 月的归档
Javascript中,定義正則表達式的方法有兩個:
/* /pattern/flags; */ var re = /mac/i;
/* new RegExp("pattern","flags"); */ var re = new RegExp(window.prompt("Please input a regex.","yes|yeah"),"g");
g The global search flag makes the RegExp search for a pattern throughout the string, creating an array of all occurrences it can find matching the given pattern.
i The ignore case flag makes a regular expression case insensitive. For international coders, note that this might not work on extended characters such as ?, ü, ?, ?.
m This flag makes the beginning of input (^) and end of input ($) codes also catch beginning and end of line respectively.
參閱此處
Applies the RegExp to the given string, and returns the match information.
var match = /s(amp)le/i.exec("Sample text") //match then contains ["Sample","amp"]
Tests if the given string matches the Regexp, and returns true if matching, false if not.
var match = /sample/.test("Sample text") //match then contains false
Matches given string with the RegExp. With g flag returns an array containing the matches, without g flag returns just the first match or if no match is found returns null.
var str = "Watch out for the rock!".match(/r?or?/g) //str then contains ["o","or","ro"]
Matches RegExp with string and returns the index of the beginning of the match if found, -1 if not.
var ndx = "Watch out for the rock!".search(/for/) //ndx then contains 10
Replaces matches with the given string, and returns the edited string.
var str = "Liorean said: My name is Liorean!".replace(/Liorean/g,'Big Fat Dork') //str then contains "Big Fat Dork said: My name is Big Fat Dork!"
Cuts a string into an array, making cuts at matches.
var str = "I am confused".split(/\s/g) //str then contains ["I","am","confused"]
Example:
var s='<div style="text-align:center;width:inherit;text-color:blue;">SOME TEXT</div>' var rx=new RegExp("<div .*?>(.*?)</div>","i"); s=s.replace(rx,"$1"); // s="SOME TEXT" // http://www.tek-tips.com/viewthread.cfm?qid=1231301
SharePoint中Team Site的主頁, 默認會給創建為按7:3的比例左右分割. 這是一個煩人的問題, 因為很多時候我們並不想以這個比例劃分左右Column.
解決方法:
Tip: You can just as easily insert new rows and columns and then add new web part zones from the Insert, SharePoint Controls menu
<script> //http://techtrainingnotes.blogspot.com/2008/11/sharepoint-how-to-hide-right-web-part.html function HideWebPartZone() { var x = document.getElementsByTagName("TD") var i=0; for (i=0;i<x.length;i++) { if (x[i].width=="70%") { // left column x[i].style.width="100%"; // center (otherwise empty) column if (document.all) // is IE var x2=x[i].nextSibling; else var x2=x[i].nextSibling.nextSibling; x2.style.width="0"; x2.style.display="none"; x2.innerHTML=""; // right column if (document.all) // is IE x2=x[i].nextSibling.nextSibling; else x2=x[i].nextSibling.nextSibling.nextSibling.nextSibling; x2.style.width="0"; x2.style.display="none"; x2.innerHTML=""; // right margin column if (document.all) // is IE x2=x[i].nextSibling.nextSibling.nextSibling; else x2=x[i].nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling; x2.style.width="0"; x2.style.display="none"; x2.innerHTML=""; //all done return; } } } _spBodyOnLoadFunctionNames.push("HideWebPartZone") </script>
此方法,在IE7中流暢度欠佳.
用設置Div box的width似乎更理想
當創建web part page 之後,需要更改page 的layout (如三欄變為兩欄),可以用同名創建欲改變的layout的web part page 以覆蓋之!
註意:覆蓋會令導致原來頁面中所有內容丟失,請先做好備份! 同時該方法不適用於home page, 因為homepage 異於普通web part page,詳情參見此處
Sharepoint在某些時候,部份的元素實屬多餘,例如Quick Launch Bar等. 要將其去除,最好當然是通過SharePoint Designer. 然而很多時候, 無法通過底層修改SharePoint的模板. 於是,只能求助于CSS.
下面是Hide Quick Launch Bar代碼
<style> .ms-navframe { display: none } </style>
Observer Pattern 的重點是, publisher發佈消息之後,subscriber會自動對消息作出反應.
將publisher 的方法複製到object O中,為其添加publisher的方法
該方法中沒有observer
window.onkeypress –> game.handlekeypress –> Player:play –> game: handlePlay –> scoreboard.update
包含一個數組記錄所有subscribers和publish方法
包含subscribe 和 unsubscribe
Example from book 『Pro Javascript Design Patterns』