@Synacs-U
Html, CSS, Js, Jquery, PHP, Mysql

Как правильно пользоваться плагинами в apache cordova?

Добрый вечер,
Как правильно установить и использовать плагин кордовы?
Действовал по этому туториалу: https://www.tutorialspoint.com/cordova/cordova_fil...

1. Добавил плагин
$cordova plugin add cordova-plugin-file


2. Вставил код в index.js
Код

Было:
onDeviceReady: function() {
        this.receivedEvent('deviceready');


Стало:
onDeviceReady: function() {
        this.receivedEvent('deviceready');
        document.getElementById("createFile").addEventListener("click", createFile); // *synacs (Обработчик)
        document.getElementById("writeFile").addEventListener("click", writeFile); // *synacs (Обработчик)
        document.getElementById("readFile").addEventListener("click", readFile); // *synacs (Обработчик)
        document.getElementById("removeFile").addEventListener("click", removeFile); // *synacs (Обработчик)
    },


Вот весь файл index.js
/*
 * 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.
 */
var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');
        document.getElementById("createFile").addEventListener("click", createFile); // *synacs (Обработчик)
        document.getElementById("writeFile").addEventListener("click", writeFile); // *synacs (Обработчик)
        document.getElementById("readFile").addEventListener("click", readFile); // *synacs (Обработчик)
        document.getElementById("removeFile").addEventListener("click", removeFile); // *synacs (Обработчик)
    },

    // 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);
    }
};

function createFile() { 
    /* *synacs 
    * (https://www.tutorialspoint.com/cordova/cordova_file_system.htm)
    * Создание и редактирование файловой системы
    */
    var type = window.TEMPORARY;
    var size = 5*1024*1024;
    window.requestFileSystem(type, size, successCallback, errorCallback)
 
    function successCallback(fs) {
       fs.root.getFile('log.txt', {create: true, exclusive: true}, function(fileEntry) {
          alert('File creation successfull!')
       }, errorCallback);
    }
 
    function errorCallback(error) {
       alert("ERROR: " + error.code)
    }
 } // end createFile();



app.initialize();



3. Вызвал из index.html
Вот весь файл index.html
<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
	<title>Jquery mobile</title>
	<link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css">
	<script src="js/jquery-v1.10.2.js"></script>
	<script src="js/jquery.mobile-1.4.5.min.js"></script>
</head>

<body>

<!-- page: #one -->
    <div data-role="page" id="home">

        <!-- header -->
            <div data-role="header">
                <a href="#setting" data-rel="back" class="ui-btn-left ui-alt-icon ui-nodisc-icon ui-btn ui-icon-gear ui-btn-icon-notext ui-corner-all" data-role="button" role="button">Настройки</a>
                <h1>Synacs</h1>
                <a href="#" data-rel="back" class="ui-btn-right ui-btn ui-icon-bullets ui-btn-icon-notext ui-shadow ui-corner-all" data-role="button" role="button">Меню</a>
            </div>
            

        <!-- /header -->
        <!-- content -->
        <div role="main" class="ui-content">
            <h2>Привет</h2>

            <p>Это тестовое приложение, для практики.</p>
                <p>Основные классы: <a href="popup/info.class.html" data-transition="pop" class="my-tooltip-btn ui-btn ui-alt-icon ui-nodisc-icon ui-btn-inline ui-icon-info ui-btn-icon-notext" title="info.class">info.class</a><code>synacs;</code>
            </p>
            <p>
                    <a href="popup/agreement.html" class="ui-btn ui-shadow ui-corner-all" data-transition="pop">Соглашение ( Terms of use )</a>
                    <a href="#" id="createFile" class="ui-btn ui-shadow ui-corner-all">Создать файл</a>

            </p>
        </div>
        <!-- /content -->


        <!-- footer -->
            <div data-role="footer" data-theme="a">
                <h4>Хуй его знает</h4>
            </div>
        <!-- /footer -->





        <!-- window: Settings  -->
        <div data-role="panel" id="setting" data-position="left" data-display="reveal">
            <h3>Настройки:</h3>
            <p>This panel is positioned on the right with the reveal display mode. The panel markup is <em>after</em> the header, content and footer in the source order.</p>
            <p>To close, click off the panel, swipe left or right, hit the Esc key, or use the button below:</p>
            <a href="#demo-links" data-rel="close" class="ui-btn ui-shadow ui-corner-all ui-btn-a ui-icon-delete ui-btn-icon-left ui-btn-inline">Close panel</a>
        </div>
        <!-- /Settings -->








    </div>
<!-- /page one -->
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>


Ни чего не вышло.
Что я делаю не так?
Ссылка на репозиторий: https://gitlab.com/synacs.user/synacs-app
  • Вопрос задан
  • 177 просмотров
Решения вопроса 1
@Synacs-U Автор вопроса
Html, CSS, Js, Jquery, PHP, Mysql
Всё разобрался. файл cordova.js должен быть подключен (хоть его как бы и нет), и вызывается функция после 'deviceready'
document.addEventListener("deviceready", function(){
    $('#title-device-info').html(device.manufacturer+' '+device.model); // HUAWEI FLA-LX1
    // Плагин cordova-plugin-device
    // https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device/
 }, false);

5bdf4a9e88395233763766.png
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы