Giter VIP home page Giter VIP logo

mybb-dvzthemeoptions's Introduction

DVZ Theme Options

Provides variables based on whitelisted cookie parameters to templates and modifies theme properties.

Requirements

  • MyBB 1.8.x
  • PHP >= 7.0

1. Theme Definitions

Theme-specific options can be placed in a theme-name-lowercase.json file in the inc/plugins/dvz_theme_options/themes/ directory in a JSON format:

{
  "scheme": {
    "light": [],
    "dark": {
      "stylesheets": [
        "dip-in-black.css"
      ],
      "editortheme": "dip-in-black.css"
    }
  },
  "menu-position": {
    "top": [],
    "side": [],
  }
}

The first-level keys specify option names, and second-level keys their possible cases (light or dark for scheme, and top or side for menu-position). The value for each case can be either an empty array to simply provide whitelisting for option cases or contain properties that modify theme options:

  • array stylesheets

    Appends additional stylesheets associated with the current theme to {$stylesheets}.

  • string editortheme

    Name of the editor theme file that overwrites the {$theme['editortheme']} variable.

Theme definitions are cached โ€” after making changes deactivate and activate the plugin (or set dvzThemeOptions\DEVELOPMENT_MODE to 1 to bypass caching).

2. Passing Initial Values to the Client

The plugin compares cookie values against the whitelist and provides a JSON-encoded object, available for templates. The values can passed to JavaScript for further processing by appending the code in the headerinclude template (e.g. inside <script> with other MyBB variables):

	// DVZ Theme Options
	var themeOptionCases = '{$themeOptionCasesJson}';

The variable will produce an object similar to {"scheme":"light","menu-position":"top"}.

3. Managing Options Client-Side

Include the following library in you theme's JavaScript files: ThemeOptions.js.

API:

  • bool active

    Indicating whether the plugin is activated โ€” false values should cause the theme to hide interface related to switching options. The library's behavior in this condition is undefined.

  • void setOptionCase( string option , string optionCase )

    Sets a new optionCase value for option.

  • string|undefined getOptionCase( string option )

    Retrieves the case value for specified option.

  • void fetchApplyProperties( [ function callback ] )

    Performs an asynchronous request to the server to receive parsed property values passed to optional callback function callback:

    • stylesheets, an array of appended extra stylesheets,
    • stylesheetsRendered, extra <link> tags for stylesheets to be updated within the <head> section,
    • editortheme, the case-overwritten value,
    • optionCases, an array of updated case values for specified options.

    The <link> stylesheet references are updated automatically once the function is executed.

Cookies in the format similar to theme_options[theme-name-lowercase][menu-position] will be modified using themeOptions.setOptionCase() and attached to future requests.

Once the document is loaded an object can be initialized with the lowercase theme name (same as the .json file) and used:

$(function () {
    themeOptions = new ThemeOptions('theme-name-lowercase');

    // make sure the plugin is installed
    if (themeOptions.active) {

        // set scheme to dark
        themeOptions.setOptionCase('scheme', 'dark');

        // repaint the page with appended CSS
        themeOptions.fetchApplyProperties(function(data) {
            console.log('Page painted ' + data['optionCases']['scheme']);
        });
    }
});

4. Raw Case Values in Templates

The option case values are provided in a globally available $themeOptionCases array. Therefore, an option called menu-position can be used in MyBB templates like so:

<div class="menu menu--$themeOptionCases['menu-position']}">
	This is the {$themeOptionCases['menu-position']} menu.
</div>

mybb-dvzthemeoptions's People

Contributors

dvz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.