JAVASCRIPT 30
Omponent-disqus.js Guest on 25th June 2020 03:22:33 AM
  1. /**
  2.  * Component Disqus
  3.  * @module Disqus
  4.  * @param  {jQuery} $ Instance of jQuery
  5.  * @param  {Document} document Instance of Document
  6.  * @return {Object} List of Disqus methods
  7.  */
  8. XA.component.disqus = (function($, document) {
  9.     /**
  10.      * This object stores all public api methods
  11.      * @type {Object.<Methods>}
  12.      * @memberOf module:Archive
  13.      * */
  14.     var api = {};
  15.     /**
  16.      * initDisqus method create script element  for discuss component
  17.      * @memberOf module:Disqus
  18.      * @method
  19.      * @param {Object} prop option of disqus component
  20.      * @alias module:Disqus.initDisqus
  21.      * @private
  22.      */
  23.     function initDisqus(prop) {
  24.         var dsq = document.createElement("script");
  25.         dsq.type = "text/javascript";
  26.         dsq.async = true;
  27.         dsq.src = "//" + prop.disqus_shortname + ".disqus.com/embed.js";
  28.         (
  29.             document.getElementsByTagName("head")[0] ||
  30.             document.getElementsByTagName("body")[0]
  31.         ).appendChild(dsq);
  32.     }
  33.     /**
  34.      * initInstance method sets up disqus_config and calls
  35.      * [".initDisqus"]{@link module:Disqus.initDisqus}  method.
  36.      * @memberOf module:Disqus
  37.      * @method
  38.      * @param {jQuery} component Root DOM element of archive component wrapped by jQuery
  39.      * @param {Object} prop option of disqus component
  40.      * @alias module:Disqus.initInstance
  41.      */
  42.     api.initInstance = function(component, prop) {
  43.         window.disqus_config = function() {
  44.             this.page.url = prop.disqus_url;
  45.             this.page.identifier = prop.disqus_identifier;
  46.             this.page.title = prop.disqus_title;
  47.             this.page.category_id = prop.disqus_category_id;
  48.         };
  49.         if (component.find("#disqus_thread").length > 0) {
  50.             initDisqus(prop);
  51.         }
  52.     };
  53.     /**
  54.      * init method calls in a loop for each
  55.      * disqus component on a page and runs Disqus's
  56.      * [".initInstance"]{@link module:Disqus.initInstance}  method.
  57.      * @memberOf module:Disqus
  58.      * @alias module:Disqus.init
  59.      */
  60.     api.init = function() {
  61.         var disqus = $(".disqus:not(.initialized)");
  62.         disqus.each(function() {
  63.             var properties = $(this).data("properties");
  64.             api.initInstance($(this), properties);
  65.             $(this).addClass("initialized");
  66.         });
  67.     };
  68.     return api;
  69. })(jQuery, document);
  70. XA.register("disqus", XA.component.disqus);

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.