12
12
function harvest_links(links_holder, link_class, link_type) {
13
13
// Get any links of the specified link_class and store them as the
14
14
// specified link_type in the specified links_holder
15
var link_info = new Array();
16
16
Y.all('.'+link_class).each(function(link) {
17
17
var href = link.getAttribute('href');
18
18
if( link_info.indexOf(href)<0 ) {
27
function process_invalid_links(link_info, link_class, link_type) {
28
// We have a collection of invalid links possibly containing links of
27
function process_links(link_info, link_class, link_type) {
28
// We have a collection of valid and invalid links containing links of
29
29
// type link_type, so we need to remove the existing link_class,
30
30
// replace it with an invalid-link class, and set the link title.
31
var invalid_links = link_info['invalid_'+link_type];
33
if( Y.Object.size(invalid_links) == 0 )
31
var invalid_links = link_info[link_type].invalid || {};
32
var valid_links = link_info[link_type].valid || {};
36
34
Y.all('.'+link_class).each(function(link) {
37
35
var href = link.getAttribute('href');
38
if( !(href in invalid_links) )
40
var invalid_link_msg = invalid_links[href];
41
link.removeClass(link_class);
42
link.addClass('invalid-link');
43
link.setAttribute('title', invalid_link_msg);
44
link.on('click', function(e) {
46
alert(invalid_link_msg);
36
if(invalid_links.hasOwnProperty(href)) {
37
var invalid_link_msg = invalid_links[href];
38
link.removeClass(link_class);
39
link.addClass('invalid-link');
40
link.setAttribute('title', invalid_link_msg);
41
link.on('click', function(e) {
43
alert(invalid_link_msg);
45
} else if(valid_links.hasOwnProperty(href)) {
46
var valid_link_msg = valid_links[href];
47
link.setAttribute('title', valid_link_msg);
51
Y.lp.app.links.check_valid_lp_links = function() {
53
Y.lp.app.links.check_valid_lp_links = function(io_provider) {
52
54
// Grabs any lp: style links on the page and checks that they are
53
55
// valid. Invalid ones have their class changed to "invalid-link".
54
// ATM, we only handle +branch links.
56
// ATM, we only handle +branch and bug links.
56
var links_to_check = {}
58
var links_to_check = {};
58
60
// We get all the links with defined css classes.
59
61
// At the moment, we just handle branch links, but in future...
75
77
failure: function(id, response, args) {
76
78
// If we have firebug installed, log the error.
77
if( console != undefined ) {
79
if( Y.Lang.isValue(console) ) {
78
80
console.log("Link Check Error: " + args + ': '
79
+ response.status + ' - ' +
80
response.statusText + ' - '
81
+ response.responseXML);
81
+ response.status + ' - ' +
82
response.statusText + ' - '
83
+ response.responseXML);
84
86
success: function(id, response) {
85
var link_info = Y.JSON.parse(response.responseText)
86
// ATM, we just handle branch links, but in future...
87
process_invalid_links(link_info, 'branch-short-link',
89
process_invalid_links(link_info, 'bug-link',
87
var link_info = Y.JSON.parse(response.responseText);
88
// We handle bug and branch links. The future is here.
89
process_links(link_info, 'branch-short-link',
91
process_links(link_info, 'bug-link',
94
96
var uri = '+check-links';
95
97
var on = Y.merge(config.on);
100
102
'arguments': [client, uri],
104
Y.lp.client.get_io_provider(io_provider).io(uri, y_config);
105
107
}, "0.1", {"requires": ["base", "node", "io", "dom", "json", "lp.client"]});