2012-07-27 12:27:13 -07:00
|
|
|
$('.NB-story img').each(function () {
|
2012-06-28 13:24:40 -07:00
|
|
|
setImage(this);
|
|
|
|
});
|
2012-06-21 11:53:48 -07:00
|
|
|
|
2012-07-27 12:27:13 -07:00
|
|
|
$('.NB-story img').bind('load', function () {
|
2012-06-28 13:24:40 -07:00
|
|
|
setImage(this);
|
|
|
|
});
|
2012-06-21 11:53:48 -07:00
|
|
|
|
2012-07-27 12:27:13 -07:00
|
|
|
$('a.NB-show-profile').live('click', function () {
|
|
|
|
var offset = $('img', this).offset();
|
|
|
|
console.log(offset);
|
|
|
|
var url = $(this).attr('href') + "/" + offset.left + "/" + (offset.top - window.pageYOffset) + "/" + offset.width + "/" + offset.height;
|
|
|
|
window.location = url;
|
|
|
|
return false;
|
2012-12-11 11:50:06 -08:00
|
|
|
});
|
2012-07-03 17:54:36 -07:00
|
|
|
|
2012-07-27 12:27:13 -07:00
|
|
|
$('.NB-button').live('touchstart', function () {
|
2012-08-10 18:10:07 -07:00
|
|
|
$(this).addClass('selected');
|
2012-07-27 12:27:13 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
$('.NB-button').live('touchend', function (e) {
|
2012-08-10 18:10:07 -07:00
|
|
|
$(this).removeClass('selected');
|
2012-07-27 12:27:13 -07:00
|
|
|
});
|
|
|
|
|
2012-06-28 13:24:40 -07:00
|
|
|
function setImage(img) {
|
|
|
|
var $img = $(img);
|
|
|
|
var width = $(img).width();
|
|
|
|
var height = $(img).height();
|
2012-07-27 12:27:13 -07:00
|
|
|
|
|
|
|
if ($img.attr('src').indexOf('feedburner') != - 1) {
|
2012-06-28 13:24:40 -07:00
|
|
|
$img.attr('class', 'NB-feedburner');
|
|
|
|
} else if (width > 300 && height > 50) {
|
|
|
|
$img.attr('class', 'NB-large-image');
|
|
|
|
if ($img.parent().attr('href')) {
|
|
|
|
$img.parent().addClass('NB-contains-image')
|
|
|
|
}
|
2012-07-27 12:27:13 -07:00
|
|
|
} else if (width > 30 && height > 30) {
|
2012-06-28 13:24:40 -07:00
|
|
|
$img.attr('class', 'NB-medium-image');
|
|
|
|
if ($img.parent().attr('href')) {
|
|
|
|
$img.parent().addClass('NB-contains-image')
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$img.attr('class', 'NB-small-image');
|
|
|
|
}
|
|
|
|
}
|
2012-06-21 11:53:48 -07:00
|
|
|
|
2012-07-30 14:58:57 -07:00
|
|
|
function slideToComment(commentId, highlight) {
|
2012-08-01 12:41:02 -07:00
|
|
|
setTimeout(function(){
|
|
|
|
var commentString = 'NB-user-comment-' + commentId;
|
|
|
|
var shareString = 'NB-user-share-bar-' + commentId;
|
|
|
|
//Get comment
|
|
|
|
var $comment = $('#' + commentString);
|
|
|
|
if ($comment.length) {
|
2012-11-13 12:28:16 -08:00
|
|
|
$.scroll($comment.offset().top - 32, 1000, 'ease-in-out');
|
2012-08-01 12:41:02 -07:00
|
|
|
} else {
|
|
|
|
var $shareBar = $('#' + shareString);
|
|
|
|
if ($shareBar.length) {
|
2012-11-13 12:28:16 -08:00
|
|
|
$.scroll($shareBar.offset().top - 32, 1000, 'ease-in-out');
|
2012-08-01 12:41:02 -07:00
|
|
|
} else {
|
|
|
|
var $shareButton =$("#NB-share-button-id");
|
2012-11-13 12:28:16 -08:00
|
|
|
$.scroll($shareButton.offset().top - 32, 1000, 'ease-in-out');
|
2012-08-01 12:41:02 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 14:58:57 -07:00
|
|
|
|
2012-08-01 12:41:02 -07:00
|
|
|
if (highlight) {
|
|
|
|
if ($comment.length) {
|
|
|
|
setTimeout(function(){
|
|
|
|
$comment.addClass('NB-highlighted');
|
|
|
|
setTimeout(function(){
|
|
|
|
$comment.removeClass('NB-highlighted');
|
|
|
|
}, 2000);
|
|
|
|
}, 1000);
|
|
|
|
} else if ($shareBar.length) {
|
2012-07-30 14:58:57 -07:00
|
|
|
|
2012-08-01 12:41:02 -07:00
|
|
|
setTimeout(function(){
|
|
|
|
$(".NB-story-comments-shares-teaser").addClass('NB-highlighted');
|
|
|
|
setTimeout(function(){
|
|
|
|
$(".NB-story-comments-shares-teaser").removeClass('NB-highlighted');
|
|
|
|
}, 2000);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
|
2012-07-30 14:58:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function findPos(obj) {
|
|
|
|
var curtop = 0;
|
|
|
|
if (obj.offsetParent) {
|
|
|
|
do {
|
|
|
|
curtop += obj.offsetTop;
|
|
|
|
} while (obj = obj.offsetParent);
|
|
|
|
return [curtop];
|
|
|
|
}
|
2012-12-10 20:22:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function NoClickDelay(el) {
|
|
|
|
this.element = typeof el == 'object' ? el : document.getElementById(el);
|
|
|
|
if( window.Touch ) this.element.addEventListener('touchstart', this, false);
|
|
|
|
}
|
|
|
|
NoClickDelay.prototype = {
|
|
|
|
handleEvent: function(e) {
|
|
|
|
switch(e.type) {
|
|
|
|
case 'touchstart': this.onTouchStart(e); break;
|
|
|
|
case 'touchmove': this.onTouchMove(e); break;
|
|
|
|
case 'touchend': this.onTouchEnd(e); break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onTouchStart: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.moved = false;
|
|
|
|
this.x = e.targetTouches[0].clientX;
|
|
|
|
this.y = e.targetTouches[0].clientY;
|
|
|
|
this.theTarget = document.elementFromPoint(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
|
2012-12-11 11:50:06 -08:00
|
|
|
this.theTarget = $(this.theTarget).closest('a').get(0);
|
|
|
|
// if(this.theTarget.nodeType == 3) this.theTarget = theTarget.parentNode;
|
2012-12-10 20:22:21 -08:00
|
|
|
this.theTarget.className+= ' pressed';
|
|
|
|
this.element.addEventListener('touchmove', this, false);
|
|
|
|
this.element.addEventListener('touchend', this, false);
|
|
|
|
},
|
|
|
|
onTouchMove: function(e) {
|
|
|
|
var x = e.targetTouches[0].clientX;
|
|
|
|
var y = e.targetTouches[0].clientY;
|
|
|
|
if( Math.sqrt(Math.pow(x-this.x,2)+Math.pow(y-this.y,2))>50){
|
|
|
|
this.moved = true;
|
|
|
|
this.theTarget.className = this.theTarget.className.replace(/ ?pressed/gi, '');
|
|
|
|
this.theTarget.className = this.theTarget.className.replace(/ ?active/gi, '');
|
|
|
|
} else {
|
|
|
|
if(this.moved==true){
|
|
|
|
this.moved=false;
|
|
|
|
this.theTarget.className+= ' pressed';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onTouchEnd: function(e) {
|
|
|
|
this.element.removeEventListener('touchmove', this, false);
|
|
|
|
this.element.removeEventListener('touchend', this, false);
|
|
|
|
if( !this.moved && this.theTarget ) {
|
|
|
|
this.theTarget.className = this.theTarget.className.replace(/ ?pressed/gi, '');
|
|
|
|
this.theTarget.className+= ' active';
|
|
|
|
var theEvent = document.createEvent('MouseEvents');
|
|
|
|
theEvent.initEvent('click', true, true);
|
|
|
|
this.theTarget.dispatchEvent(theEvent);
|
|
|
|
}
|
|
|
|
this.theTarget = undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function attachFastClick() {
|
2012-12-11 11:50:06 -08:00
|
|
|
var avatars = document.getElementsByClassName("NB-show-profile");
|
|
|
|
Array.prototype.slice.call(avatars, 0).forEach(function(avatar) {
|
|
|
|
new NoClickDelay(avatar);
|
|
|
|
});
|
2012-12-10 20:22:21 -08:00
|
|
|
var tags = document.getElementsByClassName("NB-story-tag");
|
|
|
|
Array.prototype.slice.call(tags, 0).forEach(function(tag) {
|
2012-12-11 11:50:06 -08:00
|
|
|
new NoClickDelay(tag);
|
|
|
|
});
|
|
|
|
|
|
|
|
var author = document.getElementById("NB-story-author");
|
|
|
|
if (author) {
|
|
|
|
new NoClickDelay(author);
|
|
|
|
}
|
2012-12-10 20:22:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Zepto(function($) {
|
|
|
|
attachFastClick();
|
2012-12-11 11:50:06 -08:00
|
|
|
});
|