angular-off-click icon indicating copy to clipboard operation
angular-off-click copied to clipboard

Issue with off-click-filter (again, I know)

Open ghost opened this issue 8 years ago • 1 comments

Hey,

Thanks for this directive, it is very handy. Although I have an issue with the off-click-filter :

This is my element that contain an ng-repeat of item (it's a popup menu) : <div id="fs-create-menu" off-click="fs.closePanel()" off-click-filter="'#fs-file-creator-launcher'"></div>

Which open using a button like : <button id="fs-file-creator-launcher"><span>Some text</span></button>

Just for matter of testing as you can see, I have set the id of the button in the off-click-filter, so it shouldn't trigger the off-click if I click on the button.

But then it does.

I debugged your source code and tried to understand what went wrong, I can see my filter properly store in the OffClickFilterCache as an object :

{ "#fs-file-creator-launcher": [ { "jQuery224087994817664495642": { "$appsMenuController": {} }, "$$hashKey": "object:856", "$$ngAnimateParentKey": 1 } ] }

So far so good.

And then I come across here https://github.com/TheSharpieOne/angular-off-click/blob/master/dist/angular-off-click.js#L50

What does OffClickFilterCache['*'] should return you ? Because in my case it's undefined. I assume it should return the list of filter passed to off-click-filter, but here I have nothing.. As you could guess, the filters var is [].

Is there something wrong with my logic ? or is there something wrong with the package ?

Also another thing is that you only compare the target element, but then if you want to filter an entire DOM element, you would need to filter ALL the ids and class ?

ghost avatar Dec 06 '16 15:12 ghost

'*' is a special case; filter everything. The line you reference with OffClickFilterCache['*'] || []is basically saying to get the list of things that filter everything. You would use off-click-filter="'*'" when you want that element to never trigger any off-click. The issue here is that in the last major version change (the v1.0.0 release, see the notes) the way off-click-filter works was flipped. Instead of adding it to the thing with off-click and indicating all of the elements you want to be filtered, now you add to to the elements you want to be filtered and indicate which off-click you want them to be filtered from.

Programmatically this was more efficient; allowing for better performance.

In you case, I believe what you are wanting is:

<div id="fs-create-menu" off-click="fs.closePanel()"></div>

with

<button id="fs-file-creator-launcher" off-click-filter="'#fs-create-menu'"><span>Some text</span></button>

Give that a try and let me know.

TheSharpieOne avatar Dec 06 '16 18:12 TheSharpieOne