PageSourceSearch

https://registriesdirect.ca/js/forms.js

js registriesdirect.ca collected 2026-10-05 09:35:46 UTC 5,979 bytes, 190 lines download raw bytes

1(function($){
2	$.fn.extend({
3		forms:function(opt){
4			if(opt===undefined)
5				opt={}
6			this.each(function(){
7				var th=$(this),
8					data=th.data('forms'),
9					_={
10						errorCl:'error',
11						emptyCl:'empty',
12						invalidCl:'invalid',
13						notRequiredCl:'notRequired',
14						successCl:'success',
15						successShow:'4000',
16						mailHandlerURL:'bin/MailHandler.php',
17						ownerEmail:'#',
18						stripHTML:true,
19						smtpMailServer:'localhost',
20						targets:'input,textarea',
21						controls:'a[data-type=reset],a[data-type=submit]',
22						validate:true,
23						rx:{
24							".name":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
25							".state":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
26							".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},
27							".phone":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
28							".fax":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
29							".message":{rx:/.{20}/,target:'textarea'}
30						},
31						preFu:function(){
32							_.labels.each(function(){
33								var label=$(this),
34									inp=$(_.targets,this),
35									defVal=inp.val(),
36									trueVal=(function(){
37												var tmp=inp.is('input')?(tmp=label.html().match(/value=['"](.+?)['"].+/),!!tmp&&!!tmp[1]&&tmp[1]):inp.html()
38												return defVal==''?defVal:tmp
39											})()
40								trueVal!=defVal
41									&&inp.val(defVal=trueVal||defVal)
42								label.data({defVal:defVal})								
43								inp
44									.bind('focus',function(){
45										inp.val()==defVal
46											&&(inp.val(''),_.hideEmptyFu(label),label.removeClass(_.invalidCl))
47									})
48									.bind('blur',function(){
49										_.validateFu(label)
50										if(_.isEmpty(label))
51											inp.val(defVal)
52											,_.hideErrorFu(label.removeClass(_.invalidCl))											
53									})
54									.bind('keyup',function(){
55										label.hasClass(_.invalidCl)
56											&&_.validateFu(label)
57									})
58								label.find('.'+_.errorCl+',.'+_.emptyCl).css({display:'block'}).hide()
59							})
60							_.success=$('.'+_.successCl,_.form).hide()
61						},
62						isRequired:function(el){							
63							return !el.hasClass(_.notRequiredCl)
64						},
65						isValid:function(el){							
66							var ret=true
67							$.each(_.rx,function(k,d){
68								if(el.is(k))
69									ret=d.rx.test(el.find(d.target).val())										
70							})
71							return ret							
72						},
73						isEmpty:function(el){
74							var tmp
75							return (tmp=el.find(_.targets).val())==''||tmp==el.data('defVal')
76						},
77						validateFu:function(el){							
78							el.each(function(){
79								var th=$(this)
80									,req=_.isRequired(th)
81									,empty=_.isEmpty(th)
82									,valid=_.isValid(th)								
83								
84								if(empty&&req)
85									_.showEmptyFu(th.addClass(_.invalidCl))
86								else
87									_.hideEmptyFu(th.removeClass(_.invalidCl))
88								
89								if(!empty)
90									if(valid)
91										_.hideErrorFu(th.removeClass(_.invalidCl))
92									else
93										_.showErrorFu(th.addClass(_.invalidCl))								
94							})
95						},
96						getValFromLabel:function(label){
97							var val=$('input,textarea',label).val()
98								,defVal=label.data('defVal')								
99							return label.length?val==defVal?'nope':val:'nope'
100						}
101						,submitFu:function(){
102							_.validateFu(_.labels)							
103							if(!_.form.has('.'+_.invalidCl).length)
104								$.ajax({
105									type: "POST",
106									url:_.mailHandlerURL,
107									data:{
108										name:_.getValFromLabel($('.name',_.form)),
109										email:_.getValFromLabel($('.email',_.form)),
110										phone:_.getValFromLabel($('.phone',_.form)),
111										fax:_.getValFromLabel($('.fax',_.form)),
112										state:_.getValFromLabel($('.state',_.form)),
113										message:_.getValFromLabel($('.message',_.form)),
114										owner_email:_.ownerEmail,
115										stripHTML:_.stripHTML
116									},
117									success: function(){
118										_.showFu()
119									}
120								})			
121						},
122						showFu:function(){
123							_.success.slideDown(function(){
124								setTimeout(function(){
125									_.success.slideUp()
126									_.form.trigger('reset')
127								},_.successShow)
128							})
129						},
130						controlsFu:function(){
131							$(_.controls,_.form).each(function(){
132								var th=$(this)
133								th
134									.bind('click',function(){
135										_.form.trigger(th.data('type'))
136										return false
137									})
138							})
139						},
140						showErrorFu:function(label){
141							label.find('.'+_.errorCl).slideDown()
142						},
143						hideErrorFu:function(label){
144							label.find('.'+_.errorCl).slideUp()
145						},
146						showEmptyFu:function(label){
147							label.find('.'+_.emptyCl).slideDown()
148							_.hideErrorFu(label)
149						},
150						hideEmptyFu:function(label){
151							label.find('.'+_.emptyCl).slideUp()
152						},
153						init:function(){
154							_.form=this
155							_.labels=$('label',_.form)
156
157							_.preFu()
158							
159							_.controlsFu()
160															
161							_.form
162								.bind('submit',function(){
163									if(_.validate)
164										_.submitFu()
165									else
166										_.form[0].submit()
167									return false
168								})
169								.bind('reset',function(){
170									_.labels.removeClass(_.invalidCl)									
171									_.labels.each(function(){
172										var th=$(this)
173										_.hideErrorFu(th)
174										_.hideEmptyFu(th)
175									})
176								})
177							_.form.trigger('reset')
178						}
179					}
180				if(!data)
181					(typeof opt=='object'?$.extend(_,opt):_).init.call(th),
182					th.data({cScroll:_}),
183					data=_
184				else
185					_=typeof opt=='object'?$.extend(data,opt):data
186			})
187			return this
188		}
189	})
190})(jQuery)

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.