Skip to content

Instantly share code, notes, and snippets.

@nolimits4web
Created May 31, 2014 12:07
Show Gist options
  • Save nolimits4web/2a7e3b597bd2d8dbaf01 to your computer and use it in GitHub Desktop.
Save nolimits4web/2a7e3b597bd2d8dbaf01 to your computer and use it in GitHub Desktop.

Revisions

  1. nolimits4web created this gist May 31, 2014.
    82 changes: 82 additions & 0 deletions Framework7 Plugin Barebon
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    /*==================================================
    * Awesome Plugin 1.0.0
    * Awesome plugin for Framework7 0.8.6+
    *
    * http://www.path.to/plugin/home/page
    *
    * Copyright 2010-2014, John Doe
    * The Company
    * http://www.path.to/developer/home/page
    *
    * Licensed under GPL & MIT
    *
    * Released on: May 46, 2014
    ==================================================*/

    //Include this file after main framework7.js library!

    Framework7.prototype.plugins.demoPlugin = function (app, params) {
    /*
    @app - initialized App instance
    @params - your local plugin params. Should be passed as an parameter on app initialization with same name as your plugin name (like demoPlugin in this plugin):
    var app = new Framework7({
    modalTitle: 'my app',
    //Here comes your plugin params
    demoPlugin: {
    param1: 50,
    param2: true
    },
    //Or like boolean flag:
    demoPlugin: true
    });
    */

    /*
    Here comes your local plugin scope.
    Your plugin should return object that may contain 3 objects with methods:
    - 'hooks': they work just like ususal callbacks, they called by apps on dirrent stages. Each hook receives different arguments
    - 'prevents' (not injected to app yet): they allow to prevent some app actions, for example they will allow you to prevent pages animation and make your own
    - 'process' (not injected to app yet): they work like preprocessors, each process method may takes data and return it modified
    */

    /* Note, that your plugin initialized on the first stage of app initialization and few things may be still unneaccessable here. If you need to execute code when app is fully initialized, use 'appInit' hook */

    /* This demo plugin does nothing, just console.log every available hook with arguments. May count that this is a Debug plugin */

    function appInit() {
    // Do something when app fully initialized
    console.log('appInit');
    }

    // Return object
    return {
    // Object contains hooks, all hooks are optional, don't use those you don't need
    hooks: {
    appInit: appInit,
    navbarInit: function (navbar, pageData) {
    console.log('navbarInit', navbar, pageData);
    },
    pageInit: function (pageData) {
    console.log('pageInit', pageData);
    },
    pageBeforeInit: function (pageData) {
    console.log('pageBeforeInit', pageData);
    },
    pageBeforeAnimation: function (pageData) {
    console.log('pageBeforeAnimation', pageData);
    },
    pageAfterAnimation: function (pageData) {
    console.log('pageAfterAnimation', pageData);
    },
    addView: function (view) {
    console.log('addView', view);
    },
    load: function (view, url, content) {
    console.log('load', view, url, content);
    },
    goBack: function (view, url, preloadOnly) {
    console.log('goBack', view, url, preloadOnly);
    }
    }
    };
    };