FireFox Extension XulSchool - Adding Events and Commands - on load function - firefox-addon

I'm trying to edit the helloworld from this tutorial:
https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School/Getting_Started_with_Firefox_Extensions
So, I need to execute a function when page loads, this part of the tutorial explains how to do that:
https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School/Adding_Events_and_Commands
I edited the browserOverlay.js file, I writed the init function and that listener at the end of the code:
/**
* XULSchoolChrome namespace.
*/
if ("undefined" == typeof(XULSchoolChrome)) {
var XULSchoolChrome = {};
};
/**
* Controls the browser overlay for the Hello World extension.
*/
XULSchoolChrome.BrowserOverlay = {
init : function(event) {
window.alert('aaaaeeee');
},
/**
* Says 'Hello' to the user.
*/
sayHello : function(aEvent) {
let stringBundle = document.getElementById("xulschoolhello-string-bundle");
let message = stringBundle.getString("xulschoolhello.greeting.label");
window.alert(message);
}
};
window.addEventListener("load", function() {
//window.removeEventListener("load", onFirefoxLoadEvent, false); // remove listener, no longer needed
XULSchoolChrome.BrowserOverlay.init();
}, false);
and I edited the broserOverlay.xul, I writed the onload propertie at overlay tag:
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin/" ?>
<?xml-stylesheet type="text/css"
href="chrome://xulschoolhello/skin/browserOverlay.css" ?>
<!DOCTYPE overlay SYSTEM
"chrome://xulschoolhello/locale/browserOverlay.dtd">
<overlay id="xulschoolhello-browser-overlay"
onload="XulSchoolChrome.BrowserOverlay.init();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"
src="chrome://xulschoolhello/content/browserOverlay.js" />
<stringbundleset id="stringbundleset">
<stringbundle id="xulschoolhello-string-bundle"
src="chrome://xulschoolhello/locale/browserOverlay.properties" />
</stringbundleset>
<menubar id="main-menubar">
<menu id="xulschoolhello-hello-menu" label="&xulschoolhello.hello.label;"
accesskey="&xulschoolhello.helloMenu.accesskey;" insertafter="helpMenu">
<menupopup>
<menuitem id="xulschoolhello-hello-menu-item"
label="&xulschoolhello.hello.label;"
accesskey="&xulschoolhello.helloItem.accesskey;"
oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
</menupopup>
</menu>
</menubar>
<vbox id="appmenuSecondaryPane">
<menu id="xulschoolhello-hello-menu-2" label="&xulschoolhello.hello.label;"
accesskey="&xulschoolhello.helloMenu.accesskey;"
insertafter="appmenu_addons">
<menupopup>
<menuitem id="xulschoolhello-hello-menu-item-2"
label="&xulschoolhello.hello.label;"
accesskey="&xulschoolhello.helloItem.accesskey;"
oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
</menupopup>
</menu>
</vbox>
</overlay>
It does not alert on page loads.... why?

Related

ui5 sap.m.table dynamic binding using ODataModel

