You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
2.0 KiB

var EXPO = EXPO || {}; //isolated namespace
EXPO.place = EXPO.place || {};
if (EXPO.place.object){
console.warn('WARNING: EXPO.place.object is already defined!');
}else {
EXPO.place.object = (function () {
// variables
var that = {},
Article = function (opt, it) {
this.$annotation = $('.'+opt.annotationClass, it);
this.$fullPart = $('.'+opt.fullPartClass, it);
this.$readMore = $('.'+opt.readMoreClass, it);
this.cutLength = opt.cutLength;
this.fullText;
this.init();
};
Article.prototype = {
init: function () {
var self = this,
anText = this.$annotation.text().slice(0,self.cutLength);
this.fullText = this.$annotation.html().trim();
this._setMoreLess(this.fullText,self.cutLength, 10)
//this.$annotation.html($.trim(anText));
//this.$fullPart.html($.trim(this.fullText));
},
showMore: function () {
this.$readMore.hide();
this.$annotation.hide();
this.$fullPart.removeClass('hidden');
},
_cutAnnotation: function () {
},
_setMoreLess: function (fullHtml, thrLength, tolerance) {
var alltext = fullHtml;
if (alltext.length + tolerance < thrLength) {
return;
}
else {
var firstHalf = alltext.substring(0, thrLength);
var firstHalfSpan = '<span class="firstHalf">' + firstHalf + '</span>';
this.$annotation.html(firstHalfSpan);
this.$annotation.find("p:last").append("...");
this.$fullPart.html(alltext);
}
}
};
that.opt = {}; //свойства по умолчанию
//private
$(function () {
});
// methods
//инициализация общих свойств
that.init = function (options) {
$.extend(this.opt, options);
var self = this;
this.articles = [];
//readmore on Articles
$('.'+self.opt.article.class).each(function () {
var article = new Article(self.opt.article, this);
article.$readMore.on('click', function () {
article.showMore();
});
self.articles.push(article);
});
};
return that;
}());
}