browser-component
v0.1.2
Published
Components for rendering browser style UIs.
Downloads
2
Readme
Browser-component
Browser component is a web component designed to get a browser into the browser itself. It can be used to extend a headless browser, or give some more features to a web application, such as firefox/xulrunner or chrome/chromium apps. This project comes with sub components, to let you customize the browser of your wish.
Overview
Get it directly by cloning this repository:
git clone https://github.com/jokesterfr/browser-component.git
Or use bower:
bower install browser-component
Import it in your page like so:
<link rel="import" href="./bower_components/browser-component/dist/browser-component.html" />
And use it:
<browser-component defaultPage="https://github.com">
<browser-tabbar>
<browser-tab url="https://www.laquadrature.net/en"></browser-tab>
<browser-tab url="http://lestrans.com"></browser-tab>
<browser-tab-new></browser-tab-new>
</browser-tabbar>
<browser-toolbar>
<browser-navigation></browser-navigation>
<browser-location></browser-location>
<browser-button type="home"></browser-button>
<browser-button type="zoom-in"></browser-button>
<browser-button type="zoom-out"></browser-button>
</browser-toolbar>
</browser-component>
Testing example
If you want to test this component in a chrome app context, simply type:
$ npm run example
Browser compatibility
As of today, web components are not natively supported by Firefox, Chrome and chromium support web components since version 35.
This browser-component
uses the chrome webview tag. A tweak could be made to use the equivalent XUL browser tag, to be supported by Firefox. Therefore, the lack of Web components support does not urge me to do so.
Components API
browser-component
<browser-component defaultPage="https://github.com">
<!-- y mucho mas aqui -->
</browser-component>
The browser component is the key element of this package. Its main role is to deal with multiple webviews, masking states that does not rely on the selected tab / webview.
Attributes
- defaultPage the default page to go when a tab with no url is opened, or when the home button is pressed. Defaults to null.
- controls when the value is "hidden", no controls will be displayed on screen, fullscreen browsing is activated. Defaults to "visible".
Methods
- go(uri) tells the current tab to go to this uri
- goHome() tells the current tab to go to the home page (@see defaultPage)
- zoomIn() zoom in the current tab
- zoomOut() zoom out the current tab
- stop() stop loading the current tab
- reload() reload the current tab
- back() tells the current tab to go back to last page in history
- forward() tells the current tab to go forward to the next page in history
- canGoBack() return true if the current tab can go back
- canGoForward() return true if the current tab can go forward
- showControls() displays the browser top controls
- hideControls() hides the browser top controls
browser-tabbar
The browser tabbar will display all tabs you filled in, you can use the selected attribute to choose the default tab to be selected (or the last one will be by default):
<browser-tabbar>
<browser-tab url="https://www.laquadrature.net/en"></browser-tab>
<browser-tab url="http://lestrans.com"></browser-tab>
<browser-tab-new></browser-tab-new>
</browser-tabbar>
There is no methods nor attributes to use with <browser-tabbar>
.
browser-tab
A nice favicon and title are automatically added there. The actual behaviour is that a single tab in the tabbar cannot be closed. Also, only active tabs can be closed.
Attributes
- url: URL of the content to browse
Methods
- select: selects this tab (to use the corresponding webview)
- close: closes the tab (and the corresponding webview)
browser-tab-new
<browser-tab-new></browser-tab-new>
Allows you to dynamically add some more tabs. To be placed right after the <browser-tab>
element(s).
browser-tab-separator
<browser-tab></browser-tab>
<browser-tab-separator></browser-tab-separator>
<browser-tab></browser-tab>
A graphical separation between tabs.
browser-toolbar
You may place buttons or location fields in it, feel free to suggest any other components you would like to use here.
<browser-toolbar>
<browser-navigation></browser-navigation>
<browser-location></browser-location>
<browser-button type="home"></browser-button>
<browser-button type="zoom-in"></browser-button>
<browser-button type="zoom-out"></browser-button>
</browser-toolbar>
browser-button
<browser-button type="zoom-in"></browser-button>
A simple button, customizable with any icon of your wish:
- back
- bookmark
- download
- feed
- forward
- history
- home
- menu
- new-window
- reload
- zoom-in
- zoom-out
- zoom
Feel free to PR a new one.
Actions are triggered by the <browser-button>
parent.
browser-navigation
<browser-navigation></browser-navigation>
This component is made of a back button and a forward button. The forward button disappear when there is no next page in the browsing history. States are related to current tab. Simple.
browser-location
<browser-location></browser-location>
The input which let you choose how to browse the web! Comes with a go/reload button on its right.
Licence
This work is largely inspired by Firefox Australis UI, therefore the same licence applies here: