Authored by 2586703@qq.com

截行插件

... ... @@ -2,7 +2,8 @@ define('channel', function(require, exports) {
var swipe = require("plugins/swipe"),
$ = require("jquery"),
freetile = require("lib/ui/jquery.freetile"),
share = require('plugins/share');
share = require('plugins/share'),
mlellipsis = require('plugins/mlellipsis');
require("plugins/pagination");
require("plugins/slider");
... ... @@ -216,6 +217,11 @@ define('channel', function(require, exports) {
}
});
mlellipsis.init();
$('.text-content').each(function()) {
$(this)[0].mlellipsis(2);
}
};
//品牌
exports.brand = function() {
... ...
define('plugins/mlellipsis', function(require, exports) {
exports.init = function() {
/*
* @author:tqtan
* @date:13/10/10
* @name:实现多行省略
*
*/
/*
* @method:node.mlellipsis(row)
* @node:dom节点
* @row:行数
*
*/
Element.prototype.getText = function() {
if (this.innerText == undefined) {
return this.textContent;
} else {
return this.innerText;
}
}
Element.prototype.setText = function(str) {
if (this.innerText == undefined) {
this.textContent = str || "";
} else {
this.innerText = str || "";
}
}
Element.prototype.getFinalStyle = function(property, fontSize) {
var s;
if (window.getComputedStyle) {
s = window.getComputedStyle(this, null)[property];
} else {
s = this.currentStyle[property];
}
//兼容IEbug:IE解析getComputedStyle或currentStyle,然而若line-height=1.5,它会获取计算后是1.5,而其他浏览器获得1.5*line-height
if (fontSize != undefined) {
s = s * fontSize + "px";
}
return s.substring(0, s.toString().length - 2);
}
Element.prototype.mlellipsis = function(row) {
//省略后加上title
var str = this.getText();
var title = this.getAttribute("title");
if (title == null) {
this.setAttribute("title", str);
} else {
this.setText(title);
}
//获取计算后的样式
var fontSize = this.getFinalStyle("fontSize");
if (/msie/i.test(navigator.userAgent)) {
var lineHeight = this.getFinalStyle("lineHeight", fontSize);
} else {
var lineHeight = this.getFinalStyle("lineHeight");
}
var height = this.clientHeight;
if (lineHeight == "norm") {
lineHeight = Number(fontSize * 1.5);
this.setAttribute("style", "line-height:" + lineHeight + "px");
} else {
lineHeight = Number(lineHeight);
}
//若高度足够,则不用省略
var dheight = Math.floor(row * lineHeight);
if (height >= dheight) {
str = this.getText();
while (dheight * 3 < this.clientHeight) {
this.setText(str.substring(0, str.length / 2));
str = this.getText();
}
//减去末尾文字
while (dheight < this.clientHeight) {
str = this.getText();
this.setText(str.replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
}
}
}
Element.prototype.getTextLineNumber = function(row) {
//省略后加上title
var str = this.getText();
var title = this.getAttribute("title");
if (title == null) {
this.setAttribute("title", str);
} else {
this.setText(title);
}
//获取计算后的样式
var fontSize = this.getFinalStyle("fontSize");
if (/msie/i.test(navigator.userAgent)) {
var lineHeight = this.getFinalStyle("lineHeight", fontSize);
} else {
var lineHeight = this.getFinalStyle("lineHeight");
}
var height = this.clientHeight;
if (lineHeight == "norm") {
lineHeight = Number(fontSize * 1.5);
this.setAttribute("style", "line-height:" + lineHeight + "px");
} else {
lineHeight = Number(lineHeight);
}
return height / lineHeight;
//若高度足够,则不用省略
/* var dheight = Math.floor(row*lineHeight);
if(height >= dheight){
str = this.getText();
while(dheight*3<this.clientHeight){
this.setText(str.substring(0,str.length/2));
str = this.getText();
}
//减去末尾文字
while(dheight<this.clientHeight){
str = this.getText();
this.setText(str.replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/,"..."));
}
}*/
}
/*
* /(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/ 正则:
* (\s)* 0或多个空白
* ([a-zA-Z0-9]+|\W) 一个或多个字母数字 或 任意不是字母,数字,汉字的字符
* (\.\.\.)? 零个或一个...
*/
}
});
\ No newline at end of file
... ...
... ... @@ -27,17 +27,17 @@ else
<div class="image-box">
<a href="<?php echo url('news/detail' ,array('id' => $news['id']))?>" title="<?php echo $news['title'];?>">
<img src="<?php echo $thumb;?>" alt="" style="<?php echo sprintf("height:%spx;width:%spx;", $height, $width);?>">
<i class="play-icon"></i>
</a>
<a class="item-tag" href="<?php echo url('news/index',array('tag' => $news['tag']))?>"><?php echo $news['tag'];?></a>
<?php if(trim($news['tag']) == '视频'):?>
<i class="play-icon"></i>
<?php endif;?>
</div>
<div class="content">
<h2 <?php echo $news['main_title_type'] == 1 ? 'class="volupia"':'';?>>
<a href="<?php echo url('news/detail' ,array('id' => $news['id']))?>"><?php echo $news['title'];?></a>
</h2>
<p><?php echo $description;?></p>
<p class="text-content"><?php echo $description;?></p>
<p class="time"><?php echo date('Y.m.d', $news['create_time'])?></p>
</div>
</div>
... ...