-
Notifications
You must be signed in to change notification settings - Fork 4
Popups
In OGX.JS, Popups are floating boxes with a view in them, they can be draggable, have and icon and buttons. A popup is what would be commonly called in an operating system environment, a window.
Popups are parts of the core, have a size and a view. For the following documentation consider app being an instance of Core.
let config = {
name:_STRING_, //Required, must be unique
width:_NUMBER_|_STRING_, //Required, either a number (for pixels) or a percentage
height:_NUMBER_|_STRING_, //Required, either a number (for pixels) or a percentage
title:_STRING_, //Optional, the title of the popup,
buttons:_ARRAY_, //Optional, an array of strings or objects
scroller:_BOOL_, //Optional, if the popup contains a scroller
html:_STRING_, //Optional, some HTML content to add to the body of the popup
template:_STRINT_, //Optional, HTML content coming from a template stored in Templater
anim:_STRING_, //Optional, defaults to OGX.MobileCore.POPUP_FADE
overlay:_BOOL_, //Optional, add an overlay, defaults to FALSE
listen_overlay:_BOOLEAN_, //Optional, defaults to false, if the core should listen for clicks on the overlay and hide it
zindex:_INT_ //Optional, the z-index of the popup,
css:_STRING_ //Optional, an css class to be added to the body of the popup,
view:_OBJECT_, //Optional, a view configuration object
};
app.addPopup(config);
Example - Create a simple popup of 400px x 300px with custom HTML in it
app.addPopup({
name:'MyPopup',
width:400,
height:300,
anim:OGX.Popup.POPUP_FADE,
listen_overlay:false,
html:'<p>Some HTML content</p>'
});
Example - Create a simple popup of 400px x 300px with a HTML template, and an overlay
app.addPopup({
name:'MyPopup',
width:400,
height:300,
anim:OGX.Popup.POPUP_FADE,
overlay:true,
listen_overlay:false,
template:'MyPopupTemplate'
});
Example - Create a popup of 400x300px, pass it a view 'MyView', with an empty object, a fade animation and ignore user interactions on the underlying overlay (tapping the overlay won't do anything).
app.addPopup({
name:'MyPopup',
width:400,
height:300,
anim:OGX.Popup.POPUP_FADE,
listen_overlay:false,
view:{view:'MyView', scroll:false, observe:false},
});
Same but with percent instead
app.addPopup({
name:'MyPopup',
width:'80%',
height:'80%',
anim:OGX.App.POPUP_FADE,
listen_overlay:false,
view:{view:'MyView', scroll:false, observe:false},
});
It is important to remember that HTML content can be injected either at popup level or view level, same remark for scrollers. In the following example, the HTML content and the scroller are at view level inside a popup
app.addPopup({
name:'MyPopup',
width:'80%',
height:'80%',
anim:OGX.App.POPUP_FADE,
listen_overlay:false,
view:{view:'MyView', template:'SomeTemplate', scroll:true, observe:false},
});
But we could also have used the built in scroller and have the template at popup level, it all depends on how your view is architeched.
app.addPopup({
name:'MyPopup',
width:'80%',
height:'80%',
anim:OGX.App.POPUP_FADE,
listen_overlay:false,
template:'SomeTemplate',
scroll:true,
view:{view:'MyView', scroll:false, observe:false},
});
Note that using scrollers at view level is only useful when you have multiple views in the same popup. Otherwise, if your popup only contains 1 view then you should use the popup scroller instead.
You can add buttons to your popup either by passing an array of strings (labels of buttons) or an array of objects. If you use strings, you will need to listen to the events of the popup, such as
app.addPopup({
...
buttons:['OK', 'Cancel']
});
$(document).on(OGX.Popup.CLICK_BUTTON, function(__event, __data){
console.log(__data); //logs {index:_INT_, value:_STRING} where index is the button index and value its label
});
If you'd rather not listen to events and have a callback called when the button is hit instead, do
app.addPopup({
...
buttons:[{label:'OK', callback:myFunction}, {label:'Cancel', callback:otherFunction}]
});
function myFunction(){ ... }
function otherFunction(){ ... }
To add a view to a popup
app.addToPopup(
{
name: _POPUP_NAME, //Required, String, name of the popup
view: _VIEW_, //Required, String, name of the view, i.e. OGX.Views.Test = 'Test'
data: _OBJECT_, //Object, the data object for the view, optional
container: _SELECTOR_ //String, optional. The container where the view is going to be append to, i.e. '#mydiv'. Defaults to '.ogx_popup_body:first'
}
);
If the container is not set, the default view for the popup will be used. But if your popup was instantiated with HTML content, and you wish to create a view inside the HTML element (corresponding to the selector '.my_selector'), do
app.addToPopup(
{
name:'MyPopup',
view: 'MyView',
container:'.my_selector'
}
);
To remove a view from a popup
app.removeFromPopup(_POPUP_NAME_, _SELECTOR_);
For instance, remove the view that was instanced in the popup at the default container
app.removeFromPopup('MyPopup');
To remove a specific view in a specific container
app.removeFromPopup('MyPopup', '.my_selector');
app.removePopup(_NAME_, _ANIMATION_);
Deleting a popup will also call the destroy method of any view embedded inside the popup.
- Welcome
- Changelog
- Structure
- Configuration
- Getting started
- CLI
- Poly
- Core
- Templating
- Routing
- Controllers
- Components
- Extra Components
- Helpers
- Styling
- Debugging