hybrid.gallery.js
9.19 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
var errors = new Array();
function grabGalleryFeed() {
var viewport = jQuery('#TzHybridGallery_Viewport');
viewport.html('Loading gallery...');
jQuery.ajax({
url: widget_dir + 'inc/viewer.php'
, data: global_settings
, type: 'post'
, dataType: 'json'
, success: renderGallery
});
}
function renderGallery(data) {
var viewport = jQuery('#TzHybridGallery_Viewport');
if(data.length < 1) {
viewport.html("No gallery posts.");
} else {
var output = jQuery('<div></div>');
for(i=0; i < data.length; i++) {
var item = jQuery('<div style="margin-bottom:15px;"></div>');
item.append('<div><strong>Title:</strong> '+data[i].post_title+'</div>');
item.append('<div><strong>Description:</strong> '+data[i].post_content+'</div>');
item.append('<div><strong>Gallery Type:</strong> '+data[i].gallery_type+'</div>');
item.append('<div><strong>File Name/URL:</strong> '+data[i].filename+'</div>');
item.append('<div><strong>Link Type:</strong> '+data[i].link_type+'</div>');
item.append('<div><strong>Added By:</strong> '+data[i].author_name+'</div>');
item.append('<div><strong>On:</strong> '+data[i].human_date+'</div>');
var thumb = "";
if (data[i].link_type == "linked" && data[i].gallery_type == "image") {
thumb = data[i].filename;
} else if (data[i].link_type == "linked" && data[i].gallery_type == "video") {
thumb = data[i].thumbnail;
} else {
thumb = widget_dir + "uploads/" + data[i].filename;
}
item.append('<div><strong>Thumbnail:</strong><img src="'+thumb+'" width="50" /></div>');
item.append('<div><strong>Status:</strong> '+data[i].status+'</div>');
output.append(item);
}
viewport.html(output);
}
}
function pushError(msg) {
errors.push(msg);
}
function showErrors() {
var el = jQuery("#TzImageFormErrors");
var errorContainer = jQuery(".errors",el);
errorContainer.empty();
for(var i=0; i < errors.length; i++) {
errorContainer.append("<p>"+errors[i]+"</p>");
}
errors.length = 0;
el.show();
}
function showSuccess(msg) {
var el = jQuery("#TzImageFormSuccess");
var responseContainer = jQuery(".response",el);
responseContainer.empty().html(msg);
el.show();
setTimeout("hideSuccess()",3000);
}
function hideSuccess() {
var el = jQuery("#TzImageFormSuccess");
el.fadeOut();
}
function hideErrors() {
var el = jQuery("#TzImageFormErrors");
el.hide();
}
function checkImageForm(formData,jqForm, options) {
var formElement = jqForm[0];
if (formElement.title.value == "") { pushError("The title field is required"); }
if (formElement.description.value == "") { pushError("The description field is required"); }
if (formElement.uploaded_image_filename.value == "" && formElement.imageLinked.value == "") { pushError("Please link or upload an image."); }
if (errors.length > 0) {
showErrors();
return false;
} else {
hideErrors();
return true;
}
}
function imageFormComplete(resp, statusText, xhr, $form) {
if(resp.status == "error") {
errors.length = 0;
pushError(resp.details);
showErrors();
} else {
showSuccess(resp.details);
}
jQuery('#uploaded_image_filename').val('');
jQuery('.image-selected-name').empty();
document.image_form.imageLinked.disabled = false;
jQuery('#TzHybridGallery_Control').slideUp();
}
function checkVideoForm(formData,jqForm, options) {
var formElement = jqForm[0];
if (formElement.videoLinked.value == "" && formElement.uploaded_video_filename.value == "") {
pushError("Please link or upload a video");
} else {
if (formElement.uploaded_video_filename.value != "") {
// it's an uploaded video
if (formElement.video_title.value=="" || formElement.video_description.value=="") {
pushError("Please enter a title and description for your video.");
}
} else {
// video Linked....
}
}
if (errors.length > 0) {
showErrors();
return false;
} else {
hideErrors();
return true;
}
}
function videoFormComplete(resp, statusText, xhr, $form) {
if(resp.status == "error") {
errors.length = 0;
pushError(resp.details);
showErrors();
} else {
showSuccess(resp.details);
}
jQuery('.video-selected-name').empty();
jQuery('#uploaded_video_filename').val('');
document.video_form.videoLinked.disabled = false;
jQuery('#TzHybridGallery_Control').slideUp();
}
function showResponse(message) {
jQuery('#TzHybridGallery_Response').html(message).fadeIn();
}
jQuery(document).ready(function($) {
grabGalleryFeed();
$('.form-cancel').live('click',function() {
hideErrors();
jQuery('#TzHybridGallery_Control').slideUp();
});
/* ADD NEW SECTION -------------------------------------------------------------- */
$('#TzHybridGallery_Header').delegate('a#TzAddNewBtn','click',function() {
$('#TzHybridGallery_Control').show();
var tabs = [];
var tabContainers = [];
$('.tabs ul li a').each(function() {
if(this.pathname == window.location.pathname) {
tabs.push(this);
tabContainers.push($(this.hash).get(0));
}
});
$(tabs).click(function() {
$(tabContainers).hide().filter(this.hash).show();
$(tabs).removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
$('#image_form').ajaxForm({
beforeSubmit: checkImageForm
, success: imageFormComplete
, url: widget_dir + 'inc/forms.php'
, data: { 'form_type' : 'image-form', 'gallery' : global_settings.default_gallery, 'approval' : global_settings.image_approval }
, type: 'post'
, dataType: 'json'
, clearForm: true
, resetForm: true
});
$('#video_form').ajaxForm({
beforeSubmit: checkVideoForm
, success: videoFormComplete
, url: widget_dir + 'inc/forms.php'
, data: { 'form_type' : 'video-form', 'gallery' : global_settings.default_gallery, 'approval' : global_settings.video_approval }
, type: 'post'
, dataType: 'json'
, clearForm: true
, resetForm: true
});
});
/* ------------------------------------------------------------------------------ */
$('#imageInput').uploadify({
'uploader' : widget_dir + 'assets/uploadify/uploadify.swf'
, 'script' : widget_dir + 'assets/uploadify/uploadify.php'
, 'cancelImg' : widget_dir + 'assets/uploadify/cancel.png'
, 'auto' : true
, 'folder' : upload_dir
, 'buttonImg' : widget_dir + 'assets/uploadify/upload_btn.png'
, 'height' : 26
, 'width' : 76
, 'sizeLimit' : (2*1000000)
, 'fileDesc' : "Images Only!"
, 'fileExt' : "*.gif;*.jpg;*.png"
, onComplete : function(e,q,fileObj) {
$('#uploaded_image_filename').val(fileObj.name);
$('.image-selected-name').css('color','#4D4D4D').html("<img src='"+widget_dir+"assets/images/accept.png' align='absmiddle' /> "+fileObj.name+" uploaded.");
document.image_form.imageLinked.value = "";
document.image_form.imageLinked.disabled = true;
return true;
}
});
$('#videoInput').uploadify({
'uploader' : widget_dir + 'assets/uploadify/uploadify.swf'
, 'script' : widget_dir + 'assets/uploadify/uploadify.php'
, 'cancelImg' : widget_dir + 'assets/uploadify/cancel.png'
, 'auto' : true
, 'folder' : widget_dir + 'uploads/'
, 'buttonImg' : widget_dir + 'assets/uploadify/upload_btn.png'
, 'height' : 26
, 'width' : 76
, 'sizeLimit' : (20000*1000000)
, 'fileDesc' : "Proper Video Formats Only"
, 'fileExt' : '*.wmv;*.3gp;*.avi;*.mov;*.mp4;*.mpeg;*.mpg;*.flv;*.mkv;*.gif'
, onComplete : function(e,q,fileObj) {
$('#uploaded_video_filename').val(fileObj.name);
$('.video-selected-name').css('color','#4D4D4D').html("<img src='"+widget_dir+"assets/images/accept.png' align='absmiddle' /> "+fileObj.name+" uploaded.");
document.video_form.videoLinked.value = "";
document.video_form.videoLinked.disabled = true;
return true;
}
});
});