PluginProbe
Comments Extra Fields For Post,Pages and CPT / 1.7
Comments Extra Fields For Post,Pages and CPT v1.7
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.2 2.3 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 5.0 5.1 5.2
wp-comment-fields / js / nm-global.js

nm-global.js in Comments Extra Fields For Post,Pages and CPT 1.7, at js/nm-global.js

166 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*
2 * this file is going to be magic
3 * for all N-Media plugins/themes
4 */
5
6 /*
7 * extract data from html elements
8 */
9
10 function extractElementData(elements) {
11
12 var data = new Object;
13
14 data.bug = false;
15 jQuery.each(elements,
16 function(i, item) {
17
18 if(item.req == undefined || item.req == 0){
19 item.req = false;
20
21 }else{
22 item.req = true;
23
24 }
25
26 switch (item.type) {
27
28 case 'text':
29
30 data[i] = jQuery("input[name^='" + i + "']").val();
31 if(jQuery("input[name^='" + i + "']").val() == '' && item.req){
32 jQuery("input[name^='" + i + "']").css('border', 'red 1px solid');
33 data.bug = true;
34 /*alert(item.type+' is required');*/
35 }
36 break;
37
38 case 'select':
39
40 data[i] = jQuery("select[name^='" + i + "']").val();
41 if(jQuery("select[name^='" + i + "']").val() == '' && item.req){
42 jQuery("select[name^='" + i + "']").css('border', 'red 1px solid');
43 data.bug = true;
44 /*alert(item.type+' is required');*/
45 }
46 break;
47
48 case 'checkbox':
49
50 var checkedVals = [];
51 jQuery('input:checkbox[name^="' + i + '"]:checked').each(function() {
52 checkedVals.push(jQuery(this).val());
53 });
54
55 data[i] = (checkedVals.length == 0) ? null : checkedVals;
56
57 if (!jQuery("input:checkbox[name^='" + i + "']").is(':checked') && item.req){
58
59 jQuery("input:checkbox[name^='" + i + "']").parent('label').css('color', 'red');
60 data.bug = true;
61 /*alert(item.type+' is required');*/
62 }
63
64 break;
65
66 case 'radio':
67
68 data[i] = jQuery(
69 "input:radio[name^='" + i + "']:checked").val();
70 if (!jQuery("input:radio[name^='" + i + "']").is(':checked') && item.req){
71
72 jQuery("input:radio[name^='" + i + "']").css('border', 'red 1px solid');
73 data.bug = true;
74 alert(item.type+' is required');
75 }
76 break;
77
78 case 'textarea':
79
80 data[i] = jQuery("textarea[name^='" + i + "']").val();
81
82 if(jQuery("textarea[name^='" + i + "']").val() == '' && item.req){
83 jQuery("textarea[name^='" + i + "']").css('border', 'red 1px solid');
84 data.bug = true;
85 /*alert(item.type+' is required');*/
86 }
87 break;
88 }
89
90 });
91
92 return data;
93 }
94
95
96 /*
97 * function checking the checkbox for current value
98 * current value: json object
99 * @Author: Najeeb
100 * 13 Oct, 2012
101 */
102
103 function setChecked(elementName, currentValue){
104
105 var elementCB = jQuery('input:checkbox[name="' + elementName + '"]');
106
107 var currentValues = jQuery.parseJSON(currentValue);
108
109
110 //console.log(currentValues);
111
112 jQuery.each(elementCB, function(i, item){
113
114 //console.log(item.id);
115 var current_cb_id = item.id;
116
117 jQuery.each(currentValues, function(i, item){
118
119 //console.log(item + jQuery("#"+current_cb_id).attr('value'));
120 if(jQuery("#"+current_cb_id).attr('value') == item){
121
122 jQuery("#"+current_cb_id).attr('checked', true);
123 }else{
124 if ( jQuery("#"+current_cb_id).attr('checked') == true)
125 jQuery("#"+current_cb_id).attr('checked', false);
126 }
127 //jQuery('input:checkbox[value="' + item + '"]').attr("checked", "checked");
128 });
129 });
130
131
132
133 }
134
135 /*
136 * function checking the RADIO for current value
137 * current value: single
138 * @Author: Najeeb
139 * 3 July, 2012
140 */
141
142 function setCheckedRadio(elementName, currentValue) {
143
144 var elementRadio = jQuery('input:radio[name="' + elementName + '"]');
145
146 //console.log(elementRadio);
147 jQuery.each(elementRadio, function(i, item) {
148
149 //console.log(item.id);
150 var current_radio_id = item.id;
151
152 if (jQuery("#" + current_radio_id).attr('value') == currentValue) {
153
154 jQuery("#" + current_radio_id).attr('checked', true);
155 } else {
156 if (jQuery("#" + current_radio_id).attr('checked') == true)
157 jQuery("#" + current_radio_id).attr('checked', false);
158 }
159
160 });
161
162 }
163
164
165
166