Skip to content

Commit

Permalink
support hash
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Jan 11, 2018
1 parent 8220070 commit f40bc37
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
6 changes: 4 additions & 2 deletions editor/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ mermaid.initialize({
}
});

const data = _.getUrlParams('data');
window.mermaid = mermaid;

const data = _.getHashData();

class Page extends React.Component {
constructor(props) {
Expand All @@ -47,7 +49,7 @@ class Page extends React.Component {

getEncoded() {
const encoded = _.encode(this.state.text);
const str = `?data=${encoded}`;
const str = `#data=${encoded}`;
history.replaceState({}, document.title, str);
}

Expand Down
4 changes: 2 additions & 2 deletions editor/plantuml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import './plantuml.less';
import _ from './utils';
import pkg from '../package';

const data = _.getUrlParams('data');
const data = _.getHashData();

class Page extends React.Component {
constructor(props) {
Expand All @@ -26,7 +26,7 @@ class Page extends React.Component {

getEncoded() {
const encoded = _.encode(this.state.text);
const str = `?data=${encoded}`;
const str = `#data=${encoded}`;
history.replaceState({}, document.title, str);
return encoded;
}
Expand Down
18 changes: 3 additions & 15 deletions editor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,7 @@ exports.decode = text => {
return Utf8ArrayToStr(inflated);
};

exports.getUrlParams = k => {
var params = {};
var url = location.href;
var idx = url.indexOf('?');

if (idx > 0) {
var queryStr = url.substring(idx + 1);
var args = queryStr.split('&');
for (var i = 0; i < args.length; i++) {
var a = args[i];
var nv = args[i] = a.split('=');
params[nv[0]] = nv.length > 1 ? nv[1] : true;
}
}
return params[k];
exports.getHashData = () => {
var hash = location.hash;
return hash.split('#data=')[1];
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "umlplot",
"version": "1.0.0",
"version": "1.0.1",
"description": "umlplot",
"keywords": [
"plot"
"plot",
"uml"
],
"main": "/dist/index.js",
"repository": {
Expand Down

0 comments on commit f40bc37

Please sign in to comment.