Commit 80ac93b8 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Enable comments only when CORS supported.

Previously it was only checked if IE >= 8, but now we do proper
feature-detection. This also disables comments in Opera, so Docs
app no more crashes it.

Also we now hide the comment controls completely when comments
are disabled. Previously the view-comments buttons were still there
when comments were disabled.
parent c97ad0fe
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -188,11 +188,13 @@ class JsDuckRunner
    EOHTML
  end

  # Enables comments when CORS is supported by browser.
  # This excludes Opera and IE < 8
  def add_comments(db_name)
    comments_base_url = "http://projects.sencha.com/auth"
    @options += ["--head-html", <<-EOHTML]
      <script type="text/javascript">
        Docs.enableComments = true;
        Docs.enableComments = ("withCredentials" in new XMLHttpRequest()) || (typeof XDomainRequest !== "undefined");
        Docs.baseUrl = "#{comments_base_url}";
        Docs.commentsDb = "#{db_name}";
      </script>
+2 −6
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ Ext.define('Docs.controller.Auth', {
            "available"
        );

        if (Ext.isIE) {
            Docs.enableComments = Ext.ieVersion >= 8;
        if (!Docs.enableComments) {
            return;
        }

        this.control({
@@ -67,10 +67,6 @@ Ext.define('Docs.controller.Auth', {
     * Checks if a user is logged in server side and sets up a local session if they are.
     */
    getSession: function() {
        if (!Docs.enableComments) {
            return;
        }

        Ext.Ajax.request({
            url: Docs.baseUrl + '/session',
            params: { sid: this.sid },
+5 −1
Original line number Diff line number Diff line
@@ -46,6 +46,10 @@ Ext.define('Docs.controller.Comments', {
            'remove'
        );

        if (!Docs.enableComments) {
            return;
        }

        this.getController('Auth').on({
            available: function() {
                this.enableComments();
+4 −0
Original line number Diff line number Diff line
@@ -35,6 +35,10 @@ Ext.define('Docs.controller.CommentsMeta', {
            'afterLoad'
        );

        if (!Docs.enableComments) {
            return;
        }

        this.getController('Auth').on({
            available: function() {
                this.fetchCommentMeta();