Skip to content

Commit

Permalink
Merge pull request #36 from jonataswalker/add-close-method
Browse files Browse the repository at this point in the history
Add API `close` method
  • Loading branch information
jonataswalker authored Jun 22, 2016
2 parents 128fc7a + 45688ff commit 8614c54
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ contextmenu.on('open', function(evt){

Remove all elements from the menu.

#### contextmenu.close()

Close the menu programmatically.

#### contextmenu.extend(arr)

`@param {Array} arr`
Expand Down
7 changes: 7 additions & 0 deletions src/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export default class Base extends ol.control.Control {
utils.removeAllChildren(this.container);
}

/**
* Close the menu programmatically.
*/
close() {
Base.Internal.closeMenu();
}

/**
* Enable menu
*/
Expand Down
2 changes: 1 addition & 1 deletion src/js/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class Internal {
});
}

closeMenu(){
closeMenu() {
utils.addClass(this.Base.container, vars.namespace + vars.hidden_class);
this.Base.dispatchEvent({
type: constants.eventType.CLOSE
Expand Down
40 changes: 39 additions & 1 deletion test/spec/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,46 @@ casper.test.begin('Assert DOM Elements', 3, function(test) {
elements.container + '>li', contextmenu.getDefaultItems().length);
});

casper.run(function() {
test.done();
});
});

casper.test.begin('Assert API Methods', 1, function(test) {

casper.start(config.url).waitFor(function() {
return casper.evaluate(function() {
return window.domready === true;
});
});

casper.thenEvaluate(function(options, map_id) {
var map = new ol.Map({
target: map_id,
layers: [],
view: new ol.View({
center: [0, 0],
zoom: 1
})
});

window.contextmenu = new ContextMenu(options);
map.addControl(contextmenu);
}, ctx_options, map_id);

casper.then(function() {
this.mouse.rightclick('#' + map_id);
});

casper.waitUntilVisible(elements.container, function() {
casper.evaluate(function() {
window.contextmenu.close();
});
});

casper.then(function() {
this.capture('map.png');
test.assertExists(
elements.container +'.'+ vars.namespace + vars.hidden_class);
});

casper.run(function() {
Expand Down

0 comments on commit 8614c54

Please sign in to comment.