I have a struggling with my table and it's data, let me give you some context info, I'm using the version 1.72.3, my app is a standalone app hosted in a Nginx, all proxies are in place and working fine.
I have a View like a worklist (a view with one table) and I need to query the back-end using filters but JSONModel not allow it so my idea was simple
I create a propetry in JSONModel called "salesOrders"
using the event attachPatternMatched I call the back-end using oDataModel
I set the property "salesOrders" with the result of oDataModel's call
I bind my table to the property
I place all the code but my best result on screen was
This is the definition of my table in the view.
<Table noDataText="Drop column list items here and columns in the area above" items="{salesOrderListView>/salesOrders}"
id="tableSalesOrders" growingScrollToLoad="true" sticky="ColumnHeaders" growing="true">
<items>
<ColumnListItem type="Navigation" id="item0" press="onPressSalesOrder">
<cells>
<ObjectIdentifier xmlns="sap.m" title="{ path: 'Vbeln', formatter: '.formatter.numberNoZeros' }" titleActive="fasle" id="identifier0"/>
<Link xmlns="sap.m" text="{Customer/Name1}" id="link0" press="onPressCustomer"/>
<Link xmlns="sap.m" text="{Vendor/Ename}" id="link1" press="onPressVendor"/>
<core:Icon src="sap-icon://flag" size="2em" id="icon0" color="{ path: 'Lsstk', formatter: '.formatter.flagStatusColorC' }"/>
<core:Icon xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:core="sap.ui.core"
src="sap-icon://flag" size="2em" id="icon0_copy2" color="{ path: 'Cmgst', formatter: '.formatter.flagStatusColorCred' }"/>
<core:Icon xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:core="sap.ui.core"
src="sap-icon://flag" size="2em" id="icon0_copy" color="{ path: 'Lfstk', formatter: '.formatter.flagStatusColor' }"/>
<Text xmlns="sap.m" text="{Vdatu}" id="text1"/>
<ObjectNumber xmlns="sap.m" number="{ path: 'Kwmeng', formatter: '.formatter.numberNoDecimals' }" unit="CJ" id="number0" textAlign="Center"/>
<ObjectNumber xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m"
number="{ path: 'Kwmengdlvy', formatter: '.formatter.numberNoDecimals' }" unit="CJ" id="number0_copy2" textAlign="Center"/>
<ObjectNumber xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m"
number="{ path: 'Kwmengdiff', formatter: '.formatter.numberNoDecimals' }" unit="CJ" id="number0_copy" textAlign="Center"/></cells>
</ColumnListItem>
</items>
<columns>
<Column id="column0">
<header>
<Label text="{i18n>vbelnLabel}" id="label0"/>
</header>
</Column>
<Column id="column1" minScreenWidth="Large" demandPopin="true" popinDisplay="Inline">
<header>
<Label text="{i18n>customerName1Label}" id="label1"/>
</header>
</Column>
<Column id="column2" minScreenWidth="Large" demandPopin="true" popinDisplay="Inline" popinHAlign="Left">
<header>
<Label text="{i18n>vendorEnameLabel}" id="label2"/>
</header>
</Column>
<Column xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m" id="column2_copy6"
demandPopin="true">
<header>
<Label text="Aprobación Comercial" id="label2_copy6" wrapping="true"/>
</header>
</Column>
<Column xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m" id="column2_copy5"
demandPopin="true">
<header>
<Label text="Aprobación Crediticia" id="label2_copy5" wrapping="true"/>
</header>
</Column>
<Column xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m" id="column2_copy4"
demandPopin="true">
<header>
<Label text="Expedición" id="label2_copy4"/>
</header>
</Column>
<Column xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m" id="column2_copy2">
<header>
<Label text="{i18n>vdatuLabel}" id="label2_copy2" wrapping="true"/>
</header>
</Column>
<Column xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m" id="column2_copy"
minScreenWidth="Large" demandPopin="true" popinDisplay="Inline">
<header>
<Label text="{i18n>kwmengLabel}" id="label2_copy" wrapping="true"/>
</header>
</Column>
<Column xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m" id="column2_copy7"
demandPopin="true" minScreenWidth="Large" popinDisplay="Inline">
<header>
<Label text="{i18n>kwmengDlvyLabel}" id="label2_copy7" wrapping="true"/>
</header>
</Column>
<Column xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="sap.m" id="column2_copy3">
<header>
<Label text="{i18n>kwmengDiffLabel}" id="label2_copy3" wrapping="true"/>
</header>
</Column>
</columns>
<headerToolbar>
<Toolbar width="100%" id="toolbar1">
<content>
<Title id="SalesOrderListHeader" text="{salesOrderView>/salesOrderTableTitle}"/>
<ToolbarSpacer/>
<SearchField id="searchField" tooltip="{i18n>salesOrderSearchTooltip}" search="onSearch" width="auto"/>
</content>
</Toolbar>
</headerToolbar>
</Table>
An in my controller I have this
sap.ui.define([
// "sap/ui/core/mvc/Controller",
"riders/polux/controller/BaseController",
"sap/ui/model/json/JSONModel",
"sap/ui/core/routing/History",
"riders/polux/model/formatter"
], function (BaseController, JSONModel, History, formatter) {
"use strict";
return BaseController.extend("riders.polux.controller.SalesOrderList", {
formatter: formatter,
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* #memberOf riders.polux.view.SalesOrderList
*/
onInit: function () {
var headerTitle, oViewModel, iOriginalBusyDelay, oTable = this.byId("tableSalesOrders");
// Put down salesOrderList table's original value for busy indicator delay,
// so it can be restored later on. Busy handling on the table is
// taken care of by the table itself.
iOriginalBusyDelay = oTable.getBusyIndicatorDelay();
// Model used to manipulate control states
oViewModel = new JSONModel({
headerTitle: headerTitle,
queryMode: "", //queryMode,
tableBusyDelay: 0,
salesOrders: null
});
this.getRouter().getRoute("SalesOrderList").attachPatternMatched(this._onObjectMatched, this);
this.setModel(oViewModel, "salesOrderListView");
// Make sure, busy indication is showing immediately so there is no
// break after the busy indication for loading the view's meta data is
// ended (see promise 'oWhenMetadataIsLoaded' in AppController)
oTable.attachEventOnce("updateFinished", function () {
// Restore original busy indicator delay for salesOrderList's table
oViewModel.setProperty("/tableBusyDelay", iOriginalBusyDelay);
});
// Add the page to the flp routing history
},
_onObjectMatched: function (oEvent) {
var oViewModel = this.getModel("salesOrderListView");
var oTable = this.getView().byId("tableSalesOrders");
var headerTitle, oResourceBundle = this.getResourceBundle();
var queryMode = oEvent.getParameter("arguments").queryMode;
switch (queryMode) {
case "P":
headerTitle = oResourceBundle.getText("salesOrderListViewTitleP");
break;
case "H":
headerTitle = oResourceBundle.getText("salesOrderListViewTitleH");
break;
}
oViewModel.setProperty("/headerTitle", headerTitle);
this.addHistoryEntry({
title: headerTitle,
icon: "sap-icon://table-view",
intent: "#PortalPollux-display&/SalesOrderList/" + queryMode
}, true);
var salesOrders = oViewModel.getProperty("/salesOrders");
if (!salesOrders) {
var odata = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/ZPOLLUX_SRV/");
odata.read("/SalesOrderSet", {
success: function (oData, response) {
oViewModel.setData({
salesOrders: oData
}, true);
}
});
}
},
/*
*#memberOf riders.polux.controller.SalesOrderList
*/
onGoBack: function (oEvent) {
//This code was generated by the layout editor.
var oHistory = History.getInstance();
var sPreviousHash = oHistory.getPreviousHash();
// Go one screen back if you find a Hash
if (sPreviousHash !== undefined) {
window.history.go(-1);
}
// If you do not find a correct Hash, go to the Source screen using default router;
else {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("TargetLaunchpad", true);
}
},
onPressCustomer: function (oEvent) {
// The source is the list item that got pressed - custom
this._showObjectCustomer(oEvent.getSource());
},
onPressVendor: function (oEvent) {
// The source is the list item that got pressed - custom
this._showObjectVendor(oEvent.getSource());
},
onPressSalesOrder: function (oEvent) {
// The source is the list item that got pressed - custom
this._showObjectSalesOrder(oEvent.getSource());
},
_showObjectCustomer: function (oItem) {
this.getRouter().navTo("customer", {
objectId: oItem.getBindingContext().getProperty("Kunnr")
});
},
_showObjectVendor: function (oItem) {
this.getRouter().navTo("vendor", {
objectId: oItem.getBindingContext().getProperty("Pernr")
});
},
_showObjectSalesOrder: function (oItem) {
this.getRouter().navTo("RouteSalesOrder", {
objectId: oItem.getBindingContext().getProperty("Vbeln")
});
}
});
});
I'm fighting with this for two days and I can figure out where is my error.
Can somebody help me, please?
Best Regards and Thank you in advance
From my experience using a JSONModel as solution will introduce other problems:
- you only filter the datasets you fetched. But its likely you don't load them all
- no automatic loading indication, no error handling while loading
- complicated coding for operations on loaded datasets
My solution would be to grab the table binding and apply filters in the controller. However this can not be done in the init() function, since no table binding is set up. I usually use a navigation event that may carries a query parameter from the url that must be applied to the filters as well.
onInit: function() {
...
this.getRouter().getRoute("master").attachPatternMatched(this._onMasterMatched, this);
...
}
_onMasterMatched: function() {
var oList = this.byId("myTable");
oList.getBinding("items").filter(new Filter(...));
}
You bound your items property to the path salesOrderListView>/salesOrders, so you are using named model with the name salesOrderListView. At the same time your field binding path looks like Customer/Name1 and it actually point to an unnamed model. In your case it has to be like salesOrderListView>Customer/Name1
When you call odata.read you directly set the JSON model data by this:
oViewModel.setData({
salesOrders: oData
}, true);
but if you look at oData variable during debugging you will see that most probably it is not an array, it's an object with structure:
{ d: { results: [.....] } }
So, I would try to assign data to the model this way:
oViewModel.setData({
salesOrders: oData.d.results
}, true);

