diff --git a/examples/CordovaExample/.eslintrc b/examples/CordovaExample/.eslintrc new file mode 100644 index 00000000..e5a34aec --- /dev/null +++ b/examples/CordovaExample/.eslintrc @@ -0,0 +1,5 @@ +{ + "env": { + "browser": true + } +} diff --git a/examples/CordovaExample/.gitignore b/examples/CordovaExample/.gitignore new file mode 100644 index 00000000..3e365b9a --- /dev/null +++ b/examples/CordovaExample/.gitignore @@ -0,0 +1,2 @@ +platforms/ +plugins/ diff --git a/examples/CordovaExample/config.xml b/examples/CordovaExample/config.xml new file mode 100644 index 00000000..2517ca77 --- /dev/null +++ b/examples/CordovaExample/config.xml @@ -0,0 +1,27 @@ + + + CordovaExample + + A sample Cordova application that uses the Realm JS API. + + + Realm + + + + + + + + + + + + + + + + + + + diff --git a/examples/CordovaExample/www/css/index.css b/examples/CordovaExample/www/css/index.css new file mode 100644 index 00000000..065b9e44 --- /dev/null +++ b/examples/CordovaExample/www/css/index.css @@ -0,0 +1,128 @@ +/* + * 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. + */ +* { + -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */ +} + +body { + -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */ + -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */ + -webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */ + background-color:#E4E4E4; + background-image:linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); + background-image:-webkit-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); + background-image:-ms-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%); + background-image:-webkit-gradient( + linear, + left top, + left bottom, + color-stop(0, #A7A7A7), + color-stop(0.51, #E4E4E4) + ); + background-attachment:fixed; + font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif; + font-size:12px; + height:100%; + margin:0px; + padding:0px; + width:100%; +} + +/* Portrait layout (default) */ +.app { + height:100%; /* text area height */ + width:100%; /* text area width */ + padding:34px 10px 10px 10px; + text-align:left; + margin:0px; +} + +.todo-container { + overflow: auto; +} + +.todo-container:after { + content: ""; + display: table; + float: none; +} + +.todo-item { + display: inline-block; +} + +.delete-button { + float:right; + margin-right: 20px; +} + +/* Landscape layout (with min-width) */ +@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) { + .app { + background-position:left center; + padding:75px 0px 75px 170px; /* padding-top + padding-bottom + text area = image height */ + margin:-90px 0px 0px -198px; /* offset vertical: half of image height */ + /* offset horizontal: half of image width and text area width */ + } +} + +h1 { + font-size:24px; + font-weight:normal; + margin:0px; + overflow:visible; + padding:0px; + text-align:center; +} + +.event { + border-radius:4px; + -webkit-border-radius:4px; + color:#FFFFFF; + font-size:12px; + margin:0px 30px; + padding:2px 0px; +} + +.event.listening { + background-color:#333333; + display:block; +} + +.event.received { + background-color:#4B946A; + display:none; +} + +@keyframes fade { + from { opacity: 1.0; } + 50% { opacity: 0.4; } + to { opacity: 1.0; } +} + +@-webkit-keyframes fade { + from { opacity: 1.0; } + 50% { opacity: 0.4; } + to { opacity: 1.0; } +} + +.blink { + animation:fade 3000ms infinite; + -webkit-animation:fade 3000ms infinite; +} diff --git a/examples/CordovaExample/www/img/logo.png b/examples/CordovaExample/www/img/logo.png new file mode 100644 index 00000000..9519e7dd Binary files /dev/null and b/examples/CordovaExample/www/img/logo.png differ diff --git a/examples/CordovaExample/www/index.html b/examples/CordovaExample/www/index.html new file mode 100644 index 00000000..c1f2c307 --- /dev/null +++ b/examples/CordovaExample/www/index.html @@ -0,0 +1,32 @@ + + + + + + + + + Realm Cordova Example + + +
+
+ + +
+ +
+
+ + + + diff --git a/examples/CordovaExample/www/js/index.js b/examples/CordovaExample/www/js/index.js new file mode 100644 index 00000000..10563cfb --- /dev/null +++ b/examples/CordovaExample/www/js/index.js @@ -0,0 +1,92 @@ +/* Copyright 2015 Realm Inc - All Rights Reserved + * Proprietary and Confidential + */ + +/* global Realm */ + +'use strict'; + +var app = { + initialize: function() { + // Bind any events that are required on startup. Common events are: + // 'load', 'deviceready', 'offline', and 'online'. + document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); + }, + onDeviceReady: function() { + var schema = { + name: 'Todo', + properties: [ + {name: 'text', type: Realm.Types.STRING}, + ] + }; + + this.realm = new Realm({schema: [schema]}); + + this.itemsContainer = document.getElementById('todo-items'); + this.addButton = document.getElementById('todo-button'); + this.input = document.getElementById('todo-input'); + + this.addButton.addEventListener('click', function() { + this.addTodo(); + return false; + }.bind(this), false); + + this.input.addEventListener('keypress', function(event) { + if (event.keyCode == 13) { + this.addTodo(); + return false; + } + }.bind(this), false); + + this.updateItems(); + }, + updateItems: function() { + var todos = this.realm.objects('Todo'); + var container = this.itemsContainer; + container.innerHTML = ''; + + for (var i = 0, len = todos.length; i < len; i++) { + var todo = todos[i]; + + var todoContainer = document.createElement('div'); + todoContainer.className = 'todo-container'; + + var todoItem = todoContainer.appendChild(document.createElement('div')); + todoItem.className = 'todo-item'; + todoItem.textContent = todo.text; + + var deleteButton = todoContainer.appendChild(document.createElement('button')); + deleteButton.className = 'delete-button'; + deleteButton.textContent = 'Complete'; + deleteButton.addEventListener('click', this.deleteTodo.bind(this, todo), false); + + container.appendChild(todoContainer); + } + }, + addTodo: function() { + var input = this.input; + var text = input.value; + if (!text) { + return; + } + + input.value = ''; + + var realm = this.realm; + realm.write(function() { + realm.create('Todo', {text: text}); + }); + + this.updateItems(); + }, + deleteTodo: function(todo) { + var realm = this.realm; + realm.write(function() { + realm.delete(todo); + }); + + this.updateItems(); + }, +}; + +app.initialize();