$( "#user" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: iANGEL + "manageuser/search/" + $("#user").val(),
cache: false,
type:"GET",
dataType:"json",
success: function( data ) {
//check response data
if(data.user_data.status == 200){
response($.map( data.user_data.result, function( item ) {
return item;
}));
}
}
});
},
select:function(event,ui){
$.console("[AUTOCOMPLETE] select");
//$.console(ui.item);
$(this).val( ui.item.User_NickName).attr("data",ui.item.User_ID);
return false;
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
//$.console(item);
return $( "<li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.User_NickName + "</a>" )
.appendTo(ul);
};
星期一, 12月 31, 2012
[jQuery UI] autocomplete 控制項
試很久才正常的自動完成控制項,
一開始用keyup的事件綁定後,向後端拿資料,再初始化自動完成控制項,
但就是會有異常的情況,包含後端包出來的JSON的客製的,別頁又可以正常work。
最後終於試了正常的方向,在這記錄一下,以免下次要用又搞很久Orz。
測試版本為jquery ui 1.9.1版
星期三, 12月 26, 2012
星期五, 12月 21, 2012
[jQuery] 頁面刷新處理 (F5鍵)
找了一些偵側頁面被觸發刷新的檢查的二個範例
第一種是補捉按鍵的keycode但是如果按瀏覽器的重新整理無法偵測
$(document).bind("keypress keydown keyup", function(e) {
if(e.which === 116) {
return false;
}
if(e.which === 82 && e.ctrlKey) {
return false;
}
});
第二種是比較好的方法,連上一頁跟下一頁都能一起觸發
$(window).bind('beforeunload', function() {
return "Are u sure to reload?";
});
星期四, 12月 20, 2012
[jQuery API] ajaxPrefilter
//before ajax request handler
<>
<>
$.ajaxPrefilter(function( options, originalOptions, jqXHR ){
$.console("[ajaxPrefilter] ajax url:" + options.url);
});
星期日, 12月 16, 2012
[Javascript] 日期計算的應用
常常會用到又會忘記的日期格式運算。
找了一些文章說用format("yyyy-MM-dd")可以格式化但一直爆炸XD
找到的應用會直接更新在這篇。
//取得現在的日期 var currentTime = new Date(); //往前推30天 currentTime.setDate(currentTime.getDate() + (-30));
//第一天跟最後一天 var date = new Date(); var firstDay = new Date(date.getFullYear(), date.getMonth(), 1); var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
//格式化yyyy/mm/dd
function dateFormat(date){
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var finalDate = year + "-" + m + "-" + d;
return finalDate;
};
//日期相差的天數
function getDiffDays(endDate){
var date1 = new Date();
var date2 = new Date(Date.parse(endDate.replace("-", "/")));
var date3 = date2.getTime() - date1.getTime();//時間差的毫秒数
var days = Math.floor(date3/(24*3600*1000));//相差天數
return days;
};
星期一, 12月 10, 2012
[Javascript] Detect flash version
偵測客戶端目前有沒有裝Flash的外掛。
I agree with Max Stewart. SWFObject is the way to go. I'd like to supplement his answer with a code example. This ought to to get you started:
if(swfobject.hasFlashPlayerVersion("9.0.115"))
{
alert("You have the minimum required flash version (or newer)");
}
else
{
alert("You do not have the minimum required flash version");
}
Replace "9.0.115" with whatever minimum flash version you need. I chose 9.0.115 as an example because that's the version that added h.264 support.
If the visitor does not have flash, it will report a flash version of "0.0.0", so if you just want to know if they have flash at all, use:
if(swfobject.hasFlashPlayerVersion("1"))
{
alert("You have flash!");
}
else
{
alert("You do not flash :-(");
}
星期日, 12月 09, 2012
[Javascript] setTimeout
經常會使用的setTimeout方法,做個筆記
設定Timeout,預設只會執行一次,毫秒為單位
setTimeout(function() { myFunc(); }, 4000)
重覆執行setTimeout
function myFunc(){
setTimeout(function(){ myFunc();},4000)
}
取消setTimeout
var timerID = setTimeout(function(){ myFunc();},4000)
clearTimeout(timerID );
設定條件停止
function myFunc(){
if(flag == true){
setTimeout(function(){ myFunc();},4000)
}
}
設定Timeout,預設只會執行一次,毫秒為單位
setTimeout(function() { myFunc(); }, 4000)
重覆執行setTimeout
function myFunc(){
setTimeout(function(){ myFunc();},4000)
}
取消setTimeout
var timerID = setTimeout(function(){ myFunc();},4000)
clearTimeout(timerID );
設定條件停止
function myFunc(){
if(flag == true){
setTimeout(function(){ myFunc();},4000)
}
}
星期日, 12月 02, 2012
星期四, 11月 29, 2012
[Javascript] 檢查IE Document Mode
客戶遇到ie無法正確指定文件模式的問題。
只要在ui加上<meta http-equiv="X-UA-Compatible" content="IE=edge">,即可。
不過要避免在它之前有其他script執行(網民建議)。
不過今天在客戶那邊處理的時候,之前把content內多加了一個IE=edge,chrome=1,會導致無法正確告訴ie使用最新的文件模式檢視(content)。
以下的語法可以偵測目前用戶的文件模式。
function checkIEDocumentMode(){
if (window.navigator.appName == "Microsoft Internet Explorer")
{
if (document.documentMode){
USERAGENT = document.documentMode;
} // IE8
else // IE 5-7
{
USERAGENT = 5; // Assume quirks mode unless proven otherwise
if (document.compatMode)
{
if (document.compatMode == "CSS1Compat")
USERAGENT = 7; // standards mode
}
}
// the USERAGENT variable now contains the document compatibility mode.
$.console("checkIEDocumentMode:" + USERAGENT);
//var $metaTag = $("");
//$metaTag.appendTo("head");
//content="IE=Value" value types:5、6、7、8、9、10、EmulateIE7、EmulateIE8、Edge
}
}
星期五, 11月 23, 2012
星期一, 11月 19, 2012
星期日, 11月 18, 2012
[Java] Hashmap Race condition
最近發生了一個hashmap的嚴重bug,跟同事查了才知道這是Java hashmap常見的問題之一。
由此可見大家都是java的菜鳥XD,
發生原因在於hashmap當滿了之後,如果有多個threads同時對他put或get就會產生Race Condition。
所以可以採用Java Synchronized來處理。參考這位大大的心得:[Java] Synchronized 心得
總共有三種方法可以使用
由此可見大家都是java的菜鳥XD,
發生原因在於hashmap當滿了之後,如果有多個threads同時對他put或get就會產生Race Condition。
所以可以採用Java Synchronized來處理。參考這位大大的心得:[Java] Synchronized 心得
總共有三種方法可以使用
[jQuery plugin] ajaxForm 與 validator 整合範例
時常會需要利用到jquery form與 validator 二個元件整合的應用。
把範例記錄一下 :D
範例網址:
注意在submithandler事件裡面要改用ajaxSubmit的方法而不是ajaxForm。
http://jquery.bassistance.de/validate/demo/ajaxSubmit-intergration-demo.html
注意在submithandler事件裡面要改用ajaxSubmit的方法而不是ajaxForm。
http://jquery.bassistance.de/validate/demo/ajaxSubmit-intergration-demo.html
jQuery(function() {
// show a simple loading indicator
var loader = jQuery('
')
.css({position: "relative", top: "1em", left: "25em", display: "inline"})
.appendTo("body")
.hide();
jQuery().ajaxStart(function() {
loader.show();
}).ajaxStop(function() {
loader.hide();
}).ajaxError(function(a, b, e) {
throw e;
});
var v = jQuery("#form").validate({
submitHandler: function(form) {
jQuery(form).ajaxSubmit({
target: "#result"
});
}
});
jQuery("#reset").click(function() {
v.resetForm();
});
});
星期二, 11月 13, 2012
[Alfresco] User Quota Issue
如何讓alfresco的quota即時更新, alfresco的工程師說可透過Java backend的ContentUsageService.getUserUsage(userName) 或 覆寫userUsageCollapseJob
https://forums.alfresco.com/en/viewtopic.php?f=27&t=43431
You should be able to get the up-to-date user usage via ContentUsageService.getUserUsage(userName) or else you could consider overriding the userUsageCollapseJob to run more often (eg. every minute instead of every 5 minutes).
If you're running Enterprise 3.4.6 and need more help with this issue then please contact Alfresco Support (if you haven't already).
Regards,
Jan
Ref:
Interface ContentUsageService
https://forums.alfresco.com/en/viewtopic.php?f=27&t=43431
You should be able to get the up-to-date user usage via ContentUsageService.getUserUsage(userName) or else you could consider overriding the userUsageCollapseJob to run more often (eg. every minute instead of every 5 minutes).
If you're running Enterprise 3.4.6 and need more help with this issue then please contact Alfresco Support (if you haven't already).
Regards,
Jan
Ref:
Interface ContentUsageService
星期一, 11月 12, 2012
[Java] GZIP Filter 與 404 錯誤頁面的臭蟲
起因:
GZIPFilter壓縮遇到不存在的網頁會爆炸,如下所示:
2012/11/13
目前尚未找到解法,不過透過HttpServletResponseWrapper目前竟然無法成功拿到各網頁的content,唯有在最後一層的Filter呼叫啊HttpServletResponseWrapper才有辦法拿到
Reference:
What is the simplest way to display httpServletResponse.sendError(403, “My Message”) status from JSTL
How to make a filter to detect if the user requested a not found page?
GZIPFilter壓縮遇到不存在的網頁會爆炸,如下所示:
這個網頁無法使用
http://serverip/test.jspddd 的網頁可能暫時無法使用或被永久移至新網址。
錯誤 330 (net::ERR_CONTENT_DECODING_FAILED): 未知的錯誤。
2012/11/13
目前尚未找到解法,不過透過HttpServletResponseWrapper目前竟然無法成功拿到各網頁的content,唯有在最後一層的Filter呼叫啊HttpServletResponseWrapper才有辦法拿到
Reference:
What is the simplest way to display httpServletResponse.sendError(403, “My Message”) status from JSTL
How to make a filter to detect if the user requested a not found page?
[Hadoop] WordCount Sample
記錄一下第一次跑Hadoop WordCount Job的過程 :)
1. 建立HDFS資料夾
#全部的資料夾會自動建立
hduser@hadoop-master:/usr/local/hadoop$hadoop dfs -mkdir /home/hduser/wordcount
2. 匯入要分析的文件資料(local-dir)到HDFS資料夾
$hadoop dfs -copyFromLocal
$hadoop dfs -copyFromLocal
#匯入
hduser@hadoop-master:/usr/local/hadoop$hadoop dfs -copyFromLocal /home/hduser/wordcount /home/hduser/wordcount
#查看匯入的資料
hduser@hadoop-master:/usr/local/hadoop$ hadoop dfs -ls /home/hduser/wordcount
Warning: $HADOOP_HOME is deprecated.
Warning: $HADOOP_HOME is deprecated.
[Hadoop] WordCount
匯出.jar的時候請記得選取Main Class進入點,如下所示
然後再執行job的時候就不會說找不到了
hadoop@client:~/wordcount$ hadoop jar exercise.wordco.jar WordCo /user/hadoop/wordcount/pg5000.txt /user/hadoop/wordcount/output
星期五, 11月 09, 2012
Chrome: Uncaught SyntaxError: Unexpected end of input
Chrome: Uncaught SyntaxError: Unexpected end of input
今天遇到一個找很久的BUG,
本來以為是JS裡面的{}沒對好,結果是網頁上的超連結的javascript:void(0)設錯了==
少打了void後面的(0)
這個手殘的錯誤似乎出現好幾次了XD
[jQuery plugin] validator fileupload
記錄如何驗證上傳元素,只要加上accept,filesize即可。
fileToUpload:{
accept: "png|jpe?g|gif",
filesize: 1048576
}
訂閱:
意見 (Atom)