English font working but non-English (Hindi) font not displaying in webview

An English font is working in HTML in webview, but the non-English font (Hindi) is not displaying in HTML in webview.
Here is my source code.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.wptrafficanalyzer.webviewcustomfont"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="in.wptrafficanalyzer.webviewcustomfont.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
demo.html
<html>
<head>
<meta http-equiv="content-type" content="text/html;" charset="UTF-8">
<style>
/** Specify a font named "MyFont",
and specify the URL where it can be found: */
#font-face {
font-family: "MyFont";
src: url('file:///android_asset/fonts/BLKCHCRY.TTF');
}
h2 { font-family:"MyFont"}
#font-face {
font-family: "MyFontSD";
src: url('file:///android_asset/fonts/SHREE-DEV7-1076H.TTF');
}
h1 { font-family:"MyFontSD"}
</style>
</head>
<body>
<h2>
Welcome to BLACK CHANCERY FONT
</h2>
<h1>
1234567890
Am{X
</h1>
</body>
</html>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/hello_world" />
</RelativeLayout>
MainActivity.java
package in.wptrafficanalyzer.webviewcustomfont;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Getting reference to WebView of the activity_main layout
mWebView = (WebView) findViewById(R.id.webview);
// Loading an HTML page into webview
mWebView.loadUrl("file:///android_asset/demo.html");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Note:
HTML file demo.html is copied in the assets folder
BLKCHCRY.TTF font file is copied in fonts folder
SHREE-DEV7-1076H.TTF font file is copied in fonts folder
Link to download fonts (SHREE-DEV7-1076H.TTF and BLKCHCRY.TTF)

Create a simplified reflective custom shader in A-FRAME

So I have inevitably gone down the path of custom shaders in A-FRAME. When really researching this, and given I could be considered a newbie with this tech, I have bumped into all sorts of complicated and not-so clear solutions.
Examples like: https://rawgit.com/mrdoob/three.js/master/examples/webgl_materials_cubemap_balls_reflection.html , create even more questions than answers.
However, when I visited this example: https://stemkoski.github.io/Three.js/Reflection.html , I did notice a different approach which seemed a bit more simplified.
This lead me to research more about CubeCameras and how threejs can use it as a shader in order to simulate reflectivity.
//Create cube camera
var cubeCamera = new THREE.CubeCamera( 1, 100000, 128 );
scene.add( cubeCamera );
//Create car
var chromeMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: cubeCamera.renderTarget } );
var car = new Mesh( carGeometry, chromeMaterial );
scene.add( car );
//Update the render target cube
car.setVisible( false );
cubeCamera.position.copy( car.position );
cubeCamera.updateCubeMap( renderer, scene );
//Render the scene
car.setVisible( true );
renderer.render( scene, camera );
Now the question is, how can I translate that into A-FRAME? I tried the following:
AFRAME.registerComponent('chromeThing', {
schema: {
???
},
init: function () {
var el = this.el; // Entity.
var cubeCam = document.querySelector('#cubeCam'); //There is an <a-entity camera id="cubeCam">
var mirrorCubeMaterial = new THREE.MeshBasicMaterial( { envMap: cubeCam.renderTarget } );
mirrorCube = new THREE.Mesh( el, mirrorCubeMaterial );
el.setObject3D('mesh', mirrorCube);
}
});
As you might notice, I'm not sure what the scheme of this would be.
Also, should this be a shader or a component? (how could I use this best)
EDIT:
After #ngokevin reply, I've come up with this code which is still not giving me the desired results.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chrome box</title>
<meta name="description" content="Physically-Based Materials - A-Frame">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
<script src="https://rawgit.com/ngokevin/kframe/master/dist/kframe.min.js"></script>
<script src="https://rawgit.com/ngokevin/kframe/master/components/reverse-look-controls/index.js"></script>
</head>
<body>
<a-scene>
<a-assets>
<img id="equi1" crossorigin src="https://rawgit.com/aframevr/aframe/master/examples/boilerplate/panorama/puydesancy.jpg" preload="auto">
</a-assets>
<!-- MAIN CAMERA -->
<a-entity id="mainCam" camera="userHeight: 1.6" reverse-look-controls wasd-controls></a-entity>
<!-- CMAERA FOR TEXTURE (?) -->
<a-entity id="cubecamera" camera near="0.1" far="5000" fov="512"></a-entity>
<!-- SKY DOME TO REFLECT ON BOX -->
<a-sky src="#equi1"></sky>
<!-- MAKE THIS BOX CHROME -->
<a-box id="theCube" camera-envmap-material="#cubecamera" color="tomato" depth="2" height="4" width="5" position="0 0 -3" materials=""></a-box>
<!-- THIS BOX IS MOVING AND SHOULD REFLECT ON THE CHROME BOX -->
<a-box id="reflector" color="red" position="0 0 20">
<a-animation attribute="rotation" dur="10000" fill="forwards" to="0 360 0" repeat="indefinite"></a-animation>
</a-box>
</a-scene>
</body>
<script>
AFRAME.registerComponent('camera-envmap-material', {
dependencies: ['material'],
// Selector type so we do `<a-entity camera-envmap-material="#cubecamera">`.
schema: {
type: 'selector'
},
init: function () {
var cameraEl = this.data;
var material = this.el.getObject3D('mesh').material;
// Set envmap on existing material.
// This assumes you have a CubeCamera component that does `setObject3D('cube-camera', new THREE.CubeCamera)`.
material.envMap = cameraEl.getObject3D('camera').renderTarget;
material.needsUpdate = true;
}
});
</script>
</html>
UPDATE #2
After recommendations from #ngokevin here is where I'm at, however, I can't get component to update. The problem seems to be the passing of variables to the tick:function(), I keep getting Uncaught TypeError: Cannot read property 'renderTarget' of undefined
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chrome box</title>
<meta name="description" content="Physically-Based Materials - A-Frame">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
<script src="https://rawgit.com/ngokevin/kframe/master/dist/kframe.min.js"></script>
<script src="https://rawgit.com/ngokevin/kframe/master/components/reverse-look-controls/index.js"></script>
</head>
<body>
<a-scene>
<a-assets>
<img id="equi1" crossorigin src="https://rawgit.com/aframevr/aframe/master/examples/boilerplate/panorama/puydesancy.jpg" preload="auto">
</a-assets>
<!-- MAIN CAMERA -->
<a-entity id="mainCam" camera="userHeight: 1.6" reverse-look-controls wasd-controls></a-entity>
<!-- SKY DOME TO REFLECT ON BOX -->
<a-sky src="#equi1"></sky>
<!-- MAKE THIS BOX CHROME -->
<a-box id="theCube" camera-envmap-material depth="2" height="4" width="5" position="0 0 -3" metalness="1">
</a-box>
<!-- MAKE THIS ROTATE AND REFLECT ON CHROME -->
<a-box id="reflector" color="red" position="0 0 10">
<a-animation attribute="rotation" dur="10000" fill="forwards" to="0 360 0" repeat="indefinite"></a-animation>
</a-box>
</a-scene>
</body>
<script>
AFRAME.registerComponent('camera-envmap-material', {
dependencies: ['material'],
init: function(data) {
this.cameraEl = this.data;
this.material = this.el.getObject3D('mesh').material;
this.theElement = this.el;
this.theScene = this.theElement.sceneEl;
if (!this.theScene.renderStarted) {
this.theScene.addEventListener('renderstart', this.init.bind(this));
return;
}
this.cubeCamera = new THREE.CubeCamera( 0.1, 5000, 512);
this.cubeCamera.position.set(5, 2, 4);
this.cubeCamera.updateCubeMap( this.theScene.renderer, this.theScene.object3D );
this.theElement.setObject3D('cube-camera', this.cubeCamera);
this.material.envMap = this.cubeCamera.renderTarget;
this.material.needsUpdate = true;
},
tick:function(){
this.material.envMap = this.cubeCamera.renderTarget;
this.material.needsUpdate = true;
}
});
</script>
</html>
A component would be okay to set properties on an existing material. A shader is more for registering shaders/materials, but A-Frame already has basic/standard materials. And you want the selector property in the schema.:
AFRAME.registerComponent('camera-envmap-material', {
dependencies: ['material'],
// Selector type so we do `<a-entity camera-envmap-material="#cubecamera">`.
schema: {
type: 'selector'
},
init: function () {
var cameraEl = this.data;
var material = this.el.getObject3D('mesh').material;
// Set envmap on existing material.
// This assumes you have a CubeCamera component that does `setObject3D('cube-camera', new THREE.CubeCamera)`.
material.envMap = cameraEl.getObject3D('camera').renderTarget;
material.needsUpdate = true;
}
});
Update
AFRAME.registerComponent('camera-envmap-material', {
dependencies: ['material'],
init: function () {
var cameraEl = this.data;
var material = this.el.getObject3D('mesh').material;
if (!this.el.sceneEl.renderStarted) {
this.el.sceneEl.addEventListener('renderstart', this.init.bind(this));
return;
}
var cubeCamera = new THREE.CubeCamera( 1, 100000, 128 );
cubeCamera.position.set(5, 2, 4);
cubeCamera.updateCubeMap( this.el.sceneEl.renderer, this.el.sceneEl.object3D );
this.el.setObject3D('cube-camera', cubeCamera);
material.envMap = cubeCamera.renderTarget;
material.needsUpdate = true;
}
});

