Commit 028e366d authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Replace 'id' field in search data with 'url'.

A first step in making possible to include guides and other stuff
to search.

Exposed Docs.History#navigate method to have an easy way to navigate
to any page by URL.
parent ebfcfed6
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ module JsDuck
        :member => name,
        :type => :class,
        :icon => cls.icon + "-redirect",
        :id => cls.full_name,
        :url => "#!/api/" + cls.full_name,
        :meta => cls[:meta],
        :sort => 0,
      }
@@ -55,7 +55,7 @@ module JsDuck
        :member => cls.short_name,
        :type => :class,
        :icon => cls.icon,
        :id => cls.full_name,
        :url => "#!/api/" + cls.full_name,
        :meta => cls[:meta],
        :sort => 1,
      }
@@ -68,7 +68,7 @@ module JsDuck
        :member => Class.short_name(name),
        :type => :class,
        :icon => cls.icon + "-redirect",
        :id => cls.full_name,
        :url => "#!/api/" + cls.full_name,
        :meta => cls[:meta],
        :sort => 2,
      }
@@ -81,7 +81,7 @@ module JsDuck
        :member => member[:name],
        :type => :member,
        :icon => "icon-" + member[:tagname].to_s,
        :id => cls.full_name + "-" + member[:id],
        :url => "#!/api/" + cls.full_name + "-" + member[:id],
        :meta => member[:meta],
        :sort => 3,
      }
+20 −14
Original line number Diff line number Diff line
@@ -13,7 +13,9 @@ Ext.define("Docs.History", {
            this.initialNavigate();
        }, this);

        Ext.util.History.on("change", this.navigate, this);
        Ext.util.History.on("change", function(url) {
            this.navigate(url, true);
        }, this);
    },

    /**
@@ -27,37 +29,41 @@ Ext.define("Docs.History", {
    // Invoke initial navigation only after both tabs and history are loaded
    initialNavigate: function() {
        if (this.tabsLoaded && this.historyLoaded) {
            this.navigate(Ext.util.History.getToken());
            this.navigate(Ext.util.History.getToken(), true);
        }
    },

    // Parses current URL and navigates to the page
    navigate: function(token) {

    /**
     * Parses given URL and navigates to the page.
     *
     * @param {String} token An URL where to navigate.
     * @param {Boolean} [noHistory=false] True to skip adding new history entry.
     */
    navigate: function(token, noHistory) {
        var url = this.parseToken(token);
        if (url.url == "#!/api") {
            Docs.App.getController('Classes').loadIndex(true);
            Docs.App.getController('Classes').loadIndex(noHistory);
        }
        else if (url.type === "api") {
            Docs.App.getController('Classes').loadClass(url.url, true);
            Docs.App.getController('Classes').loadClass(url.url, noHistory);
        }
        else if (url.url === "#!/guide") {
            Docs.App.getController('Guides').loadIndex(true);
            Docs.App.getController('Guides').loadIndex(noHistory);
        }
        else if (url.type === "guide") {
            Docs.App.getController('Guides').loadGuide(url.url, true);
            Docs.App.getController('Guides').loadGuide(url.url, noHistory);
        }
        else if (url.url === "#!/video") {
            Docs.App.getController('Videos').loadIndex(true);
            Docs.App.getController('Videos').loadIndex(noHistory);
        }
        else if (url.type === "video") {
            Docs.App.getController('Videos').loadVideo(url.url, true);
            Docs.App.getController('Videos').loadVideo(url.url, noHistory);
        }
        else if (url.url === "#!/example") {
            Docs.App.getController('Examples').loadIndex();
        }
        else if (url.type === "example") {
            Docs.App.getController('Examples').loadExample(url.url, true);
            Docs.App.getController('Examples').loadExample(url.url, noHistory);
        }
        else if (url.url === "#!/stats") {
            Docs.App.getController('Stats').loadIndex();
@@ -67,11 +73,11 @@ Ext.define("Docs.History", {
        }
        else {
            if (Docs.App.getController('Welcome').isActive()) {
                Docs.App.getController('Welcome').loadIndex(true);
                Docs.App.getController('Welcome').loadIndex(noHistory);
            }
            else if (!this.noRepeatNav) {
                this.noRepeatNav = true; // Prevent infinite nav loop
                this.navigate(Ext.getCmp('doctabs').staticTabs[0].href);
                this.navigate(Ext.getCmp('doctabs').staticTabs[0].href, noHistory);
            }
        }
    },
+3 −2
Original line number Diff line number Diff line
@@ -5,7 +5,8 @@ Ext.define('Docs.controller.Search', {
    extend: 'Ext.app.Controller',

    requires: [
        'Docs.ClassRegistry'
        'Docs.ClassRegistry',
        'Docs.History'
    ],

    views: [
@@ -127,7 +128,7 @@ Ext.define('Docs.controller.Search', {

    // loads class/method corrseponding to the record
    loadRecord: function(record) {
        Docs.App.getController('Classes').loadClass("#!/api/"+record.get("id"));
        Docs.History.navigate(record.get("url"));
        this.getDropdown().hide();
    },

+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
Ext.define('Docs.store.Search', {
    extend: 'Ext.data.Store',

    fields: ['cls', 'member', 'type', 'icon', 'id', 'meta', 'sort'],
    fields: ['cls', 'member', 'type', 'icon', 'url', 'meta', 'sort'],
    proxy: {
        type: 'memory',
        reader: {