Giter Club home page Giter Club logo

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

  • uri__querystring – 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__querystring

modules.require(['uri__querystring'], function(Querystring) {

    // Parse url
    var u = Querystring.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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bem-history's Issues

2.0 milestone and release

What you think about releasing v2 branch under version 2.0?
What we need to do before that?
It's like 32 commits after v1.2.

Неправильно обрабатывает хосты с портом

Если у домена указан порт, то на строчке

// Push the newState
history[method](newState.id, newState.title, newState.url);

Выбрасывает эксепшн: Uncaught Error: SecurityError: DOM Exception 18

Содержимое newState.url на момент ошибки:

. newState: Object
. data: Object
. hash: "/radio"
. id: "137569613390805398990337271243"
. normalized: true
. title: ""
. url: "http://site.com/foo"

В то время как домен site.com:8002 — кроссдоменность получается.

Incorrect behavior of getBasePage

> $.url.getBasePage('http://example.com/');
"http://example.com/"
> $.url.getBasePage('http://example.com/#!/search?q=test');
"http:/"

Expected same results.

bem-core v4

Is it possible to use bem-history whith bem-core v4?

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.