Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adding brackets & braces highlight #42

Closed
wants to merge 1 commit into from

2 participants

@IAL32

The second part in adding highlight.
Here i apply the click event to all the brackets & braces to highlight/de-highlight them. Added few functions to easify the work.
Ps: sorry for my english, i'm 16 years old and i'm Italian.

@IAL32 IAL32 Adding brackets & braces highlight
The second part in adding highlight.
Here i apply the click event to all the brackets & braces to highlight/de-highlight them. Added few functions to easify the work.
Ps: sorry for my english, i'm 16 years old and i'm Italian.
d05ad7e
@IAL32 IAL32 commented on the diff
src/content/default.js
@@ -40,9 +40,57 @@ document.addEventListener('DOMContentLoaded', function() {
collapser.addEventListener('click', collapse, false);
item.insertBefore(collapser, item.firstChild);
}
-
+
+ function hasClassName(ele,cls) {
@IAL32
IAL32 added a note

This 3 functions are totally taken from internet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bhollis
Owner

Hi @IAL32, this is a neat contribution. Thanks! But, can you explain why you want to highlight braces? They're already lined up...

@bhollis bhollis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 5, 2013
  1. @IAL32

    Adding brackets & braces highlight

    IAL32 authored
    The second part in adding highlight.
    Here i apply the click event to all the brackets & braces to highlight/de-highlight them. Added few functions to easify the work.
    Ps: sorry for my english, i'm 16 years old and i'm Italian.
This page is out of date. Refresh to see the latest.
Showing with 50 additions and 2 deletions.
  1. +50 −2 src/content/default.js
View
52 src/content/default.js
@@ -40,9 +40,57 @@ document.addEventListener('DOMContentLoaded', function() {
collapser.addEventListener('click', collapse, false);
item.insertBefore(collapser, item.firstChild);
}
-
+
+ function hasClassName(ele,cls) {
@IAL32
IAL32 added a note

This 3 functions are totally taken from internet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
+ }
+
+ function addClassName(ele,cls) {
+ if (!hasClassName(ele,cls)) ele.className += " " + cls;
+ }
+
+ function removeClassName(ele,cls) {
+ if (hasClassName(ele, cls)) {
+ var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
+ ele.className = ele.className.replace(reg, ' ');
+ }
+ }
+ function highlightBrackets(brack) {
+ var toMatch = brack.className.split(" ");
+ var brackData = {
+ "direction": toMatch[0],
+ "directionOpposite": ("left" == toMatch[0]) ? "right" : "left",
+ "type": toMatch[1],
+ "bracketID": brack.getAttribute('bracketid')
+ };
+ var toSearchQuery = "." + brackData.directionOpposite + "." + brackData.type + "[bracketid='" + brackData.bracketID + "']";
+ console.log(toSearchQuery);
+ var otherBrack = document.querySelector(toSearchQuery);
+ if(hasClassName(brack, 'light')) {
+ removeClassName(brack, 'light');
+ removeClassName(otherBrack, 'light');
+ } else {
+ addClassName(brack, 'light');
+ addClassName(otherBrack, 'light');
+ }
+ }
var items = document.getElementsByClassName('collapsible');
- for( var i = 0; i < items.length; i++) {
+ for( var i = 0; i < items.length; i++ ) {
addCollapser(items[i].parentNode);
}
+
+ var left_sel = document.getElementsByClassName('left');
+ var right_sel = document.getElementsByClassName('right');
+ if( left_sel.length != right_sel.length ) console.log('There was an error while counting left & right brackets');
+ else {
+ var brackets_length = left_sel.length || right_sel.length;
+ for( var i = 0; i < brackets_length; i++ ) {
+ left_sel[i].addEventListener('click', function() {
+ highlightBrackets(this);
+ }, false);
+ right_sel[i].addEventListener('click', function() {
+ highlightBrackets(this);
+ }, false);
+ }
+ }
}, false);
Something went wrong with that request. Please try again.