GithubHelp home page GithubHelp logo

fual / bem-history Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bem/bem-history

0.0 3.0 0.0 216 KB

BEM wrap for History API

Home Page: https://bem.info/libs/bem-history/

JavaScript 98.36% Shell 1.39% CSS 0.25%

bem-history's Introduction

bem-history

What is this?

BEM wrap for History API:

  • supports browsers with a native History API and hashchange event;
  • provides manipulations with url, browser location and history in the terms of BEM.

Components

Blocks

  • uri – module for an url parsing;
  • history – module provides work with a browser History with two modificators:
  • provider_history-api – supports a native History API;
  • provider_hashchange – supports fallback on the hashchange event;
  • location – high-level module for a window.location change.

Scheme of library work

bem-history workflow

Usage

uri

modules.require(['uri'], function(Uri) {

    // Parse url
    var u = Uri.parse('http://example.org:8080/path?test=1&test=2&param2=22');

    // Change port
    u.setPort(80);

    // Change query params
    u.deleteParam('test', '2');
    u.replaceParam('param2', 2);

    // Serialize url
    u.toString(); // "http://example.org:80/path?test=1&param2=2"

});

history

modules.require(['history'], function(History) {

    // Create history instance
    var history = new History();

    // Push new or replace history state
    history.changeState('push', { title: 'Title', url: 'http://example.org:8080/path' });
    history.changeState('replace', { title: 'Title', url: 'http://example.org:8080/path?test=1' });

});

location

modules.require(['location'], function(location) {

    // Change `window.location` using a full url
    location.change({ url: 'http://example.org:8080/path' });

    // Change current location using only the new query params
    location.change({ params: { param1: [11,12], param2: 'ololo' } });
    window.location.href; // "http://example.org:8080/path?param1=11&param1=12&param2=ololo"

});

bem-history's People

Contributors

greli avatar h4 avatar ivn-cote avatar mishanga avatar nerevar avatar ololobus avatar sipayrt avatar tadatuta avatar tormozz48 avatar

Watchers

 avatar  avatar  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.