-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQuery.form.js
104 lines (76 loc) · 2.17 KB
/
jQuery.form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Create HTML tag into a jQuery parent Node by DOM type and id.
*
*
* @type Class
* @author NorbertHeiszler <[email protected]>
* @version 2.0
*/
function jQueryForm ()
{
var A = 'array', O = 'object', S = 'string', D = '', P = '', U = 'undefined';
this.returnJquery = false;
function getParent(parent) {
if ((!( parent instanceof jQuery)) && (typeof parent == S)) {
return $(parent);
} else {
if (parent instanceof jQuery) {
return parent;
} else {
throw new Exception("Invalid input for jQueryForm parent");
}
}
}
this.appendElement = function(parent, properties) {
var $j = getParent(parent).prepend(this.createElement(properties));
if (this.returnJquery) {
return $j;
}
return this;
}
this.prependElement = function(parent, properties) {
var $j = getParent(parent).prepend(this.createElement(properties));
if (this.returnJquery) {
return $j;
}
return this;
}
this.insertElement = function(parent, properties) {
var $j = getParent(parent).html(this.createElement(properties));
if (this.returnJquery) {
return $j;
}
return this;
}
/**
* Create jQuery node by name with properties and value
*
* @param object properties
* @returns jQuery
*/
this.createElement = function(properties) {
//injected input not lose property
var properties = $.extend(true, {}, properties);
var element = properties.element;
delete properties.element;
var $node = $(document.createElement(element));
if (typeof properties.value != U) {
var value = properties.value;
delete properties.value;
//for input
$node.val(value);
//for textarea
$node.text(value);
//for else
$node.html(value);
}
if (typeof properties != U) {
$node.attr(properties);
}
return $node;
}
this.getJquery = function(set) {
this.returnJquery = set;
return this;
};
}