Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[livejournal] r19463: LJINT-442: Error on kommersant (05.07.11...

Committer: gariev
LJINT-442: Error on kommersant (05.07.11)

$('foo') returns a true object even if no 'foo' is found (empty but true collection).
U   trunk/htdocs/js/quickreply.js
Modified: trunk/htdocs/js/quickreply.js
===================================================================
--- trunk/htdocs/js/quickreply.js	2011-07-12 03:58:11 UTC (rev 19462)
+++ trunk/htdocs/js/quickreply.js	2011-07-12 06:03:25 UTC (rev 19463)
@@ -1,6 +1,7 @@
 QuickReply = {
 	lastDiv: 'qrdiv',
-	
+
+
 	reply: function(dtid, pid, newsubject)
 	{
 		var targetname = 'ljqrt' + dtid,
@@ -14,7 +15,7 @@
 			subject = $('subject');
 		
 		// Is this a dumb browser?
-		if (!qr_ptid || !qr_rto || !qr_dtid || !qr_div || !cur_div || !qr_form || !qr_form_div || !subject) {
+		if (! QuickReply._checkElements(qr_ptid, qr_rto, qr_dtid, qr_div, cur_div, qr_form, qr_form_div, subject)) {
 			return true;
 		}
 		
@@ -23,7 +24,7 @@
 		qr_rto.value = pid;
 		
 		if (QuickReply.lastDiv == 'qrdiv') {
-			qr_div.style.display = 'inline';
+			qr_div.css('display', 'inline');
 			// Only one swap
 			cur_div.parentNode.insertBefore(qr_div, cur_div);
 		} else if (QuickReply.lastDiv != dtid) {
@@ -55,7 +56,7 @@
 			pidform = $('parenttalkid');
 		
 		// do not do the default form action (post comment) if something is broke
-		if (!qr_form || !basepath || !dtid || !pidform) {
+		if (! QuickReply._checkElements(qr_form, basepath, dtid, pidform)) {
 			return false;
 		}
 		
@@ -77,7 +78,7 @@
 		var submitmore = $('submitmoreopts'),
 			submit = $('submitpost');
 		
-		if (!submitmore || !submit) {
+		if (! QuickReply._checkElements(submitmore, submit)) {
 			return false;
 		}
 		
@@ -114,12 +115,13 @@
 	save: function()
 	{
 		var qr_form = $('qrform');
-		if (!qr_form) {
+		var do_spellcheck = $('do_spellcheck'),
+			qr_upic = $('prop_picture_keyword');
+	
+		if (! QuickReply._checkElements(qr_form, do_spellcheck, qr_upic)) {
 			return false;
 		}
-		var do_spellcheck = $('do_spellcheck'),
-			qr_upic = $('prop_picture_keyword');
-		
+
 		$('saved_body').value = qr_form.body.value;
 		$('saved_subject').value = $('subject').value;
 		$('saved_dtid').value = $('dtid').value;
@@ -144,9 +146,12 @@
 				subject = $('saved_subject'),
 				subject_str = '',
 				qr_form = $('qrform');
-			if (!saved_body || saved_body.value == '' || !qr_form || !dtid) {
+			if (! QuickReply._checkElements(saved_body, qr_form, dtid)) {
 				return;
 			}
+			if (saved_body.value == '') {
+				return;
+			}
 			
 			if (subject) {
 				subject_str = subject.value;
@@ -194,6 +199,15 @@
 			}
 		});
 		ups.show();
+	},
+
+	_checkElements:  function () {
+		for (var i = 0; i < arguments.length; ++i) {
+			if (!arguments[i] || !arguments[i].length) {
+				return false;
+			}
+		}
+		return true;
 	}
 }
 

Tags: gariev, js, livejournal
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments