Solved

Jquery Typeahead - where is the source set?

Posted on 2016-11-13
1
98 Views
Last Modified: 2016-11-17
Hello all, using Jquery and Typehead but can anyone see where the data source (JSON) is being set on this page?

http://keenthemes.com/preview/metronic/theme/admin_2/components_typeahead.html


Thanks,
0
Comment
Question by:Stephen Forlance
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 41885236
in this file : http://keenthemes.com/preview/metronic/theme/assets/pages/scripts/components-typeahead.min.js
line 32 and 130 for countries, do a search for .json for other source :

var ComponentsTypeahead = function() {
    var e = function() {
            var e = new Bloodhound({
                datumTokenizer: function(e) {
                    return Bloodhound.tokenizers.whitespace(e.num)
                },
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                local: [{
                    num: "metronic"
                }, {
                    num: "keenthemes"
                }, {
                    num: "metronic theme"
                }, {
                    num: "metronic template"
                }, {
                    num: "keenthemes team"
                }]
            });
            e.initialize(), App.isRTL() && $("#typeahead_example_1").attr("dir", "rtl"), $("#typeahead_example_1").typeahead(null, {
                displayKey: "num",
                hint: !App.isRTL(),
                source: e.ttAdapter()
            });
            var t = new Bloodhound({
                datumTokenizer: function(e) {
                    return Bloodhound.tokenizers.whitespace(e.name)
                },
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                limit: 10,
                prefetch: {
                    url: "../demo/typeahead_countries.json",
                    filter: function(e) {
                        return $.map(e, function(e) {
                            return {
                                name: e
                            }
                        })
                    }
                }
            });
            t.initialize(), App.isRTL() && $("#typeahead_example_2").attr("dir", "rtl"), $("#typeahead_example_2").typeahead(null, {
                name: "typeahead_example_2",
                displayKey: "name",
                hint: !App.isRTL(),
                source: t.ttAdapter()
            });
            var a = new Bloodhound({
                datumTokenizer: function(e) {
                    return e.tokens
                },
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                remote: {
                    url: "../demo/typeahead_custom.php?query=%QUERY",
                    wildcard: "%QUERY"
                }
            });
            a.initialize(), App.isRTL() && $("#typeahead_example_3").attr("dir", "rtl"), $("#typeahead_example_3").typeahead(null, {
                name: "datypeahead_example_3",
                displayKey: "value",
                source: a.ttAdapter(),
                hint: !App.isRTL(),
                templates: {
                    suggestion: Handlebars.compile(['<div class="media">', '<div class="pull-left">', '<div class="media-object">', '<img src="{{img}}" width="50" height="50"/>', "</div>", "</div>", '<div class="media-body">', '<h4 class="media-heading">{{value}}</h4>', "<p>{{desc}}</p>", "</div>", "</div>"].join(""))
                }
            });
            var n = new Bloodhound({
                    datumTokenizer: function(e) {
                        return Bloodhound.tokenizers.whitespace(e.team)
                    },
                    queryTokenizer: Bloodhound.tokenizers.whitespace,
                    prefetch: "../demo/typeahead_nba.json"
                }),
                i = new Bloodhound({
                    datumTokenizer: function(e) {
                        return Bloodhound.tokenizers.whitespace(e.team)
                    },
                    queryTokenizer: Bloodhound.tokenizers.whitespace,
                    prefetch: "../demo/typeahead_nhl.json"
                });
            n.initialize(), i.initialize(), App.isRTL() && $("#typeahead_example_4").attr("dir", "rtl"), $("#typeahead_example_4").typeahead({
                hint: !App.isRTL(),
                highlight: !0
            }, {
                name: "nba",
                displayKey: "team",
                source: n.ttAdapter(),
                templates: {
                    header: "<h3>NBA Teams</h3>"
                }
            }, {
                name: "nhl",
                displayKey: "team",
                source: i.ttAdapter(),
                templates: {
                    header: "<h3>NHL Teams</h3>"
                }
            })
        },
        t = function() {
            var e = new Bloodhound({
                datumTokenizer: function(e) {
                    return Bloodhound.tokenizers.whitespace(e.num)
                },
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                local: [{
                    num: "metronic"
                }, {
                    num: "keenthemes"
                }, {
                    num: "metronic theme"
                }, {
                    num: "metronic template"
                }, {
                    num: "keenthemes team"
                }]
            });
            e.initialize(), App.isRTL() && $("#typeahead_example_modal_1").attr("dir", "rtl"), $("#typeahead_example_modal_1").typeahead(null, {
                displayKey: "num",
                hint: !App.isRTL(),
                source: e.ttAdapter()
            });
            var t = new Bloodhound({
                datumTokenizer: function(e) {
                    return Bloodhound.tokenizers.whitespace(e.name)
                },
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                limit: 10,
                prefetch: {
                    url: "../demo/typeahead_countries.json",
                    filter: function(e) {
                        return $.map(e, function(e) {
                            return {
                                name: e
                            }
                        })
                    }
                }
            });
            t.initialize(), App.isRTL() && $("#typeahead_example_modal_2").attr("dir", "rtl"), $("#typeahead_example_modal_2").typeahead(null, {
                name: "typeahead_example_modal_2",
                displayKey: "name",
                hint: !App.isRTL(),
                source: t.ttAdapter()
            });
            var a = new Bloodhound({
                datumTokenizer: function(e) {
                    return e.tokens
                },
                queryTokenizer: Bloodhound.tokenizers.whitespace,
                remote: "../demo/typeahead_custom.php?query=%QUERY"
            });
            a.initialize(), App.isRTL() && $("#typeahead_example_modal_3").attr("dir", "rtl"), $("#typeahead_example_modal_3").typeahead(null, {
                name: "datypeahead_example_modal_3",
                displayKey: "value",
                hint: !App.isRTL(),
                source: a.ttAdapter(),
                templates: {
                    suggestion: Handlebars.compile(['<div class="media">', '<div class="pull-left">', '<div class="media-object">', '<img src="{{img}}" width="50" height="50"/>', "</div>", "</div>", '<div class="media-body">', '<h4 class="media-heading">{{value}}</h4>', "<p>{{desc}}</p>", "</div>", "</div>"].join(""))
                }
            });
            var n = new Bloodhound({
                    datumTokenizer: function(e) {
                        return Bloodhound.tokenizers.whitespace(e.team)
                    },
                    queryTokenizer: Bloodhound.tokenizers.whitespace,
                    limit: 3,
                    prefetch: "../demo/typeahead_nba.json"
                }),
                i = new Bloodhound({
                    datumTokenizer: function(e) {
                        return Bloodhound.tokenizers.whitespace(e.team)
                    },
                    queryTokenizer: Bloodhound.tokenizers.whitespace,
                    limit: 3,
                    prefetch: "../demo/typeahead_nhl.json"
                });
            n.initialize(), i.initialize(), $("#typeahead_example_modal_4").typeahead({
                hint: !App.isRTL(),
                highlight: !0
            }, {
                name: "nba",
                displayKey: "team",
                source: n.ttAdapter(),
                templates: {
                    header: "<h3>NBA Teams</h3>"
                }
            }, {
                name: "nhl",
                displayKey: "team",
                source: i.ttAdapter(),
                templates: {
                    header: "<h3>NHL Teams</h3>"
                }
            })
        };
    return {
        init: function() {
            e(), t()
        }
    }
}();
jQuery(document).ready(function() {
    ComponentsTypeahead.init()
});

Open in new window

0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question