Skip to content

Commit 80523bd

Browse files
lazehanghustcc
authored andcommitted
added props for google adsense auto full width responsive (#10)
* added props for google adsense auto full width responsive * readme file update
1 parent 376a527 commit 80523bd

File tree

3 files changed

+71
-40
lines changed

3 files changed

+71
-40
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ import AdSense from 'react-adsense';
4848
layout='in-article'
4949
format='fluid'
5050
/>
51+
52+
// auto full width responsive ads
53+
<AdSense.Google
54+
client='ca-pub-7292810486004926'
55+
slot='7806394673'
56+
style={{ display: 'block' }}
57+
format='auto'
58+
responsive='true'
59+
/>
5160
```
5261

5362

@@ -61,6 +70,7 @@ import AdSense from 'react-adsense';
6170
- `style`:
6271
- `layout`:
6372
- `format`:
73+
- `responsive`:
6474

6575

6676
# 4. TODO

lib/google.js

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
'use strict';
22

33
Object.defineProperty(exports, "__esModule", {
4-
value: true
4+
value: true
55
});
66

7-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
7+
var _createClass = function() {
8+
function defineProperties(target, props) {
9+
for (var i = 0; i < props.length; i++) {
10+
var descriptor = props[i];
11+
descriptor.enumerable = descriptor.enumerable || false;
12+
descriptor.configurable = true;
13+
if ("value" in descriptor) descriptor.writable = true;
14+
Object.defineProperty(target, descriptor.key, descriptor);
15+
}
16+
}
17+
return function(Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; };
18+
}();
819

920
var _react = require('react');
1021

@@ -20,52 +31,59 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
2031

2132
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2233

23-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
24-
25-
var Google = function (_React$Component) {
26-
_inherits(Google, _React$Component);
34+
function _inherits(subClass, superClass) {
35+
if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); }
36+
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });
37+
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
38+
}
2739

28-
function Google() {
29-
_classCallCheck(this, Google);
40+
var Google = function(_React$Component) {
41+
_inherits(Google, _React$Component);
3042

31-
return _possibleConstructorReturn(this, (Google.__proto__ || Object.getPrototypeOf(Google)).apply(this, arguments));
32-
}
43+
function Google() {
44+
_classCallCheck(this, Google);
3345

34-
_createClass(Google, [{
35-
key: 'componentDidMount',
36-
value: function componentDidMount() {
37-
if (window) (window.adsbygoogle = window.adsbygoogle || []).push({});
38-
}
39-
}, {
40-
key: 'render',
41-
value: function render() {
42-
return _react2.default.createElement('ins', { className: this.props.className + ' adsbygoogle',
43-
style: this.props.style,
44-
'data-ad-client': this.props.client,
45-
'data-ad-slot': this.props.slot,
46-
'data-ad-layout': this.props.layout,
47-
'data-ad-format': this.props.format });
46+
return _possibleConstructorReturn(this, (Google.__proto__ || Object.getPrototypeOf(Google)).apply(this, arguments));
4847
}
49-
}]);
5048

51-
return Google;
49+
_createClass(Google, [{
50+
key: 'componentDidMount',
51+
value: function componentDidMount() {
52+
if (window)(window.adsbygoogle = window.adsbygoogle || []).push({});
53+
}
54+
}, {
55+
key: 'render',
56+
value: function render() {
57+
return _react2.default.createElement('ins', {
58+
className: this.props.className + ' adsbygoogle',
59+
style: this.props.style,
60+
'data-ad-client': this.props.client,
61+
'data-ad-slot': this.props.slot,
62+
'data-ad-layout': this.props.layout,
63+
'data-ad-format': this.props.format,
64+
'data-full-width-responsive': this.props.responsive
65+
});
66+
}
67+
}]);
68+
69+
return Google;
5270
}(_react2.default.Component);
5371

54-
exports.default = Google;
55-
;
72+
exports.default = Google;;
5673

5774
Google.propTypes = {
58-
className: _propTypes2.default.string,
59-
style: _propTypes2.default.object, // eslint-disable-line
60-
client: _propTypes2.default.string.isRequired,
61-
slot: _propTypes2.default.string.isRequired,
62-
layout: _propTypes2.default.string,
63-
format: _propTypes2.default.string
75+
className: _propTypes2.default.string,
76+
style: _propTypes2.default.object, // eslint-disable-line
77+
client: _propTypes2.default.string.isRequired,
78+
slot: _propTypes2.default.string.isRequired,
79+
layout: _propTypes2.default.string,
80+
format: _propTypes2.default.string,
81+
responsive: _propTypes2.default.string
6482
};
6583

6684
Google.defaultProps = {
67-
className: '',
68-
style: { display: 'block' },
69-
format: 'auto',
70-
layout: ''
85+
className: '',
86+
style: { display: 'block' },
87+
format: 'auto',
88+
responsive: 'false'
7189
};

src/google.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default class Google extends React.Component {
1313
data-ad-client={this.props.client}
1414
data-ad-slot={this.props.slot}
1515
data-ad-layout={this.props.layout}
16-
data-ad-format={this.props.format}></ins>
16+
data-ad-format={this.props.format}
17+
data-full-width-responsive={this.props.responsive}></ins>
1718
);
1819
}
1920
};
@@ -25,11 +26,13 @@ Google.propTypes = {
2526
slot: PropTypes.string.isRequired,
2627
layout: PropTypes.string,
2728
format: PropTypes.string,
29+
responsive: PropTypes.string
2830
};
2931

3032
Google.defaultProps = {
3133
className: '',
3234
style: {display: 'block'},
3335
format: 'auto',
34-
layout: ''
36+
layout: '',
37+
responsive: 'false'
3538
};

0 commit comments

Comments
 (0)