PageSourceSearch

https://andybrick.com/style/js/jquery.slickforms.js

js andybrick.com collected 2026-10-06 11:18:19 UTC 4,698 bytes, 171 lines download raw bytes

1/*
2 * DC jQuery Slick Forms - jQuery Slick Forms
3 * Copyright (c) 2011 Design Chemical
4 * http://www.designchemical.com
5 *
6 * Dual licensed under the MIT and GPL licenses:
7 * 	http://www.opensource.org/licenses/mit-license.php
8 * 	http://www.gnu.org/licenses/gpl.html
9 *
10 */
11
12(function($){
13
14	//define the plugin
15	$.fn.dcSlickForms = function(options) {
16
17		//set default options
18		var defaults = {
19			classError: 'error',
20			classForm: 'slick-form',
21			align: 'left',
22			animateError: true,
23			animateD: 10,
24			ajaxSubmit: true
25		};
26
27		//call in the default otions
28		var options = $.extend(defaults, options);
29		
30		//act upon the element that is passed into the design    
31		return this.each(function(options){
32			
33			// Declare the function variables:
34			var formAction = $(this).attr('action');
35			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
36			var textError = $('#v-error', this).val();
37			var textEmail = $('#v-email', this).val();
38			var $error = $('<span class="error"></span>');
39			var $form = this;
40			var $loading = $('<div class="loading"><span></span></div>');
41			var errorText = '* Required Fields';
42			$('input',$form).focus(function(){
43				$(this).addClass('focus');
44			});
45			$('input',$form).blur(function(){
46				$(this).removeClass('focus');
47			});
48			$('.nocomment').hide();
49			$('.defaultText',this).dcDefaultText();
50			$('.'+defaults.classForm+' label').hide();
51			
52			// Form submit & Validation
53			$(this).submit(function(){
54
55				formReset($form);
56				$('.defaultText',$form).dcDefaultText({action: 'remove'});
57
58				// Validate all inputs with the class "required"
59				$('.required',$form).each(function(){
60					var label = $(this).attr('title');
61					var inputVal = $(this).val();
62					var $parentTag = $(this).parent();
63					if(inputVal == ''){
64						$parentTag.addClass('error').append($error.clone().text(textError));
65					}
66			
67					// Run the email validation using the regex for those input items also having class "email"
68					if($(this).hasClass('email') == true){
69						if(!emailReg.test(inputVal)){
70							$parentTag.addClass('error').append($error.clone().text(textEmail));
71						}
72					}
73				});
74
75				// All validation complete - Check if any errors exist
76				// If has errors
77				if ($('.error',$form).length) {
78					$('.btn-submit',this).before($error.clone().text(textError));
79				} else {
80					if(defaults.ajaxSubmit == true){
81						var $response = $(this).next();
82						$(this).addClass('submit').after($loading.clone());
83						$('.defaultText',$form).dcDefaultText({action: 'remove'});
84						$.post(formAction, $(this).serialize(),function(data){
85							$('.loading').fadeOut().remove();
86							$response.html(data).fadeIn();
87							$('fieldset',this).slideUp();
88						});
89					} else {
90						$form.submit();
91					}
92				}
93				// Prevent form submission
94				return false;
95			});
96	
97		// Fade out error message when input field gains focus
98			$('input, textarea').focus(function(){
99				var $parent = $(this).parent();
100				$parent.addClass('focus');
101				$parent.removeClass('error');
102				
103			});
104			$('input, textarea').blur(function(){
105				var $parent = $(this).parent();
106				var checkVal = $(this).attr('title');
107				if (!$(this).val() == checkVal){
108					$(this).removeClass('defaulttextActive');
109				}
110				$parent.removeClass('error focus');
111				$('span.error',$parent).hide();
112			});
113			
114			function formReset(obj){
115				$('li',obj).removeClass('error');
116				$('span.error',obj).remove();
117			}
118		});
119	};
120})(jQuery);
121/*
122 * DC jQuery Default Text - jQuery Default Text
123 * Copyright (c) 2011 Design Chemical
124 * http://www.designchemical.com
125 */
126
127(function($){
128
129	//define the plugin
130	$.fn.dcDefaultText = function(options) {
131	
132		//set default options
133		var defaults = {
134			action: 'add', // alternative 'remove'
135			classActive: 'defaultTextActive'
136		};
137
138		//call in the default otions
139		var options = $.extend(defaults, options);
140  
141		return this.each(function(options){
142			
143			if(defaults.action == 'add'){
144			
145				$(this).focus(function(srcc) {
146					if ($(this).val() == $(this)[0].title) {
147						$(this).removeClass(defaults.classActive);
148						$(this).val('');
149					}
150				});
151				
152				$(this).blur(function() {
153					if ($(this).val() == "") {
154						$(this).addClass(defaults.classActive);
155						$(this).val($(this)[0].title);
156					}
157				});
158				$(this).addClass(defaults.classActive).blur();
159			}
160			
161			if(defaults.action == 'remove'){
162			
163				var checkVal = $(this).attr('title');
164				if ($(this).val() == checkVal){
165					$(this).val('');
166				}
167					
168			}
169		});
170	};
171})(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.