Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Added initial leaflet plugin main file.
Browse files Browse the repository at this point in the history
Currently encountering trouble with jquery prettyCheckables
Not all clicks on the visual input form does not seem to be triggering the html input form click.
as detailed in :
Simulate click() for jQuery Validation
arthurgouveia/prettyCheckable#49
My current solution so far is to get the parent div and listen to all the clicks on that parents and its children. ongoing..
  development #2
  * Create Initial Prototype
  • Loading branch information
chriscalip committed Mar 4, 2014
1 parent 3fc21d8 commit 1bab17f
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/PrettyCheckableLayers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Created: chriscalip Date: 02/26/14 Time: 3:20 PM
*/

L.Control.PrettyCheckableLayers = L.Control.Layers.extend({

onAdd: function (map) {
var container = L.Control.Layers.prototype.onAdd.call(this, map);
return container;
},

_addItem: function (obj) {
var label = document.createElement('label'),
checked = this._map.hasLayer(obj.layer),
input;

if (obj.overlay) {
input = document.createElement('input');
input.type = 'checkbox';
input.className = 'leaflet-control-layers-selector';
input.defaultChecked = checked;
input.setAttribute('data-label', obj.name);
input.setAttribute('data-color', 'red');
} else {
input = this._createRadioElement('leaflet-base-layers', checked);
}

input.layerId = L.stamp(obj.layer);

// start pcc specific
input.id = 'pcc-' + input.layerId;
// end pcc specific

L.DomEvent.on(input, 'click', this._onInputClick, this);

// var name = document.createElement('span');
// name.innerHTML = ' ' + obj.name;

label.appendChild(input);
// label.appendChild(name);

var container = obj.overlay ? this._overlaysList : this._baseLayersList;
container.appendChild(label);

return label;
},

renderPrettyCheckable: function () {
jQuery.each( this._form, function( key, form ) {
jQuery(form).prettyCheckable();
var newContainer = jQuery(form).parent();
newContainer.on('click', '*', function (event) {
jQuery(this).siblings(':input').click();
});
});
},

})

L.control.prettyCheckableLayers = function (baseLayers, overlays, options) {
return new L.Control.PrettyCheckableLayers(baseLayers, overlays, options)
}

0 comments on commit 1bab17f

Please sign in to comment.