comunic/assets/js/metro/metro-tile-transform.js

66 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2016-11-19 11:08:12 +00:00
(function( $ ) {
$.widget("metro.tileTransform", {
version: "1.0.0",
options: {
},
_create: function(){
var element = this.element;
var dim = {w: element.width(), h: element.height()};
element.on('click', function(e){
// e.preventDefault();
// if (element[0].tagName == 'A' && element.attr('href')) {
// document.location.href = element.attr('href');
// }
});
element.on('mousedown', function(e){
var X = e.pageX - $(this).offset().left, Y = e.pageY - $(this).offset().top;
var transform = 'top';
if (X < dim.w * 1/3 && (Y < dim.h * 1/2 || Y > dim.h * 1/2 )) {
transform = 'left';
} else if (X > dim.w * 2/3 && (Y < dim.h * 1/2 || Y > dim.h * 1/2 )) {
transform = 'right'
} else if (X > dim.w*1/3 && X<dim.w*2/3 && Y > dim.h/2) {
transform = 'bottom';
}
$(this).addClass("tile-transform-"+transform);
if (element[0].tagName == 'A' && element.attr('href')) {
setTimeout(function(){
document.location.href = element.attr('href');
}, 500);
}
});
element.on('mouseup', function(){
$(this)
.removeClass("tile-transform-left")
.removeClass("tile-transform-right")
.removeClass("tile-transform-top")
.removeClass("tile-transform-bottom");
});
element.on('mouseleave', function(){
$(this)
.removeClass("tile-transform-left")
.removeClass("tile-transform-right")
.removeClass("tile-transform-top")
.removeClass("tile-transform-bottom");
});
},
_destroy: function(){
},
_setOption: function(key, value){
this._super('_setOption', key, value);
}
})
})( jQuery );