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

Added resetPosition() to reposition clickover #11

Merged
merged 1 commit into from
Aug 23, 2012

Conversation

matthew-muscat
Copy link
Contributor

Needed this in one of my projects when retrieving clickover content via an ajax request.

While the clickover div grows, the positioning does not get updated. This function allows a simple call to resetPosition() to update the position of a clickover based on the content within it. It is based on the original positioning code found in bootstrap.

This is particularly more suitable to bootstrapx-clickover since we can use onShown events to easily fire ajax events on open (unlike the current bootstrap popover)

Added resetPosition() to handle instances (such as ajax loading) causing the clickover to grow in width/height
@lecar-red
Copy link
Owner

Thanks for the code, a quick question before i merge it in.

Can you give an example of usage? (code snippet)

Boy I wish we could ask bootstrap lib to do this instead of moving blocks of that code over but i don't see any that would allow us to reuse code from tooltip :(

@matthew-muscat
Copy link
Contributor Author

sure... heres a snippet/example of use

<a href="#" class="btn" rel="note_view" data-original-title="Notes" data-content="&lt;div class=&quot;progress progress-striped active&quot;&gt;&lt;div class=&quot;bar&quot; style=&quot;width: 100%;&quot;&gt;&lt;/div&gt;&lt;/div&gt;" data-contact-id="7727">12</a>
$('a[rel=note_view]').clickover({
    placement: 'left',
    onShown: function(){
        //save the clickover to call later...
        var clickover = this;

        //make an ajax request to load notes
        $.ajax({
            url: '/contact/note',
            data: {contact_id: clickover.options.contact_id},
            type: 'GET',
            dataType: 'json',
            success: function(response) {
                //fill in the notes in the clickover....
                $("div.clickover").find("div.popover-content").html(response);
                // reset clickover positioning
                clickover.resetPosition();
            }
        });
    }
});

certainly wish it would be possible to include repositioning directly within bootstrap, however without onShown events ajax loading isn't really possible

lecar-red added a commit that referenced this pull request Aug 23, 2012
Added resetPosition() to reposition clickover
@lecar-red lecar-red merged commit ff0555a into lecar-red:master Aug 23, 2012
@kjakub
Copy link

kjakub commented Mar 8, 2013

used this code snippet and just realized that i have to reference {contact_id: clickover.options.contactId} instead of {contact_id: clickover.options.contact_id}

@surrealroad
Copy link

I'm having trouble following this example. How does data-contact-id get passed to the ajax function?

@kjakub
Copy link

kjakub commented May 18, 2013

by reading element's data attribute and i think following applies in last code snippet: clickover.options.contactId == $('a[rel=note_view]').data("contact_id")

@matthew-muscat
Copy link
Contributor Author

hi @surrealroad - i've broken down the main three parts of this - hope this explains it for you...

in the clickover element, add the data attribute... eg:

<a href="#" rel="clickover" data-contact-id="123">James</a>

then while inside the clickover onshown event, reference 'this' clickover instance to a variable.

var clickover = this;

you can then use the variable to call on the data attribute, which clickover conveiniently makes available in it's options properties (dashes are represented as underscores at this point, however i think a version handles this in camelcase?)

clickover.options.contact_id

for the full example, you can look over my earlier post

@surrealroad
Copy link

Thanks for your help! There were a couple of things that were tripping me up, but it works now.
I also created a JSFiddle of this for future Googlers.

http://jsfiddle.net/surrealroad/8g3Qh/

@anujism
Copy link

anujism commented Feb 21, 2014

Can we use any other data than contact_id? I want to pass multiple data values in onShown function. How can that be done?

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

Successfully merging this pull request may close these issues.

None yet

5 participants