Skip to content

Instantly share code, notes, and snippets.

@mrp1q7z
Created July 28, 2014 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrp1q7z/4c277ec824259392f5d8 to your computer and use it in GitHub Desktop.
Save mrp1q7z/4c277ec824259392f5d8 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<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" />
<link rel="stylesheet" type="text/css" href="shared/style/headers.css" />
<link rel="stylesheet" type="text/css" href="shared/style/buttons.css" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<meta name="msapplication-tap-highlight" content="no" />
<title>Hello World</title>
</head>
<body>
<section id="opening" role="region" class="current" data-position="current">
<header>
<menu type="toolbar">
<a href="#"><span id="settings_button" class="icon icon-settings">settings</span></a> <!-- @@@3 -->
</menu>
<h1>Hello World</h1>
</header>
<div class="app">
<h1>Opening</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<br />
<div class="bb-docs skin-organic">
<button id="start_button">Start</button> <!-- @@@5 -->
</div>
</div>
</section>
<section id="settings" role="region" class="current" data-position="current">
<header>
<menu type="toolbar">
<button id="settings_done">done</button> <!-- @@@4 -->
</menu>
<h1>Settings</h1>
</header>
<div class="app">
<h1>Settings</h1>
</div>
</section>
<section id="main" role="region" class="current" data-position="current">
<header>
<h1>Main</h1>
</header>
<div class="app">
<h1>Main</h1>
</div>
</section>
<script type="text/javascript" src="cordova.js"></script>
<!-- @@@1(ここから) -->
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/json2.js"></script>
<script type="text/javascript" src="js/underscore-min.js"></script>
<script type="text/javascript" src="js/backbone-min.js"></script>
<!-- @@@1(ここまで) -->
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
console.log("test-000");
app.initialize();
console.log("test-999");
</script>
</body>
</html>
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// @@@2(ここから)
var ViewOpening = Backbone.View.extend({
el : "#opening",
// @@@3(ここから)
events : {
"click #settings_button" : "settingsButtonClicked",
"click #start_button" : "startButtonClicked", // @@@5
},
settingsButtonClicked: function() {
view.showSettings();
},
// @@@3(ここまで)
// @@@5
startButtonClicked: function() {
view.showMain();
},
});
var ViewSettings = Backbone.View.extend({
el : "#settings",
// @@@4(ここから)
events : {
"click #settings_done" : "settingsDoneClicked",
},
settingsDoneClicked: function() {
view.showOpening();
},
// @@@4(ここまで)
});
var ViewMain = Backbone.View.extend({
el : "#main",
});
var viewOpening = new ViewOpening;
var viewSettings = new ViewSettings;
var viewMain = new ViewMain;
var view = {
showOpening: function() {
viewOpening.$el.show();
viewSettings.$el.hide();
viewMain.$el.hide();
},
showSettings: function() {
viewOpening.$el.hide();
viewSettings.$el.show();
viewMain.$el.hide();
},
showMain: function() {
viewOpening.$el.hide();
viewSettings.$el.hide();
viewMain.$el.show();
},
};
// @@@2(ここまで)
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
view.showOpening(); // @@@2
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.addEventListener("backbutton", this.onBackButtonClick, false); // +++ add adMob +++
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
// +++ add adMob(ここから) +++
if (navigator.userAgent.indexOf('Android') >=0) {
app.createAd();
}
// +++ add adMob(ここまで)+++
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}, // カンマを追加すること
// +++ add adMob(ここから) +++
createAd: function() {
if (!(window.plugins && window.plugins.AdMob)) {
alert('AdMob plugin not available/ready.');
return;
}
var adMobId = "ca-app-pub-4623298212622664/3911393437"; // ご自分のIDに変更してください
var am = window.plugins.AdMob;
am.createBannerView(
{ 'publisherId': adMobId
,'adSize': am.AD_SIZE.BANNER
,'bannerAtTop': false
,'overlap': true
}
, function() {
am.requestAd(
{ 'isTesting':true }
, function() { am.showAd(true, function(){}, function(){}); }
, function() { alert('failed to request ad'); }
)
}
, function(){ alert("failed to create ad view"); }
);
},
onBackButtonClick: function() {
if (window.plugins && window.plugins.AdMob) {
var am = window.plugins.AdMob;
am.destroyBannerView({}, function(){}, function(){});
}
navigator.app.exitApp();
}
// +++ add adMob(ここまで)+++
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment