javascript - Cannot read property 'offsetHeight' of null -
i have strange issue showed on script , not sure causes issue happen. popping on chrome browser , guess function 'offsetheight' either deprecated or invalid. here full code:
var rep_templates = { // array of pre-defined reasons answers: null, // popup container context_menu: null, // popup copntiner height menu_height: 0, error_msg: null, // ajax form , param values pseudoform: null, url: null, postid: 0, // information phrases display user thanks_phrase: '', description_msg: '', timer_id: null, /** * inits popup * @param answers array of pre-defined reasons * @param error_msg display in case of empty message * @param url of current page * @param thanks_phrase diaplyed after successful submission */ init: function(answers, url, phrases) { if (ajax_compatible) { this.answers = answers; this.error_msg = phrases['error']; this.thanks_phrase = phrases['thanks']; this.description_msg = phrases['description']; this.context_menu = new yahoo.widget.menu("rep_tmpl_popup", {clicktohide: false, effect: { effect: yahoo.widget.containereffect.fade, duration: 0.25 }}); // fix ie7 z-index bug if (yahoo.env.ua.ie && yahoo.env.ua.ie < 8) { this.context_menu.cfg.setproperty("position", "dynamic"); this.context_menu.cfg.setproperty("iframe", true); this.context_menu.cfg.setproperty("zindex", 10100); } this.context_menu.render(document.body); var menu_object = fetch_object("rep_tmpl_menu_inner"); this.menu_height = menu_object.offsetheight; var links = yahoo.util.dom.getelementsbyclassname("report", "a", document.body); ( var = 0; < links .length; i++ ) { var index = links[i].href.indexof("p="); if (index > 0) { var postid = links[i].href.substr(index+2); yahoo.util.event.on(links[i], "click", this.show_popup, postid); } } this.pseudoform = new vb_hidden_form('ajax.php'); this.pseudoform.add_variable('ajax', 1); this.pseudoform.add_variable('s', fetch_sessionhash()); this.pseudoform.add_variable('securitytoken', securitytoken); this.pseudoform.add_variable('do', 'email_report'); this.url = url; } }, /** * inserts pre-defined reason textarea * @param id of selected reason */ set_answer: function(id) { var textarea = fetch_object('rep_tmpl_message'); textarea.value = ''; if (id > 0 && id <= this.answers.length) { textarea.value = this.answers[id-1]; var error_msg = fetch_object('rep_tmpl_error'); error_msg.innerhtml = ""; } }, /** * show popup user * @param event click event * @param postid id of post */ show_popup: function(event,postid) { rep_templates.reset_data(); yahoo.util.event.stopevent(event); var elem = event.srcelement? event.srcelement : event.target; rep_templates.postid = postid; var xy = [0,0]; xy[0] = yahoo.util.dom.getx(elem) + 25; xy[1] = yahoo.util.dom.gety(elem) - rep_templates.menu_height; if (xy[1] < 0) { xy[1] = 0; } rep_templates.context_menu.moveto(xy[0],xy[1]); rep_templates.context_menu.show(); fetch_object('rep_tmpl_message').focus(); yahoo.util.event.on(document.body, "click", rep_templates.hide_menu); }, /** * hides menu when users click hide button or click outside of popup. resets data * @param optional event. if specified, user clicked outside. */ hide_menu: function(event) { var is_inside = false; if (event) { // check if click inside or outside popup var obj = event.srcelement? event.srcelement : event.target; { if (obj.id == 'rep_tmpl_popup') { is_inside = true; break; } } while (obj = obj.parentnode); if (!is_inside) { yahoo.util.event.removelistener(document.body, "click", rep_templates.hide_menu); } } if (!event || !is_inside) { rep_templates.context_menu.hide(); rep_templates.postid = 0; } }, /** * reset fields default values */ reset_data: function() { var error_msg = fetch_object('rep_tmpl_error'); error_msg.innerhtml = ""; var phrase = fetch_object('rep_tmpl_phrase'); phrase.innerhtml = this.description_msg; yahoo.util.dom.removeclass(phrase, 'rep_tmpl_thanks_message'); var button = fetch_object('rep_tmpl_submit'); yahoo.util.dom.removeclass(button, 'disabled'); button.disabled = false; var image = fetch_object('rep_tmpl_progress'); image.style.display = 'none'; }, /** * sends ajax request * @param event click event */ send_data: function(event) { var textarea = fetch_object('rep_tmpl_message'); if (textarea && textarea.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '') != '') { this.pseudoform.add_variable('postid', this.postid); this.pseudoform.add_variable('url',this.url + "&p="+ this.postid + "#post" + this.postid); var button = event.srcelement? event.srcelement : event.target; button.disabled = true; yahoo.util.dom.addclass(button, 'disabled'); var image = fetch_object('rep_tmpl_progress'); image.style.display = ''; yahoo.util.connect.asyncrequest("post", 'ajax.php', { success: this.handle_ajax_response, failure: vbulletin_ajax_error_handler, timeout: vb_default_timeout, scope: }, this.pseudoform.build_query_string() + '&reason=' + textarea.value); } else { var error_msg = fetch_object('rep_tmpl_error'); error_msg.innerhtml = this.error_msg; } return false; }, /** * handles ajax request * @param ajax data returned */ handle_ajax_response: function(ajax) { if (ajax.responsexml) { // check error first var error = ajax.responsexml.getelementsbytagname('error'); if (error.length) { this.reset_data(); var error_msg = fetch_object('rep_tmpl_error'); error_msg.innerhtml = error[0].firstchild.nodevalue; } else { var result = ajax.responsexml.getelementsbytagname('result'); if (result.length) { var image = fetch_object('rep_tmpl_progress'); image.style.display = 'none'; var phrase = fetch_object('rep_tmpl_phrase'); phrase.innerhtml = this.thanks_phrase; yahoo.util.dom.addclass(phrase, 'rep_tmpl_thanks_message'); this.timer_id = settimeout('rep_templates.handle_timer_expiration()',1000); } } } }, /** * hides popup on timer expiration */ handle_timer_expiration: function() { cleartimeout(this.timer_id); this.hide_menu(); } }
any idea how solve issue!!
thanks
your problem object menu_object
null. guess element looking not exist. check out element , make sure has correct identifier (class or id) match fetch_object("rep_tmpl_menu_inner")
Comments
Post a Comment