[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 var ThemeSelector = Class.create(); 2 3 ThemeSelector.prototype = { 4 5 url: null, 6 save_url: null, 7 selector: null, 8 stylesheet: null, 9 file: null, 10 selector_form: null, 11 tid: null, 12 spinnerImage: "../images/spinner_big.gif", 13 miniSpinnerImage: "../images/spinner.gif", 14 isajax: false, 15 specific_count: 0, 16 selector_go: null, 17 selector_prev_option: null, 18 is_closing: false, 19 20 background: null, 21 width: null, 22 color: null, 23 extra: null, 24 text_decoration: null, 25 font_family: null, 26 font_size: null, 27 font_style: null, 28 font_weight: null, 29 30 initialize: function(url, save_url, selector, stylesheet, file, selector_form, tid) 31 { 32 if(url && save_url && selector && stylesheet && file && selector_form && tid) 33 { 34 this.url = url; 35 this.save_url = save_url; 36 this.selector = selector; 37 this.selector_prev_option = this.selector.value; 38 this.stylesheet = stylesheet; 39 this.file = file; 40 this.selector_form = selector_form; 41 this.tid = tid; 42 43 this.background = $("css_bits[background]").value; 44 this.width = $("css_bits[width]").value; 45 this.color = $("css_bits[color]").value; 46 this.extra = $("css_bits[extra]").value; 47 this.text_decoration = $("css_bits[text_decoration]").value; 48 this.font_family = $("css_bits[font_family]").value; 49 this.font_size = $("css_bits[font_size]").value; 50 this.font_style = $("css_bits[font_style]").value; 51 this.font_weight = $("css_bits[font_weight]").value; 52 53 Event.observe(window, "unload", this.saveCheck.bindAsEventListener(this, false)); 54 Event.observe($("save"), "click", this.save.bindAsEventListener(this, true)); 55 Event.observe($("save_close"), "click", this.saveClose.bindAsEventListener(this)); 56 Event.observe(this.selector, "change", this.updateSelector.bindAsEventListener(this)); 57 Event.observe(this.selector_form, "submit", this.updateSelector.bindAsEventListener(this)); 58 } 59 else if(url) 60 { 61 for(i=0; i < url; ++i) 62 { 63 Event.observe($("delete_img_"+i), "click", this.removeAttachmentBox.bindAsEventListener(this, i)); 64 } 65 66 this.specific_count = url; 67 Event.observe($("new_specific_file"), "click", this.addAttachmentBox.bindAsEventListener(this)); 68 } 69 }, 70 71 saveClose: function(e) 72 { 73 this.is_closing = true; 74 }, 75 76 updateSelector: function(e) 77 { 78 Event.stop(e); 79 80 this.saveCheck(e, true); 81 82 postData = "file="+encodeURIComponent(this.file)+"&tid="+encodeURIComponent(this.tid)+"&selector="+encodeURIComponent(this.selector.value)+"&my_post_key="+encodeURIComponent(my_post_key); 83 84 this.selector_go = $("mini_spinner").innerHTML; 85 $("mini_spinner").innerHTML = " <img src=\""+this.miniSpinnerImage+"\" style=\"vertical-align: middle;\" alt=\"\" /> "; 86 87 new Ajax.Request(this.url, { 88 method: 'post', 89 postBody: postData, 90 onComplete: this.onComplete.bind(this) 91 }); 92 }, 93 94 onComplete: function(request) 95 { 96 if(request.responseText.match(/<error>(.*)<\/error>/)) 97 { 98 message = request.responseText.match(/<error>(.*)<\/error>/); 99 100 if(!message[1]) 101 { 102 message[1] = "An unknown error occurred."; 103 } 104 105 alert('There was an error fetching the test results.\n\n'+message[1]); 106 } 107 else if(request.responseText) 108 { 109 if($("saved").innerHTML) 110 { 111 var saved = $("saved").innerHTML; 112 } 113 this.stylesheet.innerHTML = request.responseText; 114 } 115 116 this.background = $("css_bits[background]").value; 117 this.width = $("css_bits[width]").value; 118 this.color = $("css_bits[color]").value; 119 this.extra = $("css_bits[extra]").value; 120 this.text_decoration = $("css_bits[text_decoration]").value; 121 this.font_family = $("css_bits[font_family]").value; 122 this.font_size = $("css_bits[font_size]").value; 123 this.font_style = $("css_bits[font_style]").value; 124 this.font_weight = $("css_bits[font_weight]").value; 125 126 if(saved) 127 { 128 $("saved").innerHTML = saved; 129 window.setTimeout("$(\"saved\").innerHTML = \"\";", 30000); 130 } 131 132 $("mini_spinner").innerHTML = this.selector_go; 133 this.selector_go = ''; 134 135 return true; 136 }, 137 138 saveCheck: function(e, isajax) 139 { 140 if(this.is_closing == true) 141 { 142 return true; 143 } 144 145 if(this.background != $("css_bits[background]").value || this.width != $("css_bits[width]").value || this.color != $("css_bits[color]").value || this.extra != $("css_bits[extra]").value || this.text_decoration != $("css_bits[text_decoration]").value || this.font_family != $("css_bits[font_family]").value || this.font_size != $("css_bits[font_size]").value || this.font_style != $("css_bits[font_style]").value || this.font_weight != $("css_bits[font_weight]").value) 146 { 147 confirmReturn = confirm(save_changes_lang_string); 148 if(confirmReturn == true) 149 { 150 this.save(false, isajax); 151 alert('Saved'); 152 } 153 } 154 this.selector_prev_option = this.selector.value; 155 return true; 156 }, 157 158 save: function(e, isajax) 159 { 160 if(e) 161 { 162 Event.stop(e); 163 } 164 165 var css_bits = { 166 'background': $('css_bits[background]').value, 167 'width': $('css_bits[width]').value, 168 'color': $('css_bits[color]').value, 169 'extra': $('css_bits[extra]').value, 170 'text_decoration': $('css_bits[text_decoration]').value, 171 'font_family': $('css_bits[font_family]').value, 172 'font_size': $('css_bits[font_size]').value, 173 'font_style': $('css_bits[font_style]').value, 174 'font_weight': $('css_bits[font_weight]').value 175 }; 176 177 postData = "css_bits="+encodeURIComponent(js_array_to_php_array(css_bits))+"&selector="+encodeURIComponent(this.selector_prev_option)+"&file="+encodeURIComponent(this.file)+"&tid="+encodeURIComponent(this.tid)+"&my_post_key="+encodeURIComponent(my_post_key)+"&serialized=1"; 178 179 if(isajax == true) 180 { 181 postData += "&ajax=1"; 182 } 183 184 this.isajax = isajax; 185 186 if(isajax == true) 187 { 188 this.spinner2 = new ActivityIndicator("body", {image: this.spinnerImage}); 189 } 190 191 if(isajax == true) 192 { 193 new Ajax.Request(this.save_url, { 194 method: 'post', 195 postBody: postData, 196 onComplete: this.onSaveComplete.bind(this) 197 }); 198 } 199 else 200 { 201 new Ajax.Request(this.save_url, { 202 method: 'post', 203 postBody: postData, 204 onComplete: this.onUnloadSaveComplete.bind(this) 205 }); 206 } 207 }, 208 209 onSaveComplete: function(request) 210 { 211 if(request.responseText.match(/<error>(.*)<\/error>/)) 212 { 213 message = request.responseText.match(/<error>(.*)<\/error>/); 214 215 if(!message[1]) 216 { 217 message[1] = "An unknown error occurred."; 218 } 219 220 alert('There was an error fetching the test results.\n\n'+message[1]); 221 return false; 222 } 223 else if(request.responseText) 224 { 225 $("saved").innerHTML = " (Saved @ "+Date()+")"; 226 if($("ajax_alert")) 227 { 228 $("ajax_alert").innerHTML = ''; 229 $("ajax_alert").hide(); 230 } 231 } 232 233 this.background = $("css_bits[background]").value; 234 this.width = $("css_bits[width]").value; 235 this.color = $("css_bits[color]").value; 236 this.extra = $("css_bits[extra]").value; 237 this.text_decoration = $("css_bits[text_decoration]").value; 238 this.font_family = $("css_bits[font_family]").value; 239 this.font_size = $("css_bits[font_size]").value; 240 this.font_style = $("css_bits[font_style]").value; 241 this.font_weight = $("css_bits[font_weight]").value; 242 243 this.spinner2.destroy(); 244 245 return true; 246 }, 247 248 onUnloadSaveComplete: function(request) 249 { 250 if(request.responseText.match(/<error>(.*)<\/error>/)) 251 { 252 message = request.responseText.match(/<error>(.*)<\/error>/); 253 254 if(!message[1]) 255 { 256 message[1] = "An unknown error occurred."; 257 } 258 259 alert('There was an error fetching the test results.\n\n'+message[1]); 260 return false; 261 } 262 263 return true; 264 }, 265 266 addAttachmentBox: function(e) 267 { 268 Event.stop(e); 269 270 var next_count = Number(this.specific_count) + 1; 271 272 var contents = "<div id=\"attached_form_"+this.specific_count+"\"><div class=\"border_wrapper\">\n<table class=\"general form_container \" cellspacing=\"0\">\n<tbody>\n<tr class=\"first\">\n<td class=\"first\"><div class=\"form_row\"><span style=\"float: right;\"><a href=\"\" id=\"delete_img_"+this.specific_count+"\"><img src=\"styles/default/images/icons/cross.gif\" alt=\""+delete_lang_string+"\" title=\""+delete_lang_string+"\" /></a></span>"+file_lang_string+" <input type=\"text\" name=\"attached_"+this.specific_count+"\" value=\"\" class=\"text_input\" style=\"width: 200px;\" id=\"attached_"+this.specific_count+"\" /></div>\n</td>\n</tr>\n<tr class=\"last alt_row\">\n<td class=\"first\"><div class=\"form_row\"><dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">\n<dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_"+this.specific_count+"\" value=\"0\" checked=\"checked\" class=\"action_"+this.specific_count+"s_check\" onclick=\"checkAction('action_"+this.specific_count+"');\" style=\"vertical-align: middle;\" /> "+globally_lang_string+"</label></dt>\n<dt><label style=\"display: block;\"><input type=\"radio\" name=\"action_"+this.specific_count+"\" value=\"1\" class=\"action_"+this.specific_count+"s_check\" onclick=\"checkAction('action_"+this.specific_count+"');\" style=\"vertical-align: middle;\" /> "+specific_actions_lang_string+"</label></dt>\n<dd style=\"margin-top: 4px;\" id=\"action_"+this.specific_count+"_1\" class=\"action_"+this.specific_count+"s\">\n<small class=\"description\">"+specific_actions_desc_lang_string+"</small>\n<table cellpadding=\"4\">\n<tr>\n<td><input type=\"text\" name=\"action_list_"+this.specific_count+"\" value=\"\" class=\"text_input\" style=\"width: 190px;\" id=\"action_list_"+this.specific_count+"\" /></td>\n</tr>\n</table>\n</dd>\n</dl></div>\n</td>\n</tr>\n</tbody>\n</table>\n</div></div><div id=\"attach_box_"+next_count+"\"></div>\n"; 273 274 if(!$("attach_box_"+this.specific_count)) 275 { 276 $("attach_1").innerHTML = contents; 277 } 278 else 279 { 280 $("attach_box_"+this.specific_count).innerHTML = contents; 281 } 282 283 checkAction('action_'+this.specific_count); 284 285 286 if($("attached_form_"+this.specific_count)) 287 { 288 Event.observe($("delete_img_"+this.specific_count), "click", this.removeAttachmentBox.bindAsEventListener(this, this.specific_count)); 289 } 290 291 ++this.specific_count; 292 }, 293 294 removeAttachmentBox: function(e, count) 295 { 296 Event.stop(e); 297 298 confirmReturn = confirm(delete_confirm_lang_string); 299 300 if(confirmReturn == true) 301 { 302 Element.remove($("attached_form_"+count)); 303 } 304 305 } 306 } 307 308 function js_array_to_php_array(a) 309 { 310 var a_php = ""; 311 var total = 0; 312 for(var key in a) 313 { 314 ++total; 315 a_php = a_php + "s:" + 316 String(key).length + ":\"" + String(key) + "\";s:" + 317 String(a[key]).length + ":\"" + String(a[key]) + "\";"; 318 } 319 a_php = "a:" + total + ":{" + a_php + "}"; 320 return a_php; 321 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |