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

refactored js to function as a jquery plugin #10

Merged
merged 2 commits into from Mar 14, 2014
Merged

Conversation

mejackreed
Copy link
Contributor

Resolves issue #2 by using jquery plugin architecture. Eliminates global variables.

<%= javascript_tag "$('#blacklight-map').blacklight_leaflet_map({geojson_docs: #{serialize_geojson}});" %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this just $('#blacklight-map').blacklight_leaflet_map(#{serialize_geojson)? I guess it means adding another argument to the function, but I think it's probably good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be, the reason I made it that way was so that you could pass options to it in two ways, data-attributes or through "$('#blacklight-map').blacklight_leaflet_map({options:{option1: 'mapstuff'},geojson_docs: #{serialize_geojson}}). This is a typical pattern with leaflet and I was trying to maintain some of that pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like passing options, but `blacklight_leaflet_map(geojson_docs, {option1: 'mapstuff'}) would work just as well, wouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. Will change to that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It has the added benefit that it's clear you MUST have a set of geojson docs, and that options are... optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, works with optional options now $('#blacklight-map').blacklight_leaflet_map(#{serialize_geojson}, {goodOption: 'foo'})

 requires geojson_docs, and allows for additional options
@mejackreed mejackreed modified the milestone: v0.0.2 Mar 13, 2014
@mejackreed
Copy link
Contributor Author

@cbeer, @jcoyne, @jkeck anything else here we need to address before merging? The app/helpers/blacklight_maps_helper.rb changes will be overwritten when #12 is merged.


// Move the map so that it centers the clicked cluster TODO account for various size screens
function offsetMap(e){
var mapWidth = $('#blacklight-map').width();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that it's a proper plugin, I don't think we need to hard-code #blacklight-map here. I can't remember, off-hand, if it is this here, or something else..\

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added issue #14

cbeer added a commit that referenced this pull request Mar 14, 2014
refactored js to function as a jquery plugin
@cbeer cbeer merged commit 457b0b7 into master Mar 14, 2014
@cbeer cbeer deleted the jqueryPluginRefactor branch March 14, 2014 03:04
@mejackreed
Copy link
Contributor Author

Closes #13 and #14

@mejackreed mejackreed added this to the v0.1.0 milestone Mar 20, 2014
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

2 participants