can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[livejournal] r20026: LJSUP-9783: Doesn't work facebook connec...

Committer: dpetrov
LJSUP-9783: Doesn't work facebook connect
U   trunk/cgi-bin/LJ/Hooks/LJLike.pm
U   trunk/htdocs/js/livejournal.js
Modified: trunk/cgi-bin/LJ/Hooks/LJLike.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/LJLike.pm	2011-09-13 06:42:18 UTC (rev 20025)
+++ trunk/cgi-bin/LJ/Hooks/LJLike.pm	2011-09-13 07:05:25 UTC (rev 20026)
@@ -12,7 +12,7 @@
     my $locale = LJ::lang_to_locale($language);
     $locale =~ s/_.*//g;
 
-    $$after_body_open_ref .=  qq{<script type="text/javascript" src="http://apis.google.com/js/plusone.js">{lang: '$locale'}</script>};
+    $$after_body_open_ref .=  qq{<script type="text/javascript">LiveJournal.injectScript('http://apis.google.com/js/plusone.js',{text:"{lang: '$locale'}"});</script>};
 } );
 
 LJ::register_hook( 'insert_html_after_body_open' => sub {
@@ -21,7 +21,15 @@
     my $language = LJ::Lang::get_remote_lang();
     my $locale = LJ::lang_to_locale($language);
 
-    $$after_body_open_ref .= qq{<div id="fb-root"></div><script src="http://connect.facebook.net/$locale/all.js#appId=214181831945836&amp;xfbml=1"></script>};
+    $$after_body_open_ref .= qq{<div id="fb-root"></div>
+        <script type="text/javascript">
+          window.fbAsyncInit = function() {
+            FB.init({appId: '214181831945836', xfbml: true});
+          };
+
+          LiveJournal.injectScript(document.location.protocol + '//connect.facebook.net/en_US/all.js', null, document.getElementById('fb-root'))
+        </script>
+    };
 } );
 
 LJ::register_hook( 'insert_html_after_body_open' => sub {
@@ -29,7 +37,7 @@
 
     return if $LJ::REQ_GLOBAL{'sitewide_resources_ljlike_twitter'}++;
 
-    $$after_body_open_ref .=  qq{<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>};
+    $$after_body_open_ref .=  qq{<script type="text/javascript">LiveJournal.injectScript('http://platform.twitter.com/widgets.js');</script>};
 } );
 
 LJ::register_hook( 'sitewide_resources' => sub {

Modified: trunk/htdocs/js/livejournal.js
===================================================================
--- trunk/htdocs/js/livejournal.js	2011-09-13 06:42:18 UTC (rev 20025)
+++ trunk/htdocs/js/livejournal.js	2011-09-13 07:05:25 UTC (rev 20026)
@@ -314,6 +314,49 @@
 	} );
 }
 
+/**
+ * Insert script in the document.
+ *
+ * @param {String} url Url of the script
+ * @param {Object=} params Data to apply to the scipt node object, e.g. async, text.
+ * @param {Node=} parent If exists, script tag will be inserted in this node or before the
+ *     first script tag otherwise.
+ */
+LiveJournal.injectScript = function( url, params, parent ) {
+
+	function loadScript() {
+		var defaults = {
+			async: true
+		};
+
+		params = params || {};
+		params = jQuery.extend({}, defaults, params);
+
+		var e = document.createElement('script');
+		e.src = url;
+
+		for (var i in params) {
+			if (params.hasOwnProperty(i)) {
+				e[i] = params[i];
+			}
+		}
+
+		if (parent) {
+			parent.appendChild(e);
+		} else {
+			s = document.getElementsByTagName('script')[0];
+			s.parentNode.insertBefore(e, s);
+		}
+	}
+
+	//opera doesn't support async attribute, so we load the scrips on onload event to display page faster
+	if (jQuery.browser.opera) {
+		jQuery(loadScript);
+	} else {
+		loadScript();
+	}
+}
+
 LiveJournal.getLocalizedStr = function( key, dict ) {
 	dict = dict || {};
 	var str = "";

Tags: can3p, js, livejournal, pm
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