From 2acb62174ab2cac9c7a88faafcb5f0a22a54db6f Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Sun, 5 Jul 2009 10:23:06 +0800 Subject: initiliaze git rep --- templates/content/js/com.cnprog.utils.js | 116 +++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 templates/content/js/com.cnprog.utils.js (limited to 'templates/content/js/com.cnprog.utils.js') diff --git a/templates/content/js/com.cnprog.utils.js b/templates/content/js/com.cnprog.utils.js new file mode 100644 index 00000000..a5f0e982 --- /dev/null +++ b/templates/content/js/com.cnprog.utils.js @@ -0,0 +1,116 @@ +var showMessage = function(object, msg) { + var div = $('

' + msg + '

(点击消息框关闭)
'); + + div.click(function(event) { + $(".vote-notification").fadeOut("fast", function() { $(this).remove(); }); + }); + + object.parent().append(div); + div.fadeIn("fast"); +}; + +var notify = function() { + var visible = false; + return { + show: function(html) { + if (html) { + $("body").css("margin-top", "2.2em"); + $(".notify span").html(html); + } + $(".notify").fadeIn("slow"); + visible = true; + }, + close: function(doPostback) { + if (doPostback) { + $.post("/messages/markread/", { formdata: "required" }); + } + $(".notify").fadeOut("fast"); + $("body").css("margin-top", "0"); + visible = false; + }, + isVisible: function() { return visible; } + }; +} (); + +function appendLoader(containerSelector) { + $(containerSelector).append('读取中...'); +} + +function removeLoader() { + $("img.ajax-loader").remove(); +} + +function setupFormValidation(formSelector, validationRules, validationMessages, onSubmitCallback) { + enableSubmitButton(formSelector); + $(formSelector).validate({ + rules: (validationRules ? validationRules : {}), + messages: (validationMessages ? validationMessages : {}), + errorElement: "span", + errorClass: "form-error", + errorPlacement: function(error, element) { + var span = element.next().find("span.form-error"); + if (span.length == 0) { + span = element.parent().find("span.form-error"); + } + span.replaceWith(error); + }, + submitHandler: function(form) { + disableSubmitButton(formSelector); + + if (onSubmitCallback) + onSubmitCallback(); + else + form.submit(); + } + }); +} + +function enableSubmitButton(formSelector) { + setSubmitButtonDisabled(formSelector, false); +} +function disableSubmitButton(formSelector) { + setSubmitButtonDisabled(formSelector, true); +} +function setSubmitButtonDisabled(formSelector, isDisabled) { + $(formSelector).find("input[type='submit']").attr("disabled", isDisabled ? "true" : ""); +} + +var CPValidator = function(){ + return { + getQuestionFormRules : function(){ + return { + tags: { + required: true, + maxlength: 105 + }, + text: { + required: true, + minlength: 10 + }, + title: { + required: true, + minlength: 10 + } + }; + }, + getQuestionFormMessages: function(){ + return { + tags: { + required: " 标签不能为空。", + maxlength: " 最多5个标签,每个标签长度小于20个字符。" + }, + text: { + required: " 内容不能为空。", + minlength: jQuery.format(" 请输入至少 {0} 字符。") + }, + title: { + required: " 请输入标题。", + minlength: jQuery.format(" 请输入至少 {0} 字符。") + } + }; + } + }; +}(); +//Search Engine Keyword Highlight with Javascript +//http://scott.yang.id.au/code/se-hilite/ +Hilite={elementid:"content",exact:true,max_nodes:1000,onload:true,style_name:"hilite",style_name_suffix:true,debug_referrer:""};Hilite.search_engines=[["local","q"],["cnprog\\.","q"],["google\\.","q"],["search\\.yahoo\\.","p"],["search\\.msn\\.","q"],["search\\.live\\.","query"],["search\\.aol\\.","userQuery"],["ask\\.com","q"],["altavista\\.","q"],["feedster\\.","q"],["search\\.lycos\\.","q"],["alltheweb\\.","q"],["technorati\\.com/search/([^\\?/]+)",1],["dogpile\\.com/info\\.dogpl/search/web/([^\\?/]+)",1,true]];Hilite.decodeReferrer=function(d){var g=null;var e=new RegExp("");for(var c=0;c2&&f[2]){a=decodeURIComponent(a)}a=a.replace(/\'|"/g,"");a=a.split(/[\s,\+\.]+/);return a}break}}return null};Hilite.decodeReferrerQS=function(f,d){var b=f.indexOf("?");var c;if(b>=0){var a=new String(f.substring(b+1));b=0;c=0;while((b>=0)&&((c=a.indexOf("=",b))>=0)){var e,g;e=a.substring(b,c);b=a.indexOf("&",c)+1;if(e==d){if(b<=0){return a.substring(c+1)}else{return a.substring(c+1,b-1)}}else{if(b<=0){return null}}}}return null};Hilite.hiliteElement=function(f,e){if(!e||f.childNodes.length==0){return}var c=new Array();for(var b=0;b0){c++;if(c>=Hilite.max_nodes){var b=function(){Hilite.walkElements(d,f,e)};setTimeout(b,50);return}if(d.nodeType==1){if(!a.test(d.tagName)&&d.childNodes.length>0){d=d.childNodes[0];f++;continue}}else{if(d.nodeType==3){d=e(d)}}if(d.nextSibling){d=d.nextSibling}else{while(f>0){d=d.parentNode;f--;if(d.nextSibling){d=d.nextSibling;break}}}}};if(Hilite.onload){if(window.attachEvent){window.attachEvent("onload",Hilite.hilite)}else{if(window.addEventListener){window.addEventListener("load",Hilite.hilite,false)}else{var __onload=window.onload;window.onload=function(){Hilite.hilite();__onload()}}}}; \ No newline at end of file -- cgit v1.2.3-1-g7c22