منتدى استراحات زايد

منتدى استراحات زايد (http://vb.ma7room.com/index.php)
-   منتدى أخبار المواقع والمنتديات العربية والأجنبية (http://vb.ma7room.com/forumdisplay.php?f=183)
-   -   Administrators vB_AJAX_Handler (fresh look) (http://vb.ma7room.com/showthread.php?t=418801)

محروم.كوم 05-27-2010 06:20 PM

Administrators vB_AJAX_Handler (fresh look)
 
Recently rewrote my js script and noticed that the class vB_AJAX_Handler not changed with version 3.7. I offer my version.
Code:
function vB_AJAX_Handler() {
this.handler = null;
this.conn = null;
};
vB_AJAX_Handler.prototype = {
init: function(){
return AJAX_Compatible;
},
is_compatible: function(){
return AJAX_Compatible;
},
onreadystatechange: function(callback, scope){
this.callback = callback;
this.scope = scope;
},
fetch_data: function(xml){
var el = (typeof(xml) == "string") ? [xml] : xml, data = {};
for(var i = 0; i < el.length; i++)
{
data[el[i]] = this.handler.responseXML.getElementsByTagName(el[i])[0].firstChild.nodeValue;
}
return (i < 2) ? data[xml] : data;
},
send: function(uri, postData) {
this.conn = YAHOO.util.Connect.asyncRequest("POST", uri, {
success: this.callback,
failure: vBulletin_AJAX_Error_Handler,
timeout: vB_Default_Timeout,
scope: this.scope
}, postData + "&securitytoken=" + SECURITYTOKEN + "&s=" + fetch_sessionhash());
this.handler = this.conn.conn;
}
};
Updated methods: fetch_data and send.
Usage:

First variant
Code:
var xml = new vB_AJAX_Handler();
xml.onreadystatechange(function(o){
if (o.responseXML)
{
this.cont = document.createElement("div");
this.cont.id = "lsa_cont";
this.cont.style.position = "absolute";
this.cont.style.display = "none";
this.cont.innerHTML = xml.fetch_data("lsagetwin");
document.body.appendChild(this.cont);
this.textobj.value = '';
this.resobj = D.get("lsa_results");
this.init();
new Y.DD(this.cont.id).setHandleElId("lsadd");
this.winop();
init_collapsers();
}
}, this /* able to use inside your object */);
xml.send("ajaxlivesearch.php?do=lsawin","&do=lsawi n");
Second variant Code:
var xml = new vB_AJAX_Handler();
xml.scope = this;
xml.callback = function(o){
if (o.responseXML)
{
this.cont = document.createElement("div");
this.cont.id = "lsa_cont";
this.cont.style.position = "absolute";
this.cont.style.display = "none";
this.cont.innerHTML = xml.fetch_data("lsagetwin");
document.body.appendChild(this.cont);
this.textobj.value = '';
this.resobj = D.get("lsa_results");
this.init();
new Y.DD(this.cont.id).setHandleElId("lsadd");
this.winop();
init_collapsers();
}
};
xml.send("ajaxlivesearch.php?do=lsawin","&do=lsawi n");
Example with quick_edit Code:
var xml = new vB_AJAX_Handler();
xml.onreadystatechange(function(ajax)
{
if (ajax.responseXML)
{
if (YAHOO.util.Dom.get("progress_" + vB_QuickEditor.postid))
{
YAHOO.util.Dom.get("editimg_" + this.postid).setAttribute("src", vB_QuickEditor.editimgsrc);
}

document.body.style.cursor = 'auto';

// collect items from response object
var data = xml.fetch_data(["contenttypeid", "userid", "attachlimit", "max_file_size", "auth_type", "posthash", "poststarttime", "values", "phrases"]);

if (fetch_tag_count(ajax.responseXML, 'disabled'))
{
// this will fire if quick edit has been disabled after the showthread page is loaded
window.location = 'editpost.php?' + SESSIONURL + 'do=editpost&postid=' + this.postid;
}
else if (fetch_tag_count(ajax.responseXML, 'error'))
{
// do nothing
}
else
{
if (ajax.responseXML.getElementsByTagName("contenttyp eid").length > 0)
{
vBulletin.attachinfo = {
contenttypeid : data.contenttypeid,
userid : data.userid,
attachlimit : data.attachlimit,
max_file_size : data.max_file_size,
auth_type : data.auth_type,
posthash : data.posthash,
poststarttime : data.poststarttime
};

var values = data.values;
if (values.length > 0 && values[0].childNodes.length)
{
vBulletin.attachinfo.values = {};
for (var i = 0; i < values[0].childNodes.length; i++)
{
if (values[0].childNodes[i].nodeName != "#text" && typeof(values[0].childNodes[i].childNodes[0]) != "undefined")
{
vBulletin.attachinfo.values[values[0].childNodes[i].nodeName] = values[0].childNodes[i].childNodes[0].nodeValue;
}
}
}

var phrases = data.phrases;
if (phrases.length > 0 && phrases[0].childNodes.length)
{
for (var i = 0; i < phrases[0].childNodes.length; i++)
{
if (phrases[0].childNodes[i].nodeName != "#text" && typeof(phrases[0].childNodes[i].childNodes[0]) != "undefined")
{
vbphrase[phrases[0].childNodes[i].nodeName] = phrases[0].childNodes[i].childNodes[0].nodeValue;
}
}
}
}

var editor = fetch_tags(ajax.responseXML, 'editor')[0];
if (typeof editor == 'undefined')
{
window.location = "editpost.php?" + SESSIONURL + "do=editpost&postid=" + this.postid;
return false;
}
var reason = editor.getAttribute('reason');

// display the editor
this.messageobj.innerHTML = editor.firstChild.nodeValue;

// display the reason
if (fetch_object(this.editorid + '_edit_reason'))
{
this.unchanged_reason = PHP.unhtmlspecialchars(reason);
fetch_object(this.editorid + '_edit_reason').value = this.unchanged_reason;
fetch_object(this.editorid + '_edit_reason').onkeypress = vB_AJAX_QuickEditor_Events.prototype.reason_key_tr ap;
}

// initialize the editor
vB_Editor[this.editorid] = new vB_Text_Editor(
this.editorid,
editor.getAttribute('mode'),
editor.getAttribute('parsetype'),
editor.getAttribute('parsesmilies'),
undefined,
undefined,
editor.getAttribute('content')
);

if (fetch_object(this.editorid + '_editor') && fetch_object(this.editorid + '_editor').scrollIntoView)
{
fetch_object(this.editorid + '_editor').scrollIntoView(true);
}

vB_Editor[this.editorid].set_editor_width('100%', true);
vB_Editor[this.editorid].check_focus();

this.unchanged = vB_Editor[this.editorid].get_editor_contents();

YAHOO.util.Event.on(YAHOO.util.Dom.get(this.editor id + '_save'), "click", this.save, this, true);
YAHOO.util.Event.on(YAHOO.util.Dom.get(this.editor id + '_abort'), "click", this.abort, this, true);
YAHOO.util.Event.on(YAHOO.util.Dom.get(this.editor id + '_adv'), "click", this.full_edit, this, true);
YAHOO.util.Event.on("quick_edit_errors_hide", "click", this.hide_errors, this, true);
YAHOO.util.Event.on("quick_edit_errors_cancel", "click", this.abort, this, true);

var delbutton = YAHOO.util.Dom.get(this.editorid + '_delete');
if (delbutton)
{
YAHOO.util.Event.on(this.editorid + '_delete', "click", this.show_delete, this, true);
}

init_popupmenus(YAHOO.util.Dom.get(this.editorid)) ;
}

handle_dep(this.editorid);
}
}, this);
xml.send("ajax.php?do=quickedit&p=" + this.postid, '&do=quickedit&p=' + this.postid + '&editorid=' + PHP.urlencode(this.editorid));
Your thoughts? :)


الساعة الآن 04:26 AM

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.2 TranZ By Almuhajir


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