video.js not working properly with jquery mobile

I am trying to use video.js(gitHub link - https://github.com/videojs/video.js ) plugin in my jquery mobile project to get custom video player, I followed all the documentation from this site (http://videojs.com/), but due to some reasons I am getting following errors -
The element or ID supplied is not valid. (videojs).
this[a] is not a function.
My code -
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Js/jquery.js"></script>
<script src="Js/jquery.signalR-2.1.2.min.js"></script>
<script src="Js/jquery.mobile-1.4.5.js"></script>
<link href="mcss/jquery.mobile-1.4.5.css" rel="stylesheet" />
<link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.12/video.js"></script>
<script type="text/javascript">
videojs("Mobile_VIDEO_1").ready(function () {
var vid = this;
vid.on("ended", function () {
alert("is");
$("#videoListXYZ").css("display", "block");
});
});
</script>
</head>
<body>
<div data-role="page" id="p-forget-password">
<div data-role="main" class="ui-content ui-body-cf ui-responsive">
<!-- inserted dyanamically using handlebars template "http://handlebarsjs.com"/ -->
<video id="Mobile_VIDEO_1" class="video-js vjs-default-skin" controls data-id="{{VideoId}}" data-setup='{ "plugins" : { "resolutionSelector" : { "default_res" : "360" } } }' autoplay="autoplay" width="340" height="250">
<source src="{{Path}}" type="video/mp4" data-res="360" />
</video>
</div>
</div>
</body>
Please help me to find out what I am doing wrong.
-I tried using putting videojs(xyx).ready(....) inside document.ready
- I also tried sending my script at the bottom of my page as suggested by (http://help.videojs.com/discussions/problems/985-api-ready-call-fails), but it still not working
After many hit and trial, I realized that my event is firing much before the DOM initialization, so I searched for how to check when the whole page is fully loaded and I come across this document (https://css-tricks.com/snippets/jquery/run-javascript-only-after-entire-page-has-loaded/) from this link I used this
$(window).bind("load", function() {
// code here
});
to check if my page is fully loaded or not . my final solution is mentioned below , if any of you come across a better solution then please share that to help others.
$(window).bind("load", function () {
var videoPath = $('#sv1').attr('src'); //to get the path of video
if (videoPath != "" && videoPath != null) { //checking for non-empty path
console.log(videoPath);
videojs('MY_VIDEO_1', { "plugins": { "resolutionSelector": { "default_res": "360" } } }, function () {
console.log('Good to go!');
this.play();
this.on('ended', function () {
console.log('awww...over so soon?');
$("#videoList").css("display", "block");
});
});
$("#replay").click(function () {
var myPlayer = videojs("MY_VIDEO_1");
myPlayer.play();
});
}
});

sapui5 odata binding in controller

I am building app on demo MyFiorri application and I have problem binding data using ODATA. I defined odata in component.js
jQuery.sap.declare("sap.ui.demo.myFiori.Component");
sap.ui.core.UIComponent.extend("sap.ui.demo.myFiori.Component", {
createContent : function() {
// create root view
var oView = sap.ui.view({
id : "app",
viewName : "sap.ui.demo.myFiori.view.App",
type : "JS",
viewData : { component : this }
});
// set i18n model
var i18nModel = new sap.ui.model.resource.ResourceModel({
bundleUrl : "i18n/messageBundle.properties"
});
oView.setModel(i18nModel, "i18n");
// // Using OData model to connect against a real service
var url = "http://localhost:8080/serveris/SERVERIS.svc/";
var oModel = new sap.ui.model.odata.ODataModel(url, true, "", "");
oView.setModel(oModel);
sap.ui.getCore().setModel(oModel);
// set device model
var deviceModel = new sap.ui.model.json.JSONModel({
isTouch : sap.ui.Device.support.touch,
isNoTouch : !sap.ui.Device.support.touch,
isPhone : sap.ui.Device.system.phone,
isNoPhone : !sap.ui.Device.system.phone,
listMode : sap.ui.Device.system.phone ? "None" : "SingleSelectMaster",
listItemType : sap.ui.Device.system.phone ? "Active" : "Inactive"
});
deviceModel.setDefaultBindingMode("OneWay");
oView.setModel(deviceModel, "device");
// done
return oView;
}
});
Now, I need to read these data:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="http://localhost:8080/serveris/SERVERIS.svc/">
<script id="tinyhippos-injected"/>
<id>http://localhost:8080/serveris/SERVERIS.svc/Users</id>
<title type="text">Users</title>
<updated>2014-05-27T18:07:01.403+03:00</updated>
<author>
<name/>
</author>
<link href="Users" rel="self" title="Users"/>
<entry>
<id>
http://localhost:8080/serveris/SERVERIS.svc/Users(0)
</id>
<title type="text">Users</title>
<updated>2014-05-27T18:07:01.404+03:00</updated>
<category term="serveris.User" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="Users(0)" rel="edit" title="User"/>
<link href="Users(0)/TasklistDetails" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/TasklistDetails" title="TasklistDetails"type="application/atom+xml;type=feed"/>
<content type="application/xml">
<m:properties>
<d:Login>jonas</d:Login>
<d:Passw>saugus</d:Passw>
<d:UserId>0</d:UserId>
</m:properties>
</content>
</entry>
<entry>
<id>
http://localhost:8080/serveris/SERVERIS.svc/Users(1)
</id>
<title type="text">Users</title>
<updated>2014-05-27T18:07:01.405+03:00</updated>
<category term="serveris.User" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="Users(1)" rel="edit" title="User"/>
<link href="Users(1)/TasklistDetails" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/TasklistDetails" title="TasklistDetails"type="application/atom+xml;type=feed"/>
<content type="application/xml">
<m:properties>
<d:Login>petras</d:Login>
<d:Passw>pass</d:Passw>
<d:UserId>1</d:UserId>
</m:properties>
</content>
</entry>
</feed>
I made login.view.xml and login.controller.js in which i want ta access these data
login.view.xml
<core:View
controllerName="sap.ui.demo.myFiori.view.login"
xmlns="sap.m"
xmlns:l="sap.ui.layout"
xmlns:core="sap.ui.core" >
<Page
title="{i18n>LoginIn}">
<VBox
class="marginBoxContent" >
<items>
<Label text="username" />
<Input
id="nameInput"
type="Text"
placeholder="enter username ..." />
<Label text="Pasword" />
<Input
id="passwInput"
type="Password"
placeholder="enter password..." />
<Button text="Prisijungti" press="handleContinue" />
</items>
</VBox>
</Page>
</core:View>
login.controller.js
jQuery.sap.require("sap.ui.demo.myFiori.util.Formatter");
sap.ui.controller("sap.ui.demo.myFiori.view.login", {
handleContinue : function (evt) {
// var authinfo = this.getCore().getModel().getData().Users[0]; In this line I should get data
var name = this.getView().byId("nameInput").getValue();
var paswd = this.getView().byId("passwInput").getValue();
if (name == "authinfo.login" && paswd == "authinfo.passw") {
var context = evt.getSource().getBindingContext();
this.nav.to("Master", context);
}
else {
jQuery.sap.require("sap.m.MessageToast");
sap.m.MessageToast.show("there is no such user or bad login data");
}
}
});
I hope I clearly described my problem.
Put a debug breakpoint in handleContinue function and try to see what shows up in log for sap.ui.getCore().getModel().getData().
If you're able to log something, try to see this way in console:
var theModel = sap.ui.getCore().getModel()
theModel.oData
See what you get as the output and then you can continue.

Resources