Skip to content

Commit

Permalink
PayPal Plugin update to 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyMcMillan authored and purplecabbage committed May 16, 2012
1 parent 8a664a5 commit e52c489
Show file tree
Hide file tree
Showing 72 changed files with 6,175 additions and 169 deletions.
87 changes: 52 additions & 35 deletions iPhone/AdPlugin/SAiOSAdPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,77 @@ README.md for install notes
*/

/**
* Constructor
*/
* Constructor
*/
function SAiOSAdPlugin()
{
}

/**
* show - true to show the ad, false to hide the ad
*/
* show - true to show the ad, false to hide the ad
*/
SAiOSAdPlugin.prototype.orientationChanged = function()
{
//PhoneGap.exec("SAiOSAdPlugin.orientationChanged", window.orientation);
Cordova.exec("SAiOSAdPlugin.orientationChanged", window.orientation);
if (typeof PhoneGap !== "undefined")
{
PhoneGap.exec("SAiOSAdPlugin.orientationChanged", window.orientation);
}
else
{
Cordova.exec("SAiOSAdPlugin.orientationChanged", window.orientation);
}
}

/**
* show - true to show the ad, false to hide the ad
*/
* show - true to show the ad, false to hide the ad
*/
SAiOSAdPlugin.prototype.showAd = function(show)
{
//PhoneGap.exec("SAiOSAdPlugin.showAd", show);
Cordova.exec("SAiOSAdPlugin.showAd", show);
if (typeof PhoneGap !== "undefined")
{
PhoneGap.exec("SAiOSAdPlugin.showAd", show);
}
else
{
Cordova.exec("SAiOSAdPlugin.showAd", show);
}
}

/**
* atBottom - true to put the ad at the bottom, false to put the ad at the top
*/
* atBottom - true to put the ad at the bottom, false to put the ad at the top
*/
SAiOSAdPlugin.prototype.prepare = function(atBottom)
{
if (!atBottom) {
if (!atBottom)
{
atBottom = false;
}

//PhoneGap.exec("SAiOSAdPlugin.prepare", atBottom);
Cordova.exec("SAiOSAdPlugin.prepare", atBottom);

if (typeof PhoneGap !== "undefined")
{
PhoneGap.exec("SAiOSAdPlugin.prepare", atBottom);
}
else
{
Cordova.exec("SAiOSAdPlugin.prepare", atBottom);
}
}

/**
* Install function
*/
* Install function
*/
SAiOSAdPlugin.install = function()
{
if ( !window.plugins )
window.plugins = {};
if ( !window.plugins.iAdPlugin )
window.plugins.iAdPlugin = new SAiOSAdPlugin();


if (!window.plugins)
window.plugins = {
};
if (!window.plugins.iAdPlugin)
window.plugins.iAdPlugin = new SAiOSAdPlugin();
}


/**
* Add to PhoneGap/Cordova constructor
*/
//PhoneGap.addConstructor(SAiOSAdPlugin.install);
Cordova.addConstructor(SAiOSAdPlugin.install);
* Add to PhoneGap/Cordova constructor
*/

if (typeof PhoneGap !== "undefined")
{
PhoneGap.addConstructor(SAiOSAdPlugin.install);
}
else
{
Cordova.addConstructor(SAiOSAdPlugin.install);
}
270 changes: 136 additions & 134 deletions iPhone/AdPlugin/index.html
Original file line number Diff line number Diff line change
@@ -1,143 +1,145 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />

<meta http-equiv="Content-type" content="text/html; charset=utf-8">

<!-- iPad/iPhone specific css below, add after your main css >
<link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="ipad.css" type="text/css" />
<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />
-->
<!-- If you application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here -->

<!-- <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script> -->
<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
<script type="text/javascript" charset="utf-8" src="SAiOSAdPlugin.js"></script>

<script type="text/javascript" charset="utf-8">

// If you want to prevent dragging, uncomment this section
/*
function preventBehavior(e)
{
e.preventDefault();
};
document.addEventListener("touchmove", preventBehavior, false);
*/

var gLastAdLoadedDate = null;
var gTotalAdsLoaded = 0;
var gTimerId = null;
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />

function onBodyLoad()
{
document.addEventListener("deviceready", onDeviceReady,false);
}

function onOrientationChange()
{
//alert(window.orientation);
}

/* When this function is called, PhoneGap has been initialized and is ready to roll */
function onDeviceReady()
{
// listen for orientation changes
window.addEventListener("orientationchange", window.plugins.iAdPlugin.orientationChanged, false);
//window.plugins.iAdPlugin.showAd(true);
// listen for the "iAdBannerViewDidLoadAdEvent" that is sent by the iAdPlugin
document.addEventListener("iAdBannerViewDidLoadAdEvent", iAdBannerViewDidLoadAdEventHandler, false);
// listen for the "iAdBannerViewDidFailToReceiveAdWithErrorEvent" that is sent by the iAdPlugin
document.addEventListener("iAdBannerViewDidFailToReceiveAdWithErrorEvent", iAdBannerViewDidFailToReceiveAdWithErrorEventHandler, false);

var adAtBottom = false;
setTimeout(function() {
window.plugins.iAdPlugin.prepare(adAtBottom); // by default, ad is at Top
}, 1000);
}

function iAdBannerViewDidFailToReceiveAdWithErrorEventHandler(evt)
{
alert(evt.error);
window.plugins.iAdPlugin.showAd(false);
var elem = document.getElementById("showAd");
elem.checked = false;
}

function iAdBannerViewDidLoadAdEventHandler(evt)
{
// if we got this event, a new ad is loaded
var elem = document.getElementById("lastAdLoaded");
gLastAdLoadedDate = new Date();
elem.innerHTML = gLastAdLoadedDate.toLocaleString();

elem = document.getElementById("showAd");
elem.disabled = false;
elem.checked = true;
window.plugins.iAdPlugin.showAd(true);
<meta http-equiv="Content-type" content="text/html; charset=utf-8">

gTotalAdsLoaded++;
<!-- iPad/iPhone specific css below, add after your main css >
<link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="ipad.css" type="text/css" />
<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />
-->
<!-- If you application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here -->

elem = document.getElementById("totalAdsLoaded");
elem.innerHTML = gTotalAdsLoaded.toString();
<!-- <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script> -->
<script type="text/javascript" charset="utf-8" src="cordova-1.5.1.js"></script>
<script type="text/javascript" charset="utf-8" src="SAiOSAdPlugin.js"></script>

if (gTimerId) {
clearInterval(gTimerId);
}
gTimerId = setInterval(lastAdLoadedInterval, 1000);

}

function lastAdLoadedInterval()
{
var now = (new Date()).getTime();
var diff = now - gLastAdLoadedDate.getTime();
var elem = document.getElementById("lastAdLoaded");

var ms_in_a_year = 31449600000; /* 1000ms x 60s x 60m x 24hrs x 7d x 52w */
var ms_in_a_week = 604800000; /* 1000ms x 60s x 60m x 24hrs * 7d */
var ms_in_a_day = 86400000; /* 1000ms x 60s x 60m x 24hrs */
var ms_in_an_hour = 3600000; /* 1000ms x 60s x 60m */
var ms_in_a_minute = 60000; /* 1000ms x 60s */
var ms_in_a_second = 1000;

var milliseconds = Math.floor(diff);
var seconds = Math.floor(milliseconds / ms_in_a_second) % 60;
var minutes = Math.floor(milliseconds / ms_in_a_minute) % 60;
var hours = Math.floor(milliseconds / ms_in_an_hour) % 24;
var days = Math.floor(milliseconds / ms_in_a_day) % 7;
var weeks = Math.floor(milliseconds / ms_in_a_week) % 52;
var years = Math.floor(milliseconds / ms_in_a_year);

var caption = seconds + "s ago";

if (minutes > 0) {
caption = minutes + "m " + caption;
}
if (hours > 0) {
caption = hours + "h " + caption;
}
if (days > 0) {
caption = days + "d " + caption;
}
if (weeks > 0) {
caption = weeks + "w " + caption;
}
if (years > 0) {
caption = years + "yr " + caption;
}

elem.innerHTML = caption;
}

function showAdClicked(evt)
{
window.plugins.iAdPlugin.showAd(evt.checked);
}

</script>
</head>
<script type="text/javascript" charset="utf-8">

// If you want to prevent dragging, uncomment this section
/*
function preventBehavior(e)
{
e.preventDefault();
};
document.addEventListener("touchmove", preventBehavior, false);
*/

var gLastAdLoadedDate = null;
var gTotalAdsLoaded = 0;
var gTimerId = null;

function onBodyLoad()
{
document.addEventListener("deviceready", onDeviceReady,false);
}

function onOrientationChange()
{
//alert(window.orientation);
}

/* When this function is called, PhoneGap has been initialized and is ready to roll */
function onDeviceReady()
{
// listen for orientation changes
window.addEventListener("orientationchange", window.plugins.iAdPlugin.orientationChanged, false);
window.plugins.iAdPlugin.orientationChanged(true);//trigger immediately so iAd knows its orientation on first load

window.plugins.iAdPlugin.showAd(true);
// listen for the "iAdBannerViewDidLoadAdEvent" that is sent by the iAdPlugin
document.addEventListener("iAdBannerViewDidLoadAdEvent", iAdBannerViewDidLoadAdEventHandler, false);
// listen for the "iAdBannerViewDidFailToReceiveAdWithErrorEvent" that is sent by the iAdPlugin
document.addEventListener("iAdBannerViewDidFailToReceiveAdWithErrorEvent", iAdBannerViewDidFailToReceiveAdWithErrorEventHandler, false);

var adAtBottom = false;
setTimeout(function() {
window.plugins.iAdPlugin.prepare(adAtBottom); // by default, ad is at Top
}, 1000);
}

function iAdBannerViewDidFailToReceiveAdWithErrorEventHandler(evt)
{
alert(evt.error);
window.plugins.iAdPlugin.showAd(false);
var elem = document.getElementById("showAd");
elem.checked = false;
}

function iAdBannerViewDidLoadAdEventHandler(evt)
{
// if we got this event, a new ad is loaded
var elem = document.getElementById("lastAdLoaded");
gLastAdLoadedDate = new Date();
elem.innerHTML = gLastAdLoadedDate.toLocaleString();

elem = document.getElementById("showAd");
elem.disabled = false;
elem.checked = true;
window.plugins.iAdPlugin.showAd(true);

gTotalAdsLoaded++;

elem = document.getElementById("totalAdsLoaded");
elem.innerHTML = gTotalAdsLoaded.toString();

if (gTimerId) {
clearInterval(gTimerId);
}
gTimerId = setInterval(lastAdLoadedInterval, 1000);

}

function lastAdLoadedInterval()
{
var now = (new Date()).getTime();
var diff = now - gLastAdLoadedDate.getTime();
var elem = document.getElementById("lastAdLoaded");

var ms_in_a_year = 31449600000; /* 1000ms x 60s x 60m x 24hrs x 7d x 52w */
var ms_in_a_week = 604800000; /* 1000ms x 60s x 60m x 24hrs * 7d */
var ms_in_a_day = 86400000; /* 1000ms x 60s x 60m x 24hrs */
var ms_in_an_hour = 3600000; /* 1000ms x 60s x 60m */
var ms_in_a_minute = 60000; /* 1000ms x 60s */
var ms_in_a_second = 1000;

var milliseconds = Math.floor(diff);
var seconds = Math.floor(milliseconds / ms_in_a_second) % 60;
var minutes = Math.floor(milliseconds / ms_in_a_minute) % 60;
var hours = Math.floor(milliseconds / ms_in_an_hour) % 24;
var days = Math.floor(milliseconds / ms_in_a_day) % 7;
var weeks = Math.floor(milliseconds / ms_in_a_week) % 52;
var years = Math.floor(milliseconds / ms_in_a_year);

var caption = seconds + "s ago";

if (minutes > 0) {
caption = minutes + "m " + caption;
}
if (hours > 0) {
caption = hours + "h " + caption;
}
if (days > 0) {
caption = days + "d " + caption;
}
if (weeks > 0) {
caption = weeks + "w " + caption;
}
if (years > 0) {
caption = years + "yr " + caption;
}

elem.innerHTML = caption;
}

function showAdClicked(evt)
{
window.plugins.iAdPlugin.showAd(evt.checked);
}

</script>
</head>
<body style="margin:0; padding:0;border:1px solid blue;" onload="onBodyLoad()">
<span style="position:absolute; top:0;">
This is some text at the top of the webview.
Expand Down
Loading

0 comments on commit e52c489

Please sign in to comment.