Alexander Nazarov (nfokz) wrote in changelog,
Alexander Nazarov
nfokz
changelog

[livejournal] r22417: LJSUP-12661: jQuery JSON detection worka...

Committer: anazarov
LJSUP-12661: jQuery JSON detection workaround
U   trunk/htdocs/js/basic.js
Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js	2012-07-11 06:38:59 UTC (rev 22416)
+++ trunk/htdocs/js/basic.js	2012-07-11 07:50:03 UTC (rev 22417)
@@ -911,18 +911,25 @@
 			options = node.data('widget-options'),
 			bootstrap = node.data('bootstrap') || null;
 
-
 		if (node.attr('data-widget-id')) {
 			/* Widget already has unique id */
 			return;
 		}
 
-		if (typeof options !== 'object') {
-			if (options) {
-				LJ.console.warn('Invalid options string: ' + options);
-			}
+		switch (typeof options) {
+			case 'object':
+				/* jQuery parsing was successfull */
+				break;
 
-			options = {};
+			case 'string':
+				/* Sometimes detection fails (when options string has line breaks) */
+				try {
+					options = JSON.parse(options || '{}');
+				} catch (error) {
+					LJ.console.warn('Invalid options string: ' + options);
+					options = {};
+				}
+				break;
 		}
 
 		if (force) {

Tags: anazarov, js, livejournal, nfokz
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