]> git.openstreetmap.org Git - osqa.git/blob - forum/skins/default/media/js/com.cnprog.utils.js
deleting the test file
[osqa.git] / forum / skins / default / media / js / com.cnprog.utils.js
1 //var $, scriptUrl, osqaSkin
2 var mediaUrl = function(resource){
3     return scriptUrl + 'm/' + osqaSkin + '/' + resource;
4 };
5
6 var showMessage = function(object, msg) {
7     var div = $('<div class="vote-notification"><h3>' + msg + '</h3>(' +
8     $.i18n._('click to close') + ')</div>');
9
10     div.click(function(event) {
11         $(".vote-notification").fadeOut("fast", function() { $(this).remove(); });
12     });
13
14     object.parent().append(div);
15     div.fadeIn("fast");
16 };
17
18 var notify = function() {
19     var visible = false;
20     return {
21         show: function(html) {
22             if (html) {
23                 $("body").css("margin-top", "2.2em");
24                 $(".notify span").html(html);        
25             }          
26             $(".notify").fadeIn("slow");
27             visible = true;
28         },       
29         close: function(doPostback) {
30             if (doPostback) {
31                $.post(scriptUrl + $.i18n._("messages/") + 
32                 $.i18n._("markread/"), { formdata: "required" });
33             }
34             $(".notify").fadeOut("fast");
35             $("body").css("margin-top", "0");
36             visible = false;
37         },     
38         isVisible: function() { return visible; }     
39     };
40 } ();
41
42 function appendLoader(containerSelector) {
43     $(containerSelector).append('<img class="ajax-loader" ' +
44         'src="' + mediaUrl("media/images/indicator.gif") + '" title="' +
45         $.i18n._('loading...') +
46         '" alt="' +
47         $.i18n._('loading...') +
48     '" />');
49 }
50
51 function removeLoader() {
52     $("img.ajax-loader").remove();
53 }
54
55 function setSubmitButtonDisabled(formSelector, isDisabled) { 
56     $(formSelector).find("input[type='submit']").attr("disabled", isDisabled ? "true" : "");    
57 }
58
59 function enableSubmitButton(formSelector) {
60     setSubmitButtonDisabled(formSelector, false);
61 }
62
63 function disableSubmitButton(formSelector) {
64     setSubmitButtonDisabled(formSelector, true);
65 }
66
67 function setupFormValidation(formSelector, validationRules, validationMessages, onSubmitCallback) {
68     enableSubmitButton(formSelector);
69     $(formSelector).validate({
70         rules: (validationRules ? validationRules : {}),
71         messages: (validationMessages ? validationMessages : {}),
72         errorElement: "span",
73         errorClass: "form-error",
74         errorPlacement: function(error, element) {
75             var span = element.next().find("span.form-error");
76             if (span.length === 0) {
77                 span = element.parent().find("span.form-error");
78             }
79             span.replaceWith(error);
80         },
81         submitHandler: function(form) {
82             disableSubmitButton(formSelector);
83             
84             if (onSubmitCallback){
85                 onSubmitCallback();
86             } 
87             else{
88                 form.submit();
89             }
90         }
91     });
92 }
93
94 var CPValidator = function(){
95     return {
96         getQuestionFormRules : function(){
97             return {
98                 tags: {
99                     required: true,
100                     maxlength: 105
101                 },  
102                 text: {
103                     required: true,
104                     minlength: 10
105                 },
106                 title: {
107                     required: true,
108                     minlength: 10
109                 }
110             };
111         },
112         getQuestionFormMessages: function(){
113             return {
114                 tags: {
115                     required: " " + $.i18n._('tags cannot be empty'),
116                     maxlength: " " + $.i18n._('tablimits info')
117                 },
118                 text: {
119                     required: " " + $.i18n._('content cannot be empty'),
120                     minlength: $.format(' ' + $.i18n._('content minchars'))
121                 },
122                 title: {
123                     required: " " + $.i18n._('please enter title'),
124                     minlength: $.format(' ' + $.i18n._('title minchars'))
125                 }
126             };
127         }
128     };
129 }();
130 //Search Engine Keyword Highlight with Javascript
131 //http://scott.yang.id.au/code/se-hilite/
132 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;c<Hilite.search_engines.length;c++){var f=Hilite.search_engines[c];e.compile("^http://(www\\.)?"+f[0],"i");var b=d.match(e);if(b){var a;if(isNaN(f[1])){a=Hilite.decodeReferrerQS(d,f[1])}else{a=b[f[1]+1]}if(a){a=decodeURIComponent(a);if(f.length>2&&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;b<e.length;b++){e[b]=e[b].toLowerCase();if(Hilite.exact){c.push("\\b"+e[b]+"\\b")}else{c.push(e[b])}}c=new RegExp(c.join("|"),"i");var a={};for(var b=0;b<e.length;b++){if(Hilite.style_name_suffix){a[e[b]]=Hilite.style_name+(b+1)}else{a[e[b]]=Hilite.style_name}}var d=function(m){var j=c.exec(m.data);if(j){var n=j[0];var i="";var h=m.splitText(j.index);var g=h.splitText(n.length);var l=m.ownerDocument.createElement("SPAN");m.parentNode.replaceChild(l,h);l.className=a[n.toLowerCase()];l.appendChild(h);return l}else{return m}};Hilite.walkElements(f.childNodes[0],1,d)};Hilite.hilite=function(){var a=Hilite.debug_referrer?Hilite.debug_referrer:document.referrer;var b=null;a=Hilite.decodeReferrer(a);if(a&&((Hilite.elementid&&(b=document.getElementById(Hilite.elementid)))||(b=document.body))){Hilite.hiliteElement(b,a)}};Hilite.walkElements=function(d,f,e){var a=/^(script|style|textarea)/i;var c=0;while(d&&f>0){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()}}}};