indexing.js
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Indexing tester utilities
*
* @package JMAP::INDEXING::administrator::components::com_jmap
* @subpackage js
* @author Joomla! Extensions Store
* @copyright (C) 2015 Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
//'use strict';
(function($) {
var Indexing = function() {
/**
* The first operation is get informations about published data sources
* and start cycle over all the records using promises and recursion
*
* @access private
* @param String keyword
* @param String language
* @return Void
*/
var getKeywordsSuggestion = function(keyword, language) {
//Set the global keyword variable
JMapSupersuggest.setKeywordVariable(keyword, language);
//Generate array of new Keywords (ABC method).
var sKeywords = JMapSupersuggest.generateKeywords(keyword);
//Create a variable that keeps track of how many callbacks we have left before we are done.
JMapSupersuggest.setCallbackNumer(sKeywords.length);
//This actually starts the process of getting the suggestions
JMapSupersuggest.getSuggestionsFromG(sKeywords, language);
};
/**
* Function dummy constructor
*
* @access private
* @param String
* contextSelector
* @method <<IIFE>>
* @return Void
*/
(function __construct() {
// Bind the event listener for the user interaction
var containerWidth = $('div.popover').width();
if(!$('#search').val()) {
$('span[data-role=keywords_suggestion]').css('opacity', 0);
}
// Enables bootstrap popover
$('label.hasClickPopover[data-role=keywords_suggestion]').popover({
trigger: 'click',
placement: 'right',
html: 1,
noTitle: true,
container: 'body',
content: function() {
return $('<img/>')
.attr({
'src': jmap_baseURI + 'administrator/components/com_jmap/images/loading.gif',
'class': 'waiterinfo'})
.css({
'position': 'relative',
'width': '32px',
'height': '32px',
'max-width': 'inherit'});
}
}).on('shown.bs.popover', function(event){
// Add a unique class namespace to the popover
$('body div.popover:last-child').addClass('keywords_suggestion');
// Get input from user
var keyword = $('#search').val();
var langIso = $('#acceptlanguage').val() || 'en-GB';
var language = langIso.split('-').shift();
// Return if no user input.
if (!keyword) {
return false;
}
// Disable button to keep user from submitting twice.
$('#search').prop('disabled', true);
// Call here the async data fetch
getKeywordsSuggestion(keyword, language);
}).on('hidden.bs.popover', function(event){
$('div.popover.right div.arrow').css('top', '');
});
$('span.hasHoverTooltip').tooltip({
trigger:'hover',
placement:'top',
container: 'body'
}).on('show.bs.tooltip', function(event){
event.stopPropagation();
});
// Ensure closing it when click on other DOM elements
$(document).on('click', 'body', function(jqEvent){
if( !$(jqEvent.target).hasClass('hasClickPopover') &&
!$(jqEvent.target).hasClass('popover-content') &&
!$(jqEvent.target).parents('div.popover-content').length) {
$('label.hasClickPopover').popover('hide');
}
});
// Bind live event handler to show the keyword suggestor button
$('#search').on('keyup', function(jqEvent){
if($(this).val()) {
$('span[data-role=keywords_suggestion]').css('opacity', 1);
} else {
$('span[data-role=keywords_suggestion]').css('opacity', 0);
}
});
}).call(this);
}
// On DOM Ready
$(function() {
window.JMapIndexing = new Indexing();
});
})(jQuery);