google.js
4.23 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
126
127
128
129
130
131
132
133
/**
* Submit sitemaps to GWT utility class
*
* @package JMAP::GOOGLE::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 WebmastersTools = function() {
/**
* Snippet to append for file uploader
*
* @access private
* @var String
*/
var submitsitemapSnippet ='<div id="uploadrow" style="display: none;">' +
'<span class="input-group input-large">' +
'<span title="' + COM_JMAP_ADDSITEMAP_DESC + '" class="input-group-addon"><span class="glyphicon glyphicon-upload"></span> ' + COM_JMAP_ADDSITEMAP + '</span>' +
'<input type="text" id="sitemaplink" name="sitemaplink" value="">' +
'</span>' +
'<button class="btn btn-primary btn-xs" id="startimport">' + COM_JMAP_SUBMIT + '</button> ' +
'<button class="btn btn-primary btn-xs" id="cancelimport">' + COM_JMAP_CANCEL + '</button>' +
'</div>';
/**
* Clicked sitemap URL to delete
*
* @access private
* @var String
*/
var sitemapUrl = '';
/**
* Function dummy constructor
*
* @access private
* @param String
* contextSelector
* @method <<IIFE>>
* @return Void
*/
(function __construct() {
// Remove predefined Joomla behavior
$('#toolbar-upload button').removeAttr('onclick');
// Append uploader row
$('#uploadrow').remove();
$('#adminForm').prepend(submitsitemapSnippet)
// Attach custom feature
$('#toolbar-upload button').on('click', function(jqEvent){
jqEvent.preventDefault();
// Append uploader row
$('#uploadrow').slideDown();
return false;
});
// Bind the uploader button
$('#startimport').on('click', function(jqEvent) {
// Validate input
var sitemapInput = $('#sitemaplink');
var sitemapLink = $('#sitemaplink').val();
if(!sitemapLink) {
sitemapInput.css('border', '1px solid #F00').next('span.validation').remove().end().after('<span class="validation label label-danger">' + COM_JMAP_REQUIRED + '</span>');
sitemapInput.on('change', function(jqEvent){
$(this).css('border', '1px solid #ccc').next('span.validation').remove();
});
return false;
}
// Validate URL
var expression = "^(http[s]?:\\/\\/(www\\.)?|ftp:\\/\\/(www\\.)?|www\\.){1}([0-9A-Za-z-\\.@:%_\+~#=]+)+((\\.[a-zA-Z]{2,3})*)(/(.)*)?(\\?(.)*)?";
var regexUrl = new RegExp(expression);
if(!sitemapLink.match(regexUrl)) {
sitemapInput.css('border', '1px solid #F00').next('span.validation').remove().end().after('<span class="validation label label-danger">' + COM_JMAP_INVALID_URL_FORMAT + '</span>');
sitemapInput.on('change', function(jqEvent){
$(this).css('border', '1px solid #ccc').next('span.validation').remove();
});
return false;
}
// Change the task and submit miniform uploader
$('#adminForm input[name=task]').val('google.submitSitemap');
$('#adminForm').trigger('submit');
});
// Cancel upload operation
$('#cancelimport').on('click', function(jqEvent){
jqEvent.preventDefault();
$('#uploadrow').slideUp();
return false;
});
// Modal sitemap delete confirmation
$('#sitemapDeleteModal').on('shown.bs.modal', function(bsEvent) {
$('button[data-role=confirm-delete]').one('click', function(jqEvent){
$('#adminForm input[name=sitemapurl]').val(sitemapUrl);
$('#adminForm input[name=task]').val('google.deleteSitemap');
$('#adminForm').submit();
});
});
$('a[data-role=sitemapdelete]').on('click', function (jqEvent) {
sitemapUrl = $(this).data('url');
$('#sitemapDeleteModal').modal({
backdrop:'static'
});
});
// Resubmit sitemap button
$('a[data-role=sitemapresubmit]').on('click', function (jqEvent) {
sitemapUrl = $(this).data('url');
// Change the task and submit miniform uploader
$('#sitemaplink').val(sitemapUrl);
$('#adminForm input[name=task]').val('google.submitSitemap');
$('#adminForm').trigger('submit');
});
}).call(this);
};
// On DOM Ready
$(function() {
window.JMapWebmastersTools = new WebmastersTools();
});
})(jQuery);