إنضمامك إلي منتديات استراحات زايد يحقق لك معرفة كل ماهو جديد في عالم الانترنت ...

انضم الينا
استراحات زايد الصفحة الرئيسية


إضافة رد
 
LinkBack أدوات الموضوع انواع عرض الموضوع
  #1  
قديم 05-27-2010, 06:20 PM
عضو ماسي
بيانات محروم.كوم
 رقم العضوية : 503
 تاريخ التسجيل : Dec 2007
الجنس : female
علم الدوله :
 المشاركات : 2,100,613
عدد الـنقاط :3341
 تقييم المستوى : 2139

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?
__DEFINE_LIKE_SHARE__
رد مع اقتباس
إضافة رد

مواقع النشر (المفضلة)


تعليمات المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا تستطيع إرفاق ملفات
لا تستطيع تعديل مشاركاتك

BB code is متاحة
كود [IMG] متاحة
كود HTML معطلة
Trackbacks are متاحة
Pingbacks are متاحة
Refbacks are متاحة



الساعة الآن 02:03 PM


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

RSS RSS 2.0 XML MAP HTML