Here at my company, we are working hard to deliver a good comment using the experience of the amazing Disqus widget.
Our site is entirely AJAX based, using requirejs, jquery and backbone for most.
We have already added the Disqus widget to the pages where we need it. During the page change, we, of course, destroy the div where the Disqus widget lives, and we again create all the things.
Everything is fine with the old widgets in each browser. There is a problem with activating the Disqus 2012 widget, which does not appear with the error "Uncaught TypeError: cannot call the postMessage" null "method in Safari and Chrome. Firefox works fine.
Here is the code:
define([ 'underscore', 'backbone', 'models/config', 'models/book' ], function(_, Backbone, config) { App.Models.Disqus = Backbone.Model.extend({ bookObj: null, initialize: function(options){ console.log("discus.initialize()"); var _this=this; _this.bookObj= new App.Models.Book({id: options.id}); _this.bookObj.fetch({ dataType: 'jsonp', success: function(model,response){ (typeof DISQUS == 'undefined')?_this.initDisqus():_this.resetDisqus(); } }); }, initDisqus: function(){ console.log("discus.init()"); disqus_shortname=config.get('DISQUS_ID'); disqus_title = this.bookObj.get('content').title; disqus_config = function (){ // this.page.identifier = _this.id; // this.page.url = document.URL; this.language = config.get('LANG'); }; require(['http://'+disqus_shortname+'.disqus.com/embed.js'], function(){}); }, resetDisqus: function(){ console.log("discus.reset()"); var _this=this; DISQUS.reset({ reload: true, config: function(){ this.page.identifier = _this.id; this.page.url = document.URL; this.page.title = _this.bookObj.get('content').title; this.language = config.get('LANG'); } }); } }); return App.Models.Disqus; });
If you need more information, feel free to ask.
Thanks in advance, Giorgio
OK guys solved this way:
define([ 'underscore', 'backbone', 'models/config', 'models/book' ], function(_, Backbone, config) { App.Models.Disqus = Backbone.Model.extend({ bookObj: null, initialize: function(options){ console.log("discus.initialize()"); var _this=this; _this.bookObj= new App.Models.Book({id: options.id}); _this.bookObj.fetch({ dataType: 'jsonp', success: function(model,response){ //(typeof DISQUS == 'undefined')?_this.initDisqus():_this.resetDisqus(); delete DISQUS; disqus_shortname = config.get('DISQUS_ID'); disqus_identifier = _this.id; disqus_url = document.URL; disqus_title = _this.bookObj.get('content').title; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); } }); }, }); return App.Models.Disqus; });