Skip to content

Commit 7039220

Browse files
committed
Completely remove all code relevant to sub-observers.
Update documentation.
1 parent bf8f647 commit 7039220

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ gmail.observe.off(null,'before'); // disables all before observers
10901090
gmail.observe.off(); // disables all
10911091
```
10921092

1093-
#### gmail.observe.register(action, class/args, parent=null)
1093+
#### gmail.observe.register(action, class/args)
10941094

10951095
Allow an application to register a custom DOM observer specific to their application.
10961096
Adds it to the configured DOM observers that will then be supported by the dom insertion observer.
@@ -1102,7 +1102,6 @@ This method can be called two different ways:
11021102
Simple:
11031103
- action - the name of the new DOM observer
11041104
- class - the class of an inserted DOM element that identifies that this action should be triggered
1105-
- parent - optional - if specified, this observer will be registered as a sub_observer for the specified parent (meaning it will only be checked for if the parent observer has something bound to it, and has been triggered).
11061105

11071106
Complex:
11081107
- action - the name of the new DOM observer
@@ -1111,7 +1110,6 @@ Complex:
11111110
- selector - if you need to match more than just the className of a specific element to indicate a match, you can use this selector for further checking (uses element.is(selector) on matched element). E.g. if there are multiple elements with a class indicating an observer should fire, but you only want it to fire on a specific id, then you would use this
11121111
- sub_selector - if specified, we do a jquery element.find for the passed selector on the inserted element and ensure we can find a match
11131112
- handler - if specified this handler is called if a match is found. Otherwise default calls the callback & passes the jQuery matchElement
1114-
- parent - optional - as above with simple
11151113

11161114
```js
11171115

src/gmail.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,8 @@ interface GmailObserve {
787787
action - the name of the new DOM observer
788788
className / args - for a simple observer, this arg can simply be the class on an inserted DOM element that identifies this event should be
789789
triggered. For a more complicated observer, this can be an object containing properties for each of the supported DOM observer config arguments
790-
parent - optional - if specified, this observer will be registered as a sub_observer for the specified parent
791790
*/
792-
register(action: string, args: string | StringDict, parent?: any): void;
791+
register(action: string, args: string | StringDict): void;
793792
/**
794793
Observe DOM nodes being inserted. When a node with a class defined in api.tracker.dom_observers is inserted,
795794
trigger the related event and fire off any relevant bound callbacks

src/gmail.js

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,13 +1608,12 @@ var Gmail = function(localJQuery) {
16081608
// map observers to DOM class names
16091609
// as elements are inserted into the DOM, these classes will be checked for and mapped events triggered,
16101610
// receiving "e" event object, and a jquery bound inserted DOM element
1611-
// NOTE: supported observers and sub_observers must be registered in the supported_observers array as well as the dom_observers config
1611+
// NOTE: supported observers must be registered in the supported_observers array as well as the dom_observers config
16121612
// Config example: event_name: {
16131613
// class: "className", // required - check for this className in the inserted DOM element
16141614
// selector: "div.className#myId", // if you need to match more than just the className of a specific element to indicate a match, you can use this selector for further checking (uses element.is(selector) on matched element). E.g. if there are multiple elements with a class indicating an observer should fire, but you only want it to fire on a specific id, then you would use this
16151615
// sub_selector: "div.className", // if specified, we do a jquery element.find for the passed selector on the inserted element and ensure we can find a match
1616-
// handler: function( matchElement, callback ) {}, // if specified this handler is called if a match is found. Otherwise default calls the callback & passes the jQuery matchElement
1617-
// sub_observers: { }, // hash of event_name: config_hash"s - config hash supports all properties of this config hash. Observer will be bound as DOMNodeInserted to the matching class+sub_selector element.
1616+
// handler: function( matchElement, callback ) {} // if specified this handler is called if a match is found. Otherwise default calls the callback & passes the jQuery matchElement
16181617
// },
16191618
// TODO: current limitation allows only 1 action per watched className (i.e. each watched class must be
16201619
// unique). If this functionality is needed this can be worked around by pushing actions to an array
@@ -1747,9 +1746,8 @@ var Gmail = function(localJQuery) {
17471746
action - the name of the new DOM observer
17481747
className / args - for a simple observer, this arg can simply be the class on an inserted DOM element that identifies this event should be
17491748
triggered. For a more complicated observer, this can be an object containing properties for each of the supported DOM observer config arguments
1750-
parent - optional - if specified, this observer will be registered as a sub_observer for the specified parent
17511749
*/
1752-
api.observe.register = function(action, args, parent) {
1750+
api.observe.register = function(action, args) {
17531751

17541752
// check observers configured
17551753
if (api.tracker.dom_observer_init) {
@@ -1774,14 +1772,7 @@ var Gmail = function(localJQuery) {
17741772
config["class"] = args;
17751773
}
17761774
api.tracker.custom_supported_observers.push(action);
1777-
if (parent) {
1778-
if (!api.tracker.custom_dom_observers[parent]) {
1779-
api.tracker.custom_dom_observers[parent] = {sub_observers: {}};
1780-
}
1781-
api.tracker.custom_dom_observers[parent].sub_observers[action] = config;
1782-
} else {
1783-
api.tracker.custom_dom_observers[action] = config;
1784-
}
1775+
api.tracker.custom_dom_observers[action] = config;
17851776
};
17861777

17871778
/**
@@ -1906,22 +1897,6 @@ var Gmail = function(localJQuery) {
19061897
var handler = config.handler ? config.handler : function(match, callback) { callback(match); };
19071898
// console.log( "inserted DOM: class match in watchdog",observer,api.tracker.watchdog.dom[observer] );
19081899
api.observe.trigger_dom(observer, element, handler);
1909-
1910-
// if sub_observers are configured for this observer, bind a DOMNodeInsertion listener to this element & to check for specific elements being added to this particular element
1911-
if(config.sub_observers) {
1912-
1913-
// create observer_map for the sub_observers
1914-
var observer_map = {};
1915-
$.each(config.sub_observers, function(act,cfg){
1916-
observer_map[cfg.class] = act;
1917-
});
1918-
1919-
// this listener will check every element inserted into the DOM below the current element
1920-
// and repeat this method, but specifically below the current element rather than the global DOM
1921-
element.on("DOMNodeInserted", function(e) {
1922-
api.tools.insertion_observer(e.target, config.sub_observers, observer_map, "SUB ");
1923-
});
1924-
}
19251900
}
19261901
}
19271902
}

0 commit comments

Comments
 (0)