Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
Developer
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook
My Carrier: none
Accepted Solution

PhoneGap and bbUI.js - can't find variable blackberry

[ Edited ]

I'm getting this error using bbUI.js in PhoneGap:

 

ReferenceError: Can't find variable: blackberry  bbui.js:145

 

The error occurs when bb.init() is called.

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<title>Hello World</title>
<link rel="stylesheet" type="text/css" href="css/bbui.css" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" src="js/jquery-2.0.2.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/bbui.js"></script>
<script type="text/javascript">
var deviceReadyDeferred = $.Deferred();
var webworksReadyDeferred = $.Deferred();

//make sure cordova is ready
document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
	alert("deviceReady");
	deviceReadyDeferred.resolve();
}

//make sure webworks is ready (so that bbui will work)
document.addEventListener("webworksready", webworksReady, false);
function webworksReady() {
	alert("webworksReady");
	webworksReadyDeferred.resolve();
}

//when cordova and webworks are both ready start bbui
$.when(deviceReadyDeferred, webworksReadyDeferred).then(doWhenBothFrameworksLoaded);
function doWhenBothFrameworksLoaded() {
	alert("bb.init()");
	bb.init();
	// Open first screen
	alert("bb.pushScreen('firstscreen.html', 'firstScreen')");
	bb.pushScreen('firstscreen.html', 'firstScreen');
} 
</script>
</head>
<body>
</body>
</html>
Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: PhoneGap and bbUI.js - can't find variable blackberry

Hi,

 

If you are using Apache Cordova / PhoneGap v2.8 or greater, you'll need to add plugins using the plugin script.


See the getting started guide for more information:

 

http://cordova.apache.org/docs/en/2.9.0/guide_getting-started_blackberry10_index.md.html

 

I believe bbUI requires both of these:

 

https://github.com/blackberry/cordova-blackberry-plugins/tree/master/plugin/com.blackberry.app

https://github.com/blackberry/cordova-blackberry-plugins/tree/master/plugin/com.blackberry.ui.contex...

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Developer
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook
My Carrier: none

Re: PhoneGap and bbUI.js - can't find variable blackberry

I added those plugins. Now I'm getting:

ReferenceError: Can't find variable: bb
Developer
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: PhoneGap and bbUI.js - can't find variable blackberry

Additionally you need... So I believe

 

local:///chrome/webworks.js

 

Can't be sure (don't use PG for BB)

 

May help




Click the like button if you find my posts useful!
Developer
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook
My Carrier: none

Re: PhoneGap and bbUI.js - can't find variable blackberry

Nope that didn't work.  Also cordova.js is firing the webworksready event.

 

My index.html currently looks like this:

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<title>Hello World</title>
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" src="js/jquery-2.0.2.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
var deviceReadyDeferred = $.Deferred();
var webworksReadyDeferred = $.Deferred();

//make sure cordova is ready
document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
	alert("deviceReady");
	deviceReadyDeferred.resolve();
}

//make sure webworks is ready (so that bbui will work)
document.addEventListener("webworksready", webworksReady, false);
function webworksReady() {
	alert("webworksReady");
	webworksReadyDeferred.resolve();
}

//when cordova and webworks are both ready start bbui
$.when(deviceReadyDeferred, webworksReadyDeferred).then(doWhenBothFrameworksLoaded);
function doWhenBothFrameworksLoaded() {
	alert("bb.init()");
	bb.init();
	// Open first screen
	alert("bb.pushScreen('firstscreen.html', 'firstScreen')");
	bb.pushScreen('firstscreen.html', 'firstScreen');
} 
</script>
</head>
<body>
</body>
</html>

 

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: PhoneGap and bbUI.js - can't find variable blackberry

It looks like you're missing the script tag for bbui.js. The bb namespace comes from that library.

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Developer
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook
My Carrier: none

Re: PhoneGap and bbUI.js - can't find variable blackberry

I added back the bbui.js script. Getting this error: 

 

TypeError: 'undefined' is not an object (evaluating 'blackberry.event.addEventListener') bbui.js:145

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<title>Hello World</title>
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" src="js/jquery-2.0.2.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/bbui.js"></script>
<script type="text/javascript">
var deviceReadyDeferred = $.Deferred();
var webworksReadyDeferred = $.Deferred();

//make sure cordova is ready
document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
	alert("deviceReady");
	deviceReadyDeferred.resolve();
}

//make sure webworks is ready (so that bbui will work)
document.addEventListener("webworksready", webworksReady, false);
function webworksReady() {
	alert("webworksReady");
	webworksReadyDeferred.resolve();
}

//when cordova and webworks are both ready start bbui
$.when(deviceReadyDeferred, webworksReadyDeferred).then(doWhenBothFrameworksLoaded);
function doWhenBothFrameworksLoaded() {
	alert("bb.init()");
	bb.init();
	// Open first screen
	alert("bb.pushScreen('firstscreen.html', 'firstScreen')");
	bb.pushScreen('firstscreen.html', 'firstScreen');
} 
</script>
</head>
<body>
</body>
</html>

 This is the list of installed plugins:

com.blackberry.app
com.blackberry.jpps
com.blackberry.ui.contextmenu
com.blackberry.utils
org.apache.cordova.blackberry10.pimlib
org.apache.cordova.core.Accelerometer
org.apache.cordova.core.Battery
org.apache.cordova.core.Camera
org.apache.cordova.core.Contacts
org.apache.cordova.core.Device
org.apache.cordova.core.Logger
org.apache.cordova.core.Media
org.apache.cordova.core.Network
org.apache.cordova.core.Notification
org.apache.cordova.core.SplashScreen

 

 

 

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: PhoneGap and bbUI.js - can't find variable blackberry

Ok, blackberry.event has been deprecated in cordova, but not yet in WebWorks.

 

You'll need to change that line in bbui.js to document.addEventListener OR you can add this to your script block to ensure any calls to blackberry.event are routed to document.

 


if (!blackberry) {
blackberry = {};
}
blackberry.event = document;
Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: PhoneGap and bbUI.js - can't find variable blackberry

Added this issue to bbui.js on GitHub

 

https://github.com/blackberry/bbUI.js/issues/929

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Developer
Posts: 125
Registered: ‎10-02-2011
My Device: Playbook
My Carrier: none

Re: PhoneGap and bbUI.js - can't find variable blackberry

That did it. Thanks!