Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include.postload.js

Issue 5088751004942336: Issue 370 - Right-clicked element is removed independent of created filter (Closed)
Patch Set: Rebase to rev 3c9cea80c481 Created July 18, 2014, 8:54 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « iconAnimation.js ('k') | include.preload.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (elt.className) 292 if (elt.className)
293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); 293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' ');
294 294
295 clickHideFilters = new Array(); 295 clickHideFilters = new Array();
296 selectorList = new Array(); 296 selectorList = new Array();
297 if (elementId) 297 if (elementId)
298 { 298 {
299 clickHideFilters.push(document.domain + "###" + elementId); 299 clickHideFilters.push(document.domain + "###" + elementId);
300 selectorList.push("#" + elementId); 300 selectorList.push("#" + elementId);
301 } 301 }
302 if (elementClasses) 302 if (elementClasses && elementClasses.length > 0)
303 { 303 {
304 for(var i = 0; i < elementClasses.length; i++) 304 var selector = elementClasses.map(function(elClass)
305 { 305 {
306 clickHideFilters.push(document.domain + "##." + elementClasses[i]); 306 return "." + elClass.replace(/([^\w-])/, "\\$1");
307 selectorList.push("." + elementClasses[i]); 307 }).join("");
308 } 308
309 clickHideFilters.push(document.domain + "##" + selector);
310 selectorList.push(selector);
309 } 311 }
310 if (url) 312 if (url)
311 { 313 {
312 clickHideFilters.push(relativeToAbsoluteUrl(url)); 314 clickHideFilters.push(relativeToAbsoluteUrl(url));
313 selectorList.push(elt.localName + '[src="' + url + '"]'); 315 selectorList.push(elt.localName + '[src="' + url + '"]');
314 } 316 }
315 317
316 // Show popup 318 // Show popup
317 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); 319 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
318 320
(...skipping 27 matching lines...) Expand all
346 params = elt.querySelectorAll("param[name=\"src\"]"); 348 params = elt.querySelectorAll("param[name=\"src\"]");
347 if(params[0]) 349 if(params[0])
348 url = params[0].getAttribute("value"); 350 url = params[0].getAttribute("value");
349 } 351 }
350 } else if(!url) { 352 } else if(!url) {
351 url = elt.getAttribute("src") || elt.getAttribute("href"); 353 url = elt.getAttribute("src") || elt.getAttribute("href");
352 } 354 }
353 return url; 355 return url;
354 } 356 }
355 357
356 // Converts relative to absolute URL
357 // e.g.: foo.swf on http://example.com/whatever/bar.html
358 // -> http://example.com/whatever/foo.swf
359 function relativeToAbsoluteUrl(url)
360 {
361 // If URL is already absolute, don't mess with it
362 if (!url || /^[\w\-]+:/i.test(url))
363 return url;
364
365 // Leading / means absolute path
366 // Leading // means network path
367 if (url[0] == '/')
368 {
369 if (url[1] == '/')
370 return document.location.protocol + url;
371 else
372 return document.location.protocol + "//" + document.location.host + url;
373 }
374
375 // Remove filename and add relative URL to it
376 var base = document.baseURI.match(/.+\//);
377 if (!base)
378 return document.baseURI + "/" + url;
379 return base[0] + url;
380 }
381
382 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js 358 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js
383 // and licensed under the MIT license. See jquery-*.min.js for details. 359 // and licensed under the MIT license. See jquery-*.min.js for details.
384 function removeDotSegments(u) { 360 function removeDotSegments(u) {
385 var r = '', m = []; 361 var r = '', m = [];
386 if (/\./.test(u)) { 362 if (/\./.test(u)) {
387 while (u !== undefined && u !== '') { 363 while (u !== undefined && u !== '') {
388 if (u === '.' || u === '..') { 364 if (u === '.' || u === '..') {
389 u = ''; 365 u = '';
390 } else if (/^\.\.\//.test(u)) { // starts with ../ 366 } else if (/^\.\.\//.test(u)) { // starts with ../
391 u = u.substring(3); 367 u = u.substring(3);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 case "get-clickhide-state": 480 case "get-clickhide-state":
505 sendResponse({active: clickHide_activated}); 481 sendResponse({active: clickHide_activated});
506 break; 482 break;
507 case "clickhide-activate": 483 case "clickhide-activate":
508 clickHide_activate(); 484 clickHide_activate();
509 break; 485 break;
510 case "clickhide-deactivate": 486 case "clickhide-deactivate":
511 clickHide_deactivate(); 487 clickHide_deactivate();
512 break; 488 break;
513 case "clickhide-new-filter": 489 case "clickhide-new-filter":
514 // The request is received by all frames, so ignore it if we're not the frame the 490 // The message is received by all frames, so ignore it if we're not the frame the
515 // user right-clicked in 491 // user right-clicked in
516 if(!lastRightClickEvent) 492 if(!lastRightClickEvent)
517 return; 493 return;
518 // We hope the URL we are given is the same as the one in the element re ferenced 494 // We hope the URL we are given is the same as the one in the element re ferenced
519 // by lastRightClickEvent.target. If not, we just discard 495 // by lastRightClickEvent.target. If not, we just discard
520 var target = lastRightClickEvent.target; 496 var target = lastRightClickEvent.target;
521 var url = target.src; 497 var url = target.src;
522 // If we don't have the element with a src URL same as the filter, look for it. 498 // If we don't have the element with a src URL same as the filter, look for it.
523 // Chrome's context menu API is terrible. Why can't it give us the frigg in' element 499 // Chrome's context menu API is terrible. Why can't it give us the frigg in' element
524 // to start with? 500 // to start with?
(...skipping 10 matching lines...) Expand all
535 // This is hopefully our element. In case of multiple elements 511 // This is hopefully our element. In case of multiple elements
536 // with the same src, only one will be highlighted. 512 // with the same src, only one will be highlighted.
537 target = elts[i]; 513 target = elts[i];
538 break; 514 break;
539 } 515 }
540 } 516 }
541 } 517 }
542 // Following test will be true if we found the element with the filter U RL 518 // Following test will be true if we found the element with the filter U RL
543 if(msg.filter === url) 519 if(msg.filter === url)
544 { 520 {
545 // This request would have come from the chrome.contextMenu handler, s o we 521 // This message would have come from the chrome.contextMenu handler, s o we
546 // simulate the user having chosen the element to get rid of via the u sual means. 522 // simulate the user having chosen the element to get rid of via the u sual means.
547 clickHide_activated = true; 523 clickHide_activated = true;
548 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s o why set it? 524 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s o why set it?
549 clickHideFilters = [msg.filter]; 525 clickHideFilters = [msg.filter];
550 // Coerce red highlighted overlay on top of element to remove. 526 // Coerce red highlighted overlay on top of element to remove.
551 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta fix it sometime 527 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta fix it sometime
552 currentElement = addElementOverlay(target); 528 currentElement = addElementOverlay(target);
553 currentElement_backgroundColor = target.style.backgroundColor; 529 currentElement_backgroundColor = target.style.backgroundColor;
554 // clickHide_mouseOver(lastRightClickEvent); 530 // clickHide_mouseOver(lastRightClickEvent);
555 clickHide_mouseClick(lastRightClickEvent); 531 clickHide_mouseClick(lastRightClickEvent);
556 } 532 }
557 else 533 else
558 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", request.filter, url, lastRightClickEvent.target.src); 534 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", msg.filter, url, lastRightClickEvent.target.src);
559 break; 535 break;
560 case "clickhide-init": 536 case "clickhide-init":
561 if (clickHideFiltersDialog) 537 if (clickHideFiltersDialog)
562 { 538 {
563 sendResponse({filters: clickHide_filters}); 539 sendResponse({filters: clickHide_filters});
564 540
565 clickHideFiltersDialog.style.width = (msg.width + 5) + "px"; 541 clickHideFiltersDialog.style.width = msg.width + "px";
566 clickHideFiltersDialog.style.height = (msg.height + 5) + "px"; 542 clickHideFiltersDialog.style.height = msg.height + "px";
567 clickHideFiltersDialog.style.visibility = "visible"; 543 clickHideFiltersDialog.style.visibility = "visible";
568 } 544 }
569 break; 545 break;
570 case "clickhide-move": 546 case "clickhide-move":
571 if (clickHideFiltersDialog) 547 if (clickHideFiltersDialog)
572 { 548 {
573 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + request.x) + "px"; 549 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px";
574 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + request.y) + "px"; 550 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px";
575 } 551 }
576 break; 552 break;
577 case "clickhide-close": 553 case "clickhide-close":
578 if (clickHideFiltersDialog) 554 if (clickHideFiltersDialog)
579 { 555 {
580 // Explicitly get rid of currentElement 556 // Explicitly get rid of currentElement
581 if (msg.remove && currentElement && currentElement.parentNode) 557 var element = currentElement;
582 currentElement.parentNode.removeChild(currentElement); 558 currentElement.parentNode.removeChild(currentElement);
559 ext.backgroundPage.sendMessage({
560 type: "should-collapse",
561 url: element.src,
562 documentUrl: document.URL,
563 mediatype: typeMap[element.localName]
564 }, function(response)
565 {
566 if (response && element.parentNode)
567 element.parentNode.removeChild(element);
568 });
583 569
584 clickHide_deactivate(); 570 clickHide_deactivate();
585 } 571 }
586 break; 572 break;
587 default: 573 default:
588 sendResponse({}); 574 sendResponse({});
589 break; 575 break;
590 } 576 }
591 }); 577 });
592 } 578 }
OLDNEW
« no previous file with comments | « iconAnimation.js ('k') | include.preload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld