local js = require "js" -- LuaJS (to access JS objects) local window = js.global -- Global object (window) local document = window.document -- Document object (DOM) local cms = window.cms -- CMS object (CraftYourCMS Helpers) -- Register your plugin (name (the plugin slug)) local plugin = cms:registerPlugin("disqus-embed") -- Need to be the same as the created plugin name, else it not work -- Add a new module that can be rendered on the website -- (name, title) local disqusModule = plugin:addModule("disqus-module", "Discussion / Commentaires") -- Add setting editable by the admin for this module -- (name, type[options...], label, defaultValue) disqusModule:addSetting("domain", "text[required|minlength:3]", "Domaine disqus", "exemple.disqus.com") -- Define the render function for this module -- The plugin will be automatically rendered on the website where the module is added by the admin disqusModule:onRender(function(module) local name = module:getSetting("domain") local script = document:createElement('script'); script.src = 'https://' .. name .. '/embed.js'; script:setAttribute('data-timestamp', window:Date()); document.body:appendChild(script); local css = document:createElement('style'); css.innerHTML = "#disqus_thread { width: 100% }"; document.head:appendChild(css); return "
" end)