Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose function #72

Closed
joostliketoast opened this issue Jun 26, 2015 · 7 comments
Closed

expose function #72

joostliketoast opened this issue Jun 26, 2015 · 7 comments

Comments

@joostliketoast
Copy link

i tried using the qtip2 plugin for jquery, the function works with expose but it doesn't seem to take the parameters set in opal. using the x-string option works fine.

Any ideas why? did i implement it incorrectly?

  Element.expose :qtip

    @el = Element.find selector
    @tooltips = []
    @el.each do |tooltip|
      @tooltips.push tooltip
      %x{
        $(#{tooltip.get}).qtip({
          show: 'click',
          hide: 'unfocus',
          content: {
              title: {
                text: $(#{tooltip.get}).attr('title'),
                button: true
              },
              text: $(#{tooltip.get}).next('div') // Use the "div" element next to this for the content
          },
          position: {
            my: 'top left',  // Position my top left...
            at: 'bottom right', // at the bottom right of...
            target: $(#{tooltip.get}) // my target
          },
          style: {
              classes: 'qtip-bootstrap'
          }
        });
      }
      ## SEEMS BROKEN FOR NOW
      # tooltip.qtip(
      #   show: 'click',
      #   hide: 'unfocus',
      #   content: {
      #     title: {
      #       text: tooltip.attr('title'),
      #       button: true
      #     },
      #     text: tooltip.next('div') # Use the "div" element next to this for the content
      #   },
      #   position: {
      #     my: 'top left', # Position my top left...
      #     at: 'bottom right', # at the bottom right of...
      #     target: tooltip # my target
      #   },
      #   style: {
      #     classes: 'qtip-bootstrap'
      #   }
      # )
  end
@elia
Copy link
Member

elia commented Jun 26, 2015

Does it work when you "expose" in another file?

If the answer is yes then it's known bug for which we should have an issue open in opal/opal.

@joostliketoast
Copy link
Author

i just tried it with putting 'expose' in the file that loads in the module. sadly same result

@elia
Copy link
Member

elia commented Jun 29, 2015

@joostliketoast oh I see, I skimmed through the issue description initially and missed the fact that the problem is just with params.

.expose passes on the params as the are, so you're passing a ruby/opal Hash instance instead of a bare JS object. This should work:

require 'native'

tooltip.qtip({
  show: 'click',
  hide: 'unfocus',
  content: {
    title: {
      text: tooltip.attr('title'),
      button: true
    },
    text: tooltip.next('div') # Use the "div" element next to this for the content
  },
  position: {
    my: 'top left', # Position my top left...
    at: 'bottom right', # at the bottom right of...
    target: tooltip # my target
  },
  style: {
    classes: 'qtip-bootstrap'
  }
}.to_n)

@joostliketoast
Copy link
Author

ah thanks that worked! :)
good to know that expose uses plain js parameters instead of opal

@elia
Copy link
Member

elia commented Jun 30, 2015

Great! @joostliketoast would you mind doing a PR to update the README?

@joostliketoast
Copy link
Author

no problem i will send a PR

@elia elia closed this as completed Jun 30, 2015
@elia
Copy link
Member

elia commented Jun 30, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants