rizzo-next
Version:
The next generation of Lonely Planet's style guide and pattern library.
112 lines (82 loc) • 4.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
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; }; }();
var _bane = require("../../core/bane");
var _jquery = require("jquery");
var _jquery2 = _interopRequireDefault(_jquery);
var _article_body = require("../article_body");
var _article_body2 = _interopRequireDefault(_article_body);
var _social_share = require("../social_share");
var _social_share2 = _interopRequireDefault(_social_share);
var _article_model = require("./article_model");
var _article_model2 = _interopRequireDefault(_article_model);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; }
var ArticleComponent = function (_Component) {
_inherits(ArticleComponent, _Component);
function ArticleComponent() {
_classCallCheck(this, ArticleComponent);
return _possibleConstructorReturn(this, (ArticleComponent.__proto__ || Object.getPrototypeOf(ArticleComponent)).apply(this, arguments));
}
_createClass(ArticleComponent, [{
key: "initialize",
value: function initialize() {
this._setArticle();
}
}, {
key: "_insertInlineAdSlots",
value: function _insertInlineAdSlots($article) {
var $articleBody = $article.find(".js-article-body");
var interval = 6;
var adSlot = function adSlot(adNumber) {
return "\n <div class=\"ad ad--inline ad--article\">\n <div class=\"ad--inline__container\">\n <div class=\"adunit--articles-inline\" id=\"ad-articles-in-article-" + adNumber + "\" />\n </div>\n </div>\n ";
};
var paragraphs = $articleBody.find("p").filter(function (index, p) {
return (!(0, _jquery2.default)(p).attr("class") || (0, _jquery2.default)(p).attr("class") === "feature") && !(0, _jquery2.default)(p).has(".copy--body__strong").length;
});
(0, _jquery2.default)(paragraphs).each(function (index, p) {
var notFirst = index !== 0;
var atEachInterval = (index + 1) % interval === 0;
var adCount = (index + 1) / interval;
if (notFirst && atEachInterval) {
(0, _jquery2.default)(p).after(adSlot(adCount));
}
});
}
}, {
key: "_setArticle",
value: function _setArticle() {
this.socialShareComponent = new _social_share2.default({
el: this.$el.find(".js-action-sheet")
});
var article = new _article_model2.default({
url: window.location.pathname + ".json"
});
var rawArticle = window.lp.article_raw;
article.set(rawArticle);
this.$el.attr("id", this._createIdForArticle(rawArticle.slug));
this._setPoiCallouts(article.get("content").callouts);
this._insertInlineAdSlots(this.$el);
}
}, {
key: "_createIdForArticle",
value: function _createIdForArticle(slug) {
return slug.split("/")[slug.split("/").length - 1];
}
}, {
key: "_setPoiCallouts",
value: function _setPoiCallouts(callouts) {
this.articleBody = new _article_body2.default({
el: this.$el.find(".js-article-body"),
poiData: callouts
});
}
}]);
return ArticleComponent;
}(_bane.Component);
exports.default = ArticleComponent;