Skip to content

Instantly share code, notes, and snippets.

@crissmancd
Created December 5, 2013 22:20
Show Gist options
  • Save crissmancd/7815049 to your computer and use it in GitHub Desktop.
Save crissmancd/7815049 to your computer and use it in GitHub Desktop.
#= Trying to put the last condition into its own function
#= Leaving the "not" in the last condition in the list WORKS:
parentIsText = ->
$(target.parentNode).hasClass("cke_dialog_ui_input_text")
true if elementIsNotTarget and elementHasNoTarget and parentIsNotSelect and not parentIsText
#= Putting the "not" inside the last condition function DOES NOT WORK
parentIsNotText = ->
not $(target.parentNode).hasClass("cke_dialog_ui_input_text")
true if elementIsNotTarget and elementHasNoTarget and parentIsNotSelect and parentIsText
#= Why does moving the "not" to inside the function break it?
@jlsuttles
Copy link

Ran it through http://js2coffee.org

var parentIsNotText, parentIsText;

parentIsText = function() {
  return $(target.parentNode).hasClass("cke_dialog_ui_input_text");
};

if (elementIsNotTarget && elementHasNoTarget && parentIsNotSelect && !parentIsText) {
  true;
}

parentIsNotText = function() {
  return !$(target.parentNode).hasClass("cke_dialog_ui_input_text");
};

if (elementIsNotTarget && elementHasNoTarget && parentIsNotSelect && parentIsText) {
  true;
}

@crissmancd
Copy link
Author

I guess in the not working version I forgot to change the function name to parentIsNotText, but only in the gist

@crissmancd
Copy link
Author

Also, there is another almost identical function that does work:

parentIsNotSelect = ->
not $(target.parentNode).hasClass("cke_dialog_ui_input_select")

    parentIsNotText = ->
      not $(target.parentNode).hasClass("cke_dialog_ui_input_text")

    true  if elementIsNotTarget and elementHasNoTarget and parentIsNotSelect and parentIsNotText

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