Skip to content
This repository has been archived by the owner on Feb 2, 2020. It is now read-only.

Commit

Permalink
make layout creating using default templateLayoutFactory templates
Browse files Browse the repository at this point in the history
* add dist folder to .gitignore
* fix error at build:umd script
  • Loading branch information
Mike_Device committed Feb 27, 2017
1 parent ff66db3 commit cab5b81
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
.DS_Store
.DS_Store?
.idea/
Expand Down
2 changes: 0 additions & 2 deletions lib/MapMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ var MapMarker = function (_Component) {
key: '_setupMarkerLayout',
value: function _setupMarkerLayout(component) {
this._markerElement = document.createElement('div');
this._markerElement.className = 'icon-content';
this._markerElement.style.display = 'inline-block';

_reactDom2.default.render(component, this._markerElement);
this._controller.setLayout('iconLayout', this._markerElement);
Expand Down
16 changes: 6 additions & 10 deletions lib/controllers/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ function createLayout(_ref) {
_ref$extendMethods = _ref.extendMethods,
extendMethods = _ref$extendMethods === undefined ? {} : _ref$extendMethods;

var LayoutClass = _api2.default.getAPI().templateLayoutFactory.createClass('<i></i>', Object.assign({
var LayoutClass = _api2.default.getAPI().templateLayoutFactory.createClass(domElement.innerHTML, Object.assign({
build: function build() {
LayoutClass.superclass.build.call(this);

this.element = this.getElement();
this.element.style.display = 'inline-block';

this.options = this.getData().options;

this._setupContent(domElement);
this._updateSize();

detectImagesLoaded(this.getElement()).then(this._updateMarkerShape.bind(this));
detectImagesLoaded(this.element).then(this._updateMarkerShape.bind(this));
},

getShape: function getShape() {
Expand All @@ -54,18 +56,12 @@ function createLayout(_ref) {
this.events.fire('shapechange');
},

_setupContent: function _setupContent(domElement) {
var element = this.getElement();
element.appendChild(domElement);
},

_updateSize: function _updateSize() {
this._size = this._getSize();
},

_getSize: function _getSize() {
var element = this.getElement().querySelector('.icon-content');
return [element.offsetWidth, element.offsetHeight];
return [this.element.offsetWidth, this.element.offsetHeight];
}
}, extendMethods));

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build:lib": "babel ./src -d lib",
"build:umd": "webpack src/index.js dist/YandexMapReact.js --config webpack.config.dev.js",
"watch": "babel --watch ./src -d lib",
"watch:umd": "webpack src/index.js dist/YandexMapReact.js --watch --config webpack.config.dev.js",
"lint": "eslint src/",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
2 changes: 0 additions & 2 deletions src/MapMarker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class MapMarker extends Component {

_setupMarkerLayout (component) {
this._markerElement = document.createElement('div');
this._markerElement.className = 'icon-content';
this._markerElement.style.display = 'inline-block';

ReactDOM.render(component, this._markerElement);
this._controller.setLayout('iconLayout', this._markerElement);
Expand Down
16 changes: 6 additions & 10 deletions src/controllers/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ function detectImagesLoaded (element) {
}

function createLayout ({domElement, extendMethods = {}}) {
const LayoutClass = (api.getAPI()).templateLayoutFactory.createClass('<i></i>', Object.assign({
const LayoutClass = (api.getAPI()).templateLayoutFactory.createClass(domElement.innerHTML, Object.assign({
build: function () {
LayoutClass.superclass.build.call(this);

this.element = this.getElement();
this.element.style.display = 'inline-block';

this.options = this.getData().options;

this._setupContent(domElement);
this._updateSize();

detectImagesLoaded(this.getElement()).then(this._updateMarkerShape.bind(this));
detectImagesLoaded(this.element).then(this._updateMarkerShape.bind(this));
},

getShape: function () {
Expand All @@ -47,18 +49,12 @@ function createLayout ({domElement, extendMethods = {}}) {
this.events.fire('shapechange');
},

_setupContent: function (domElement) {
const element = this.getElement();
element.appendChild(domElement);
},

_updateSize: function () {
this._size = this._getSize();
},

_getSize: function () {
const element = this.getElement().querySelector('.icon-content');
return [element.offsetWidth, element.offsetHeight];
return [this.element.offsetWidth, this.element.offsetHeight];
}
}, extendMethods));

Expand Down
3 changes: 3 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ module.exports = {
loaders: [
{test: /\.jsx?/i, exclude: /node_modules/, loader: 'babel'}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
}
};

0 comments on commit cab5b81

Please sign in to comment.