Permalink
Browse files

Converted late-socials.js into a module at ui/social-media.js.

  • Loading branch information...
1 parent a0e737a commit ca727e8e73cc3256114236bce37f2c455b6e8935 @toolness committed May 19, 2012
Showing with 77 additions and 72 deletions.
  1. +12 −11 js/main.js
  2. +65 −61 js/{late-socials.js → ui/social-media.js}
View
23 js/main.js
@@ -10,10 +10,11 @@ require([
"./ui/live-preview",
"./ui/history",
"./ui/publish",
- "./ui/share"
+ "./ui/share",
+ "./ui/social-media"
], function(Help, Parachute, Publisher, ParsingCodeMirror,
ContextSensitiveHelp, ErrorHelp, LivePreview, HistoryUI,
- PublishUI, ShareUI) {
+ PublishUI, ShareUI, SocialMedia) {
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
@@ -65,17 +66,17 @@ require([
redo: $("#redo_button")
});
var socialMedia = SocialMedia({
- jQuery: jQuery,
- getURL: function() {
- return $("#share-container .link-to-this a.view")[0].href;
- },
- container: $("#share-container")
+ jQuery: jQuery,
+ getURL: function() {
+ return $("#share-container .link-to-this a.view")[0].href;
+ },
+ container: $("#share-container")
});
var shareUI = ShareUI({
- codeMirror: codeMirror,
- dialog: $('#share-dialog'),
- socialMedia: socialMedia,
- publisher: publisher
+ codeMirror: codeMirror,
+ dialog: $('#share-dialog'),
+ socialMedia: socialMedia,
+ publisher: publisher
});
var pageToLoad = getQueryVariable('p') || "default";
var parachute = Parachute(window, codeMirror, pageToLoad);
View
126 js/late-socials.js → js/ui/social-media.js 100755 → 100644
@@ -1,61 +1,65 @@
-"use strict";
-
-/**
- * A tiny library for load-loading social media share buttons.
- * If we don't do this, social media will track users even before
- * they click the like button and we don't like that kind of
- * monitoring behaviour.
- */
-var SocialMedia = function(options) {
- var $ = options.jQuery;
- var parent = options.container;
- var getURL = options.getURL;
- var urlPlaceHolder = "__URL__PLACE__HOLDER__";
-
- /**
- * The various social media all have the same API.
- */
- var self = {
-
- facebook: {
- class: "facebook",
- id: "facebook-jssdk",
- src: "http://connect.facebook.net/en_US/all.js#xfbml=1&appId=1",
- html: "<div id='fb-root'></div><div class='fb-like' data-href='"+urlPlaceHolder+"' data-send='false' data-show-faces='false' data-font='tahoma'></div>" },
-
- google: {
- class: "google",
- id: "google-plus",
- src: "https://apis.google.com/js/plusone.js",
- html: "<g:plusone annotation='none' href='"+urlPlaceHolder+"'></g:plusone>" },
-
- twitter: {
- class: "twitter",
- id: "twitter-wjs",
- src: "http://platform.twitter.com/widgets.js",
- html: "<a href='https://twitter.com/share'class='twitter-share-button' data-url='"+urlPlaceHolder+"' data-via='Mozilla' data-count='none'>Tweet</a>" },
-
- /**
- * Hot-load a social medium's button by first
- * injecting the necessary HTML for the medium
- * to perform its own iframe replacements, and
- * then late-loading the script required for
- * the medium to load up its functionality.
- */
- hotLoad: function($, element, socialMedium) {
- // TODO: Should we escape the return value of getURL()? It's likely
- // to not contain any characters that need escaping, and its value
- // is trusted, but we may still want to do it.
- element.html(socialMedium.html.replace(urlPlaceHolder, getURL()));
- (function(document, id, src, url) {
- var script = document.createElement("script");
- script.type = "text/javascript";
- script.id = id;
- script.src = src;
- document.head.appendChild(script);
- }(document, socialMedium.id, socialMedium.src));
- }
- };
-
- return self;
-};
+"use strict";
+
+/**
+ * A tiny library for load-loading social media share buttons.
+ * If we don't do this, social media will track users even before
+ * they click the like button and we don't like that kind of
+ * monitoring behaviour.
+ */
+define(function() {
+ return function SocialMedia(options) {
+ var $ = options.jQuery;
+ var parent = options.container;
+ var getURL = options.getURL;
+ var urlPlaceHolder = "__URL__PLACE__HOLDER__";
+
+ /**
+ * The various social media all have the same API.
+ */
+ var self = {
+ facebook: {
+ class: "facebook",
+ id: "facebook-jssdk",
+ src: "http://connect.facebook.net/en_US/all.js#xfbml=1&appId=1",
+ html: "<div id='fb-root'></div><div class='fb-like' data-href='"+urlPlaceHolder+"' data-send='false' data-show-faces='false' data-font='tahoma'></div>"
+ },
+
+ google: {
+ class: "google",
+ id: "google-plus",
+ src: "https://apis.google.com/js/plusone.js",
+ html: "<g:plusone annotation='none' href='"+urlPlaceHolder+"'></g:plusone>"
+ },
+
+ twitter: {
+ class: "twitter",
+ id: "twitter-wjs",
+ src: "http://platform.twitter.com/widgets.js",
+ html: "<a href='https://twitter.com/share'class='twitter-share-button' data-url='"+urlPlaceHolder+"' data-via='Mozilla' data-count='none'>Tweet</a>"
+ },
+
+ /**
+ * Hot-load a social medium's button by first
+ * injecting the necessary HTML for the medium
+ * to perform its own iframe replacements, and
+ * then late-loading the script required for
+ * the medium to load up its functionality.
+ */
+ hotLoad: function($, element, socialMedium) {
+ // TODO: Should we escape the return value of getURL()? It's likely
+ // to not contain any characters that need escaping, and its value
+ // is trusted, but we may still want to do it.
+ element.html(socialMedium.html.replace(urlPlaceHolder, getURL()));
+ (function(document, id, src, url) {
+ var script = document.createElement("script");
+ script.type = "text/javascript";
+ script.id = id;
+ script.src = src;
+ document.head.appendChild(script);
+ }(document, socialMedium.id, socialMedium.src));
+ }
+ };
+
+ return self;
+ };
+});

0 comments on commit ca727e8

Please sign in to comment.