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
Regular Contributor
iruka
Posts: 79
Registered: ‎09-17-2012
My Device: Torch 9800
My Carrier: DiGi
Accepted Solution

BB10 - Subscribing to webworksready event

Hi all. I am seriously confused on how to subscribe to webworksready event.  The app I'm working on will have one index.html but will uses different JavaScript function to re-write the <body> and also act as module/pages of the app. 

 

When user loads the app, it will retrieve the device pin but I have problem as the functions seems to get called twice. 

 

<!DOCTYPE html>
<html>
<head>
  <meta name="x-blackberry-defaultHoverEffect" content="false" />
  <link href="css/layout_q10.css" rel="stylesheet" type="text/css">
  <script src="local:///chrome/webworks.js" type="text/javascript"></script>
  <script src="js/jquery-1.8.0.js" type="text/javascript"></script>
  <script src="js/action.js" type="text/javascript"></script>
  <script src="js/module.js" type="text/javascript"></script>
  <script src="js/database.js" type="text/javascript"></script>
  <script type="text/javascript">
    var meta = document.createElement("meta");
	meta.setAttribute('name', 'viewport');
	meta.setAttribute('content','initial-scale=' + (1/window.devicePixelRatio) + ',user-scalable=no');
	document.getElementsByTagName('head')[0].appendChild(meta);
	
	var empNo, totalpage, pagenum; 
	var indieClaim = new Array();
	
	$(document).ready(function(){
	  authenticateBB();
	});
	window.addEventListener("load", function(e) {
	  document.addEventListener("webworksready", function(){
	  });
	}, false);
  </script>
</head>
<body id="mainBody">

</body>
</html>

 

function authenticateBB()
{
  alert("here");
  alert(blackberry.identity.uuid);
}

 authenticateBB() is being called twice. Have I place something somewhere I shouldn't? Sorry, just picked up JavaScript and jQuery.  

 

Any advice and suggestion would be greatly appreciated. 

Please use plain text.
BlackBerry Development Advisor (Retired)
grahamzibar
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10
My Carrier: Bell

Re: BB10 - Subscribing to webworksready event

[ Edited ]

I would keep everything as is except for the last script tag you have in the head of the document. Instead of placing it right before the closing head tag, place it right before the closing body tag and modify it like so:

<script type="text/javascript">
var meta = document.createElement("meta");
meta.setAttribute('name', 'viewport');
meta.setAttribute('content','initial-scale=' + (1/window.devicePixelRatio) + ',user-scalable=no');
document.getElementsByTagName('head')[0].appendChild(meta);

var empNo, totalpage, pagenum;
var indieClaim = new Array();

window.addEventListener('webworksready', authenticateBB);
</script>

Hope that helps!

------------------------------
@grahamzibar
-_- zZZ
Please use plain text.
Developer
peardox
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: BB10 - Subscribing to webworksready event

It stopped working for me as well recently (10.1.0.237)

 

I do direct injection - this sort of thing...

 

		if(isbb10) {
			var bbww = document.createElement("script");
			bbww.src='local:///chrome/webworks.js';
			bbww.type = 'text/javascript';
			document.getElementsByTagName('head')[0].appendChild(bbww);
			document.addEventListener("webworksready", onWebworksReady, false);
			}

 

I recently had to rip that out of everything as the event never fires

 

The reason for this kinda code is for cross-platform stuff




Click the like button if you find my posts useful!
Please use plain text.
Regular Contributor
iruka
Posts: 79
Registered: ‎09-17-2012
My Device: Torch 9800
My Carrier: DiGi

Re: BB10 - Subscribing to webworksready event

Hi grahamzibar, I have to move it to <body> tag but authenticate is still being called twice. 

 

Hi peardox. I'm not sure I place the solution you provided correctly as I have tried placing it on both <body> and <head> but authenticateBB does not get called.

 

In head

<script type="text/javascript">
 var meta = document.createElement("meta");
 meta.setAttribute('name', 'viewport');
 meta.setAttribute('content', 'initial-scale='+ (1/window.devicePixelRatio) + ',user-scalable=no');
 document.getElementsByTagName('head')[0].appendChild(meta);

var empNo, totalpage, pagenum; var indieClaim = new Array(); var bbww = document.createElement("script"); bbww.src='local:///chrome/webworks.js'; bbww.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(bbww); document.addEventListener("webworksready", authenticateBB, false); </script>

In body

<script type="text/javascript">
var bbww = document.createElement("script");
bbww.src='local:///chrome/webworks.js';
bbww.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(bbww);
document.addEventListener("webworksready", authenticateBB, false);
</script>

:smileysad:

 

I wonder if it's device issue as I tried to load the same code on Z10 Dev Alpha B, it works fine. authenticateBB did not called twice. 

 

The one that is giving me problem is Q10 Dev Alpha C, 10.1.0.809. The strange thing as weil, it does not have BlackBerry Hub. If you swipe to the left, it only display a message saying BlackBerry Hub Coming Soon. 

 

 

 

Please use plain text.
Developer
peardox
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: BB10 - Subscribing to webworksready event

Twice only ever happens in Ripple




Click the like button if you find my posts useful!
Please use plain text.
Regular Contributor
iruka
Posts: 79
Registered: ‎09-17-2012
My Device: Torch 9800
My Carrier: DiGi

Re: BB10 - Subscribing to webworksready event

I have changed my OS to 10.1.0.1485 and the authenticateBB isn't being called twice. And my device got BlackBerry Hub. So it's OS issue. 

Please use plain text.
Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: BB10 - Subscribing to webworksready event

I resorted to bundling a heavily customized webworks.js with the app instead of using the on-device one. This way I was able to remove the dependency on Ripple, fix bugs and gracefully degrade on other browsers/devices.

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Please use plain text.