2016-01-06 05:11:07 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react');
|
|
|
|
var ReactDOM = require("react-dom");
|
2016-01-06 05:29:08 +03:00
|
|
|
var Tinter = require("../../../Tinter");
|
2016-01-06 05:11:07 +03:00
|
|
|
|
2016-04-16 03:00:10 +03:00
|
|
|
var TintableSvg = React.createClass({
|
2016-01-06 05:11:07 +03:00
|
|
|
displayName: 'TintableSvg',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
src: React.PropTypes.string.isRequired,
|
|
|
|
width: React.PropTypes.string.isRequired,
|
|
|
|
height: React.PropTypes.string.isRequired,
|
|
|
|
className: React.PropTypes.string,
|
|
|
|
},
|
|
|
|
|
2016-04-16 03:00:10 +03:00
|
|
|
statics: {
|
|
|
|
// list of currently mounted TintableSvgs
|
|
|
|
mounts: {},
|
|
|
|
idSequence: 0,
|
|
|
|
},
|
|
|
|
|
2016-01-07 06:39:00 +03:00
|
|
|
componentWillMount: function() {
|
2016-01-07 13:18:18 +03:00
|
|
|
this.fixups = [];
|
2016-01-07 06:39:00 +03:00
|
|
|
},
|
|
|
|
|
2016-01-06 05:11:07 +03:00
|
|
|
componentDidMount: function() {
|
2016-04-16 03:00:10 +03:00
|
|
|
this.id = TintableSvg.idSequence++;
|
|
|
|
TintableSvg.mounts[this.id] = this;
|
2016-01-06 05:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2016-04-16 03:00:10 +03:00
|
|
|
delete TintableSvg.mounts[this.id];
|
2016-01-07 06:39:00 +03:00
|
|
|
},
|
|
|
|
|
2016-04-16 03:00:10 +03:00
|
|
|
tint: function() {
|
|
|
|
// TODO: only bother running this if the global tint settings have changed
|
|
|
|
// since we loaded!
|
2016-01-07 06:59:09 +03:00
|
|
|
Tinter.applySvgFixups(this.fixups);
|
2016-01-06 05:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onLoad: function(event) {
|
2016-04-16 03:00:10 +03:00
|
|
|
// console.log("TintableSvg.onLoad for " + this.props.src);
|
2016-01-07 06:59:09 +03:00
|
|
|
this.fixups = Tinter.calcSvgFixups([event.target]);
|
|
|
|
Tinter.applySvgFixups(this.fixups);
|
2016-01-06 05:11:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
2016-04-14 23:44:05 +03:00
|
|
|
<object className={ "mx_TintableSvg " + (this.props.className ? this.props.className : "") }
|
2016-01-06 05:11:07 +03:00
|
|
|
type="image/svg+xml"
|
|
|
|
data={ this.props.src }
|
|
|
|
width={ this.props.width }
|
2016-04-17 23:46:27 +03:00
|
|
|
height={ this.props.height }
|
|
|
|
onLoad={ this.onLoad }
|
|
|
|
/>
|
2016-01-06 05:11:07 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2016-04-16 03:00:10 +03:00
|
|
|
|
2016-04-17 23:46:27 +03:00
|
|
|
module.exports = TintableSvg;
|