Commit ff0ad167 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

мобильный скролл.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@54188 954022d7-b5bf-4e40-9824-e11837661b57
parent 0e124c57
......@@ -32,7 +32,6 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
this.topLineEditorElement = null;
this.isViewerMode = false;
this.controller = null; // Создадим позднее, т.к. не знаем мобильная версия или нет
// if ("function" === typeof(eventsController)) {
// var prot = eventsController.prototype;
......@@ -42,10 +41,10 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
// prot.reinitializeScroll = prot["reinitializeScroll"];
// prot.scrollVertical = prot["scrollVertical"];
// prot.scrollHorizontal = prot["scrollHorizontal"];
//
// this.controller = new eventsController();
// } else {
// this.controller = new asc.asc_CEventsController();
this.controller = new asc.asc_CEventsController();
// }
this.handlers = new asc.asc_CHandlersList(eventsHandlers);
......@@ -506,7 +505,7 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
asc_OpenDocument: function(url, data)
{
this._initEventController();
// this._initEventController();
var wb = new Workbook(url, this.handlers, this);
this.initGlobalObjects(wb);
......@@ -721,8 +720,8 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
asc_setViewerMode: function (isViewerMode) {
this.isViewerMode = isViewerMode;
// Если нет controller-а, мы выставим позднее режим
if (null !== this.controller)
this.controller.setViewerMode(isViewerMode);
// if (null !== this.controller)
// this.controller.setViewerMode(isViewerMode);
if (this.collaborativeEditing)
this.collaborativeEditing.setViewerMode(isViewerMode);
......@@ -1232,8 +1231,8 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
},
asc_getController: function() {
//return this.controller;
return null;
return this.controller;
// return null;
},
// Посылает эвент о том, что обновились листы
......
......@@ -130,6 +130,8 @@
<script type="text/javascript" src="../../../../OfficeWeb/Excel/model/UndoRedo.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/scroll.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/mobileTouch.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/iscroll.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/StringRender.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellTextRender.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellEditorView.js"></script>
......
......@@ -93,6 +93,7 @@
this.vsbApiLockMouse = false;
this.hsbApiLockMouse = false;
return this;
}
......@@ -112,7 +113,23 @@
this.element = canvasElem;
this.handlers = new asc.asc_CHandlersList(handlers);
this.settings = $.extend(true, {}, this.settings, settings);
if( this.view.Api.isMobileVersion ){
var __hasTouch = 'ontouchstart' in window;
if (__hasTouch)
{
this.element.addEventListener("touchstart" , function (e) {self._onTouchStart(e); return false;} , false);
this.element.addEventListener("touchmove" , function (e) {self._onTouchMove(e); return false;} , false);
this.element.addEventListener("touchend" , function (e) {self._onTouchEnd(e); return false;} , false);
}
else{
this.element.addEventListener("touchstart" , function (e) {self._onMouseDown(e.touches[0]); return false;} , false);
this.element.addEventListener("touchmove" , function (e) {self._onMouseMove(e.touches[0]); return false;} , false);
this.element.addEventListener("touchend" , function (e) {self._onMouseUp(e.changedTouches[0]); return false;} , false);
}
// this.element.addEventListener("dblclick" , function () {alert("123");/*return self._onMouseDblClick.apply(self, arguments);*/} , false);
return;
}
this._createScrollBars();
// initialize events
......@@ -147,14 +164,17 @@
// for Mozilla Firefox (можно делать проверку на window.MouseScrollEvent || window.WheelEvent для FF)
this.element.addEventListener("DOMMouseScroll", function () {return self._onMouseWheel.apply(self, arguments);} , false);
if(!this.view.Api.isMobileVersion){
this.element.addEventListener("touchstart" , function (e) {self._onMouseDown(e.touches[0]); return false;} , false);
this.element.addEventListener("touchmove" , function (e) {self._onMouseMove(e.touches[0]); return false;} , false);
this.element.addEventListener("touchend" , function (e) {self._onMouseUp(e.changedTouches[0]); return false;} , false);
}
}
// Курсор для графических объектов. Определяем mousedown и mouseup для выделения текста.
var oShapeCursor = document.getElementById("id_target_cursor");
if (null != oShapeCursor && oShapeCursor.addEventListener) {
if (null != oShapeCursor && oShapeCursor.addEventListener && !this.view.Api.isMobileVersion) {
oShapeCursor.addEventListener("mousedown" , function () {return self._onMouseDown.apply(self, arguments);}, false);
oShapeCursor.addEventListener("mouseup" , function () {return self._onMouseUp.apply(self, arguments);} , false);
oShapeCursor.addEventListener("mousemove" , function () {return self._onMouseMove.apply(self, arguments);}, false);
......@@ -223,11 +243,13 @@
this.handlers.trigger("reinitializeScroll", whichSB, function (vSize, hSize) {
if (isVert) {
vSize = self.vsb.offsetHeight + Math.max(vSize * opt.vscrollStep, 1);
// this.m_dScrollY_max = vSize;
self.vsbHSt.height = vSize + "px";
self.vsbApi.Reinit(opt, opt.vscrollStep * ws.getFirstVisibleRow(/*allowPane*/true));
}
if (isHoriz) {
hSize = self.hsb.offsetWidth + Math.max(hSize * opt.hscrollStep, 1);
// this.m_dScrollX_max = hSize ;
self.hsbHSt.width = hSize + "px";
self.hsbApi.Reinit(opt, opt.vscrollStep * ws.getFirstVisibleCol(/*allowPane*/true));
}
......@@ -1463,6 +1485,16 @@
return {x: x, y: y};
};
asc_CEventsController.prototype._onTouchStart = function (event){
this.view.MobileTouchManager.onTouchStart(event);
}
asc_CEventsController.prototype._onTouchMove = function (event){
var n = new Date().getTime()
this.view.MobileTouchManager.onTouchMove(event);
}
asc_CEventsController.prototype._onTouchEnd = function (event){
this.view.MobileTouchManager.onTouchEnd(event);
}
/*
* Export
......
......@@ -109,6 +109,13 @@
this.defaultFont = new asc_FP(this.model.getDefaultFont(), this.model.getDefaultSize());
//-----------------------
this.m_dScrollY = 0;
this.m_dScrollX = 0;
this.m_dScrollY_max = 1;
this.m_dScrollX_max = 1;
this.MobileTouchManager = null;
this._init(fontRenderingMode);
return this;
......@@ -394,6 +401,11 @@
this.clipboard.Api = this.Api;
this.clipboard.init();
if (this.Api.isMobileVersion){
this.MobileTouchManager = new CMobileTouchManager();
this.MobileTouchManager.Init(this);
}
return this;
};
......@@ -462,20 +474,36 @@
var ws = this.getWorksheet(),
vsize = !whichSB || whichSB === 1 ? ws.getVerticalScrollRange() : undefined,
hsize = !whichSB || whichSB === 2 ? ws.getHorizontalScrollRange() : undefined;
if( vsize != undefined )
this.m_dScrollY_max = /*this.canvas.offsetHeight +*/ Math.max(this.controller.settings.vscrollStep * vsize, 1);
if( hsize != undefined )
this.m_dScrollX_max = /*this.canvas.offsetWidth +*/ Math.max(this.controller.settings.hscrollStep * hsize, 1);
if(this.Api.isMobileVersion){
this.MobileTouchManager.Resize();
return;
}
asc_applyFunction(callback, vsize, hsize);
};
WorkbookView.prototype._onScrollY = function (pos) {
console.log("_onScrollY " + pos)
// document.getElementById("cv1" ).value = "_onScrollY " + pos;
var ws = this.getWorksheet();
var delta = asc_round(pos - ws.getFirstVisibleRow(/*allowPane*/true));
console.log("deltaY " + delta)
if (delta !== 0) {
ws.scrollVertical(delta, this.cellEditor);
}
};
WorkbookView.prototype._onScrollX = function (pos) {
console.log("_onScrollX " + pos)
// document.getElementById("cv1" ).value = "_onScrollX " + pos;
var ws = this.getWorksheet();
var delta = asc_round(pos - ws.getFirstVisibleCol(/*allowPane*/true));
console.log("deltaX " + delta)
if (delta !== 0) {
ws.scrollHorizontal(delta, this.cellEditor);
}
......@@ -1144,8 +1172,8 @@
WorkbookView.prototype._canResize = function () {
var oldWidth = this.canvas.width;
var oldHeight = this.canvas.height;
var width = this.element.offsetWidth - this.defaults.scroll.widthPx;
var height = this.element.offsetHeight - this.defaults.scroll.heightPx;
var width = this.element.offsetWidth - (this.Api.isMobileVersion ? 0 : this.defaults.scroll.widthPx);
var height = this.element.offsetHeight - (this.Api.isMobileVersion ? 0 : this.defaults.scroll.heightPx);
if (oldWidth === width && oldHeight === height)
return false;
......
/*!
* iScroll v4.2.5 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org
* Released under MIT license, http://cubiq.org/license
*/
(function ( window, doc ) {
var m = Math,
dummyStyle = doc.createElement( 'div' ).style,
vendor = (function () {
var vendors = 't,webkitT,MozT,msT,OT'.split( ',' ),
t,
i = 0,
l = vendors.length;
for ( ; i < l; i++ ) {
t = vendors[i] + 'ransform';
if ( t in dummyStyle ) {
return vendors[i].substr( 0, vendors[i].length - 1 );
}
}
return false;
})(),
cssVendor = vendor ? '-' + vendor.toLowerCase() + '-' : '',
// Style properties
transform = prefixStyle( 'transform' ),
transitionProperty = prefixStyle( 'transitionProperty' ),
transitionDuration = prefixStyle( 'transitionDuration' ),
transformOrigin = prefixStyle( 'transformOrigin' ),
transitionTimingFunction = prefixStyle( 'transitionTimingFunction' ),
transitionDelay = prefixStyle( 'transitionDelay' ),
// Browser capabilities
isAndroid = (/android/gi).test( navigator.appVersion ),
isIDevice = (/iphone|ipad/gi).test( navigator.appVersion ),
isTouchPad = (/hp-tablet/gi).test( navigator.appVersion ),
has3d = prefixStyle( 'perspective' ) in dummyStyle,
hasTouch = 'ontouchstart' in window && !isTouchPad,
hasTransform = vendor !== false,
hasTransitionEnd = prefixStyle( 'transition' ) in dummyStyle,
TRNEND_EV = (function () {
if ( vendor === false ) return false;
var transitionEnd = {
'':'transitionend',
'webkit':'webkitTransitionEnd',
'Moz':'transitionend',
'O':'otransitionend',
'ms':'MSTransitionEnd'
};
return transitionEnd[vendor];
})(),
nextFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function ( callback ) {
return setTimeout( callback, 1 );
};
})(),
cancelFrame = (function () {
return window.cancelRequestAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame ||
clearTimeout;
})(),
// Helpers
translateZ = has3d ? ' translateZ(0)' : '',
// Constructor
CTouchScroll = function ( api, options, scroller ) {
var that = this,
i;
var o = {m_oMainView:{},m_oEditor:{},m_oScrollVerApi:{}}
o.m_oMainView.HtmlElement = o.m_oEditor.HtmlElement = api.canvasOverlay;
o.m_dDocumentWidth = api.canvas.width;
o.m_dDocumentHeight = api.canvas.height;
that.api = api;
that.wrapper = api.element;
that.wrapper.style.overflow = 'hidden';
that.scroller = (scroller !== undefined) ? scroller : null;
// Default options
that.options = {
hScroll:true,
vScroll:true,
x:0,
y:0,
bounce:false,
bounceLock:false,
momentum:true,
lockDirection:true,
useTransform:true,
useTransition:false,
topOffset:0,
checkDOMChanges:false, // Experimental
handleClick:true,
// Scrollbar
hScrollbar:true,
vScrollbar:true,
fixedScrollbar:isAndroid,
hideScrollbar:/*isIDevice*/true,
fadeScrollbar:isIDevice && has3d,
scrollbarClass:'',
// Zoom
zoom:false,
zoomMin:1,
zoomMax:4,
doubleTapZoom:2,
wheelAction:'scroll',
// Snap
snap:false,
snapThreshold:1,
// Events
onRefresh:null,
onBeforeScrollStart:null,
onScrollStart:null,
onBeforeScrollMove:null,
onScrollMove:null,
onBeforeScrollEnd:null,
onScrollEnd:null,
onTouchEnd:null,
onDestroy:null,
onZoomStart:null,
onZoom:null,
onZoomEnd:null
};
// User defined options
for ( i in options ) that.options[i] = options[i];
// Set starting position
that.x = that.options.x;
that.y = that.options.y;
// Normalize options
that.options.useTransform = hasTransform && that.options.useTransform;
that.options.hScrollbar = that.options.hScroll && that.options.hScrollbar;
that.options.vScrollbar = that.options.vScroll && that.options.vScrollbar;
that.options.zoom = that.options.useTransform && that.options.zoom;
that.options.useTransition = hasTransitionEnd && that.options.useTransition;
// Helpers FIX ANDROID BUG!
// translate3d and scale doesn't work together!
// Ignoring 3d ONLY WHEN YOU SET that.options.zoom
if ( that.options.zoom && isAndroid ) {
translateZ = '';
}
// Set some default styles
if ( that.scroller ) {
that.scroller.style[transitionProperty] = that.options.useTransform ? cssVendor + 'transform' : 'top left';
that.scroller.style[transitionDuration] = '0';
that.scroller.style[transformOrigin] = '0 0';
if ( that.options.useTransition )
that.scroller.style[transitionTimingFunction] = 'cubic-bezier(0.33,0.66,0.66,1)';
if ( that.options.useTransform )
that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px)' + translateZ;
else
that.scroller.style.cssText += ';position:absolute;top:' + that.y + 'px;left:' + that.x + 'px';
}
if ( that.options.useTransition )
that.options.fixedScrollbar = true;
that.refresh();
};
// Prototype
CTouchScroll.prototype = {
enabled:true,
x:0,
y:0,
steps:[],
scale:1,
currPageX:0, currPageY:0,
pagesX:[], pagesY:[],
aniTime:null,
wheelZoomCount:0,
handleEvent:function ( e ) {
var that = this;
switch ( e.type ) {
case TRNEND_EV:
that._transitionEnd( e );
break;
}
},
_scrollbar:function ( dir ) {
var that = this,
bar;
if ( dir == 'h' ) {
if ( !that.hScrollbar ) {
if ( that.hScrollbarWrapper ) {
if ( hasTransform )
that.hScrollbarIndicator.style[transform] = '';
that.hScrollbarWrapper.parentNode.removeChild( that.hScrollbarWrapper );
that.hScrollbarWrapper = null;
that.hScrollbarIndicator = null;
}
return;
}
if ( !that.hScrollbarWrapper ) {
// Create the scrollbar wrapper
bar = doc.createElement( 'div' );
if ( that.options.scrollbarClass )
bar.className = that.options.scrollbarClass + dir.toUpperCase();
else
bar.style.cssText = 'position:absolute;z-index:100;height:7px;bottom:1px;left:2px;right:' + (that.vScrollbar ? '7' : '2') + 'px';
bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:opacity;' + cssVendor + 'transition-duration:' + (that.options.fadeScrollbar ? '350ms' : '0') + ';overflow:hidden;opacity:' + (that.options.hideScrollbar ? '0' : '1');
that.wrapper.appendChild( bar );
that.hScrollbarWrapper = bar;
// Create the scrollbar indicator
bar = doc.createElement( 'div' );
if ( !that.options.scrollbarClass ) {
bar.style.cssText = 'position:absolute;z-index:100;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);' + cssVendor + 'background-clip:padding-box;' + cssVendor + 'box-sizing:border-box;height:100%;' + cssVendor + 'border-radius:3px;border-radius:3px';
}
bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:' + cssVendor + 'transform;' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1);' + cssVendor + 'transition-duration:0;' + cssVendor + 'transform: translate(0,0)' + translateZ;
if ( that.options.useTransition )
bar.style.cssText += ';' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1)';
that.hScrollbarWrapper.appendChild( bar );
that.hScrollbarIndicator = bar;
}
that.hScrollbarSize = that.hScrollbarWrapper.clientWidth;
that.hScrollbarIndicatorSize = m.max( m.round( that.hScrollbarSize * that.hScrollbarSize / that.scrollerW ), 8 );
that.hScrollbarIndicator.style.width = that.hScrollbarIndicatorSize + 'px';
that.hScrollbarMaxScroll = that.hScrollbarSize - that.hScrollbarIndicatorSize;
that.hScrollbarProp = that.hScrollbarMaxScroll / that.maxScrollX;
// Reset position
that._scrollbarPos( dir, true );
}
else if ( dir == 'v' ) {
if ( !that.vScrollbar ) {
if ( that.vScrollbarWrapper ) {
if ( hasTransform )
that.vScrollbarIndicator.style[transform] = '';
that.vScrollbarWrapper.parentNode.removeChild( that.vScrollbarWrapper );
that.vScrollbarWrapper = null;
that.vScrollbarIndicator = null;
}
return;
}
if ( !that.vScrollbarWrapper ) {
// Create the scrollbar wrapper
bar = doc.createElement( 'div' );
if ( that.options.scrollbarClass )
bar.className = that.options.scrollbarClass + dir.toUpperCase();
else
bar.style.cssText = 'position:absolute;z-index:100;width:7px;bottom:' + (that.hScrollbar ? '7' : '2') + 'px;top:2px;right:1px';
bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:opacity;' + cssVendor + 'transition-duration:' + (that.options.fadeScrollbar ? '350ms' : '0') + ';overflow:hidden;opacity:' + (that.options.hideScrollbar ? '0' : '1');
that.wrapper.appendChild( bar );
that.vScrollbarWrapper = bar;
// Create the scrollbar indicator
bar = doc.createElement( 'div' );
if ( !that.options.scrollbarClass ) {
bar.style.cssText = 'position:absolute;z-index:100;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);' + cssVendor + 'background-clip:padding-box;' + cssVendor + 'box-sizing:border-box;width:100%;' + cssVendor + 'border-radius:3px;border-radius:3px';
}
bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:' + cssVendor + 'transform;' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1);' + cssVendor + 'transition-duration:0;' + cssVendor + 'transform: translate(0,0)' + translateZ;
if ( that.options.useTransition )
bar.style.cssText += ';' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1)';
that.vScrollbarWrapper.appendChild( bar );
that.vScrollbarIndicator = bar;
}
// var percentInViewV = (m.abs(that.maxScrollY) + that.vScrollbarWrapper.clientHeight ) / that.vScrollbarWrapper.clientHeight;
// that.vScrollbarIndicatorSize = m.max(Math.ceil( 1 / percentInViewV * that.vScrollbarWrapper.clientHeight ),8)
that.vScrollbarSize = that.vScrollbarWrapper.clientHeight;
that.vScrollbarIndicatorSize = m.max( m.round( that.vScrollbarSize * that.vScrollbarSize / that.scrollerH ), 8 );
that.vScrollbarIndicator.style.height = that.vScrollbarIndicatorSize + 'px';
that.vScrollbarMaxScroll = that.vScrollbarSize - that.vScrollbarIndicatorSize;
that.vScrollbarProp = that.vScrollbarSize / that.maxScrollY;
// Reset position
that._scrollbarPos( dir, true );
}
},
_resize:function () {
var that = this;
setTimeout( function () {
that.refresh();
}, isAndroid ? 200 : 0 );
},
_pos:function ( x, y, isAnim ) {
if ( this.zoomed ) return;
console.log("this.maxScrollY " + this.maxScrollY);
console.log("this.maxScrollX " + this.maxScrollX);
x = this.hScroll ? x : 0;
y = this.vScroll ? y : 0;
this.x = x;
this.y = y;
if ( isAnim === true ) {
this.api.NoneRepaintPages = true;
}
else {
this.api.NoneRepaintPages = false;
}
if ( this.api.ReaderModeDiv == null ) {
if ( this.hScroll ) {
this.api._onScrollX( -this.x );
}
if ( this.vScroll ) {
this.api._onScrollY( -this.y );
}
}
else if ( this.scroller ) {
if ( this.options.useTransform ) {
this.scroller.style[transform] = 'translate(' + x + 'px,' + y + 'px) scale(' + this.scale + ')' + translateZ;
}
else {
x = m.round( x );
y = m.round( y );
this.scroller.style.left = x + 'px';
this.scroller.style.top = y + 'px';
}
}
this._scrollbarPos( 'h' );
this._scrollbarPos( 'v' );
},
_scrollbarPos:function ( dir, hidden ) {
var that = this;
var size = 0;
var pos = that.y;
if ( dir == 'h' ) {
pos = that.x;
if ( !that.hScrollbar )
return;
pos = that.hScrollbarProp * pos;
if ( pos < 0 ) {
if ( !that.options.fixedScrollbar ) {
size = that.hScrollbarIndicatorSize + m.round( pos * 3 );
if ( size < 8 )
size = 8;
that.hScrollbarIndicator.style['width'] = size + 'px';
}
pos = 0;
}
else if ( pos > that.hScrollbarMaxScroll ) {
if ( !that.options.fixedScrollbar ) {
size = that.hScrollbarIndicatorSize - m.round( (pos - that.hScrollbarMaxScroll) * 3 );
if ( size < 8 )
size = 8;
that.hScrollbarIndicator.style['width'] = size + 'px';
pos = that.hScrollbarMaxScroll + (that.hScrollbarIndicatorSize - size);
}
else {
pos = that.hScrollbarMaxScroll;
}
}
that.hScrollbarWrapper.style[transitionDelay] = '0';
that.hScrollbarWrapper.style.opacity = hidden && that.options.hideScrollbar ? '0' : '1';
that.hScrollbarIndicator.style[transform] = 'translate(' + pos + 'px,0)' + translateZ;
}
else {
if ( !that.vScrollbar )
return;
pos = that.vScrollbarProp * pos;
if ( pos < 0 ) {
if ( !that.options.fixedScrollbar ) {
size = that.vScrollbarIndicatorSize + m.round( pos * 3 );
if ( size < 8 )
size = 8;
that.vScrollbarIndicator.style['height'] = size + 'px';
}
pos = 0;
}
else if ( pos > that.vScrollbarMaxScroll ) {
if ( !that.options.fixedScrollbar ) {
size = that.vScrollbarIndicatorSize - m.round( (pos - that.vScrollbarMaxScroll) * 3 );
if ( size < 8 )
size = 8;
that.vScrollbarIndicator.style['height'] = size + 'px';
pos = that.vScrollbarMaxScroll + (that.vScrollbarIndicatorSize - size);
}
else {
pos = that.vScrollbarMaxScroll;
}
}
that.vScrollbarWrapper.style[transitionDelay] = '0';
that.vScrollbarWrapper.style.opacity = hidden && that.options.hideScrollbar ? '0' : '1';
that.vScrollbarIndicator.style[transform] = 'translate(0,' + pos + 'px)' + translateZ;
}
},
_start:function ( e ) {
var that = this,
point = hasTouch ? e.touches[0] : e,
matrix, x, y,
c1, c2;
if ( !that.enabled ) return;
if ( that.options.onBeforeScrollStart ) that.options.onBeforeScrollStart.call( that, e );
if ( that.options.useTransition || that.options.zoom ) that._transitionTime( 0 );
that.moved = false;
that.animating = false;
that.zoomed = false;
that.distX = 0;
that.distY = 0;
that.absDistX = 0;
that.absDistY = 0;
that.dirX = 0;
that.dirY = 0;
// Gesture start
if ( that.options.zoom && hasTouch && e.touches.length > 1 ) {
c1 = m.abs( e.touches[0].pageX - e.touches[1].pageX );
c2 = m.abs( e.touches[0].pageY - e.touches[1].pageY );
that.touchesDistStart = m.sqrt( c1 * c1 + c2 * c2 );
that.originX = m.abs( e.touches[0].pageX + e.touches[1].pageX - that.wrapperOffsetLeft * 2 ) / 2 - that.x;
that.originY = m.abs( e.touches[0].pageY + e.touches[1].pageY - that.wrapperOffsetTop * 2 ) / 2 - that.y;
if ( that.options.onZoomStart ) that.options.onZoomStart.call( that, e );
}
if ( that.options.momentum ) {
cancelFrame( that.aniTime );
that.steps = [];
that._pos( this.x, this.y ); // это чтобы обновился экран
if ( that.options.onScrollEnd )
that.options.onScrollEnd.call( that );
}
that.absStartX = that.x; // Needed by snap threshold
that.absStartY = that.y;
that.startX = that.x;
that.startY = that.y;
that.pointX = point.pageX;
that.pointY = point.pageY;
that.startTime = e.timeStamp || Date.now();
if ( that.options.onScrollStart ) that.options.onScrollStart.call( that, e );
},
_move:function ( e ) {
var that = this,
point = hasTouch ? e.touches[0] : e,
deltaX = point.pageX - that.pointX,
deltaY = point.pageY - that.pointY,
newX = that.x + deltaX,
newY = that.y + deltaY,
c1, c2, scale,
timestamp = e.timeStamp || Date.now();
if ( that.options.onBeforeScrollMove ) that.options.onBeforeScrollMove.call( that, e );
// Zoom
if ( that.options.zoom && hasTouch && e.touches.length > 1 && that.scroller ) {
c1 = m.abs( e.touches[0].pageX - e.touches[1].pageX );
c2 = m.abs( e.touches[0].pageY - e.touches[1].pageY );
that.touchesDist = m.sqrt( c1 * c1 + c2 * c2 );
that.zoomed = true;
scale = 1 / that.touchesDistStart * that.touchesDist * this.scale;
if ( scale < that.options.zoomMin ) scale = 0.5 * that.options.zoomMin * Math.pow( 2.0, scale / that.options.zoomMin );
else if ( scale > that.options.zoomMax ) scale = 2.0 * that.options.zoomMax * Math.pow( 0.5, that.options.zoomMax / scale );
that.lastScale = scale / this.scale;
newX = this.originX - this.originX * that.lastScale + this.x;
newY = this.originY - this.originY * that.lastScale + this.y;
this.scroller.style[transform] = 'translate(' + newX + 'px,' + newY + 'px) scale(' + scale + ')' + translateZ;
if ( that.options.onZoom ) that.options.onZoom.call( that, e );
return;
}
that.pointX = point.pageX;
that.pointY = point.pageY;
// Slow down if outside of the boundaries
if ( newX > 0 || newX < that.maxScrollX ) {
newX = that.options.bounce ? that.x + (deltaX / 2) : newX >= 0 || that.maxScrollX >= 0 ? 0 : that.maxScrollX;
}
if ( newY > that.minScrollY || newY < that.maxScrollY ) {
newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= that.minScrollY || that.maxScrollY >= 0 ? that.minScrollY : that.maxScrollY;
}
that.distX += deltaX;
that.distY += deltaY;
that.absDistX = m.abs( that.distX );
that.absDistY = m.abs( that.distY );
if ( that.absDistX < 6 && that.absDistY < 6 ) {
return;
}
// Lock direction
if ( that.options.lockDirection ) {
if ( that.absDistX > that.absDistY + 5 ) {
newY = that.y;
deltaY = 0;
}
else if ( that.absDistY > that.absDistX + 5 ) {
newX = that.x;
deltaX = 0;
}
}
that.moved = true;
that._pos( newX, newY );
that.dirX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0;
that.dirY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0;
if ( timestamp - that.startTime > 300 ) {
that.startTime = timestamp;
that.startX = that.x;
that.startY = that.y;
}
if ( that.options.onScrollMove ) that.options.onScrollMove.call( that, e );
},
_end:function ( e ) {
if ( hasTouch && e.touches.length !== 0 ) return;
var that = this,
point = hasTouch ? e.changedTouches[0] : e,
target, ev,
momentumX = { dist:0, time:0 },
momentumY = { dist:0, time:0 },
duration = (e.timeStamp || Date.now()) - that.startTime,
newPosX = that.x,
newPosY = that.y,
distX, distY,
newDuration,
snap,
scale;
if ( that.options.onBeforeScrollEnd ) that.options.onBeforeScrollEnd.call( that, e );
if ( that.zoomed ) {
scale = that.scale * that.lastScale;
scale = Math.max( that.options.zoomMin, scale );
scale = Math.min( that.options.zoomMax, scale );
that.lastScale = scale / that.scale;
that.scale = scale;
that.x = that.originX - that.originX * that.lastScale + that.x;
that.y = that.originY - that.originY * that.lastScale + that.y;
that.scroller.style[transitionDuration] = '200ms';
that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + that.scale + ')' + translateZ;
that.zoomed = false;
that.refresh();
if ( that.options.onZoomEnd ) that.options.onZoomEnd.call( that, e );
return;
}
if ( !that.moved ) {
if ( hasTouch ) {
if ( that.doubleTapTimer && that.options.zoom ) {
// Double tapped
clearTimeout( that.doubleTapTimer );
that.doubleTapTimer = null;
if ( that.options.onZoomStart ) that.options.onZoomStart.call( that, e );
that.zoom( that.pointX, that.pointY, that.scale == 1 ? that.options.doubleTapZoom : 1 );
if ( that.options.onZoomEnd ) {
setTimeout( function () {
that.options.onZoomEnd.call( that, e );
}, 200 ); // 200 is default zoom duration
}
}
else if ( this.options.handleClick ) {
that.doubleTapTimer = setTimeout( function () {
that.doubleTapTimer = null;
// Find the last touched element
target = point.target;
while ( target.nodeType != 1 ) target = target.parentNode;
if ( target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA' ) {
ev = doc.createEvent( 'MouseEvents' );
ev.initMouseEvent( 'click', true, true, e.view, 1,
point.screenX, point.screenY, point.clientX, point.clientY,
e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
0, null );
ev._fake = true;
target.dispatchEvent( ev );
}
}, that.options.zoom ? 250 : 0 );
}
}
that._resetPos( 400 );
if ( that.options.onTouchEnd ) that.options.onTouchEnd.call( that, e );
return;
}
if ( duration < 300 && that.options.momentum ) {
momentumX = newPosX ? that._momentum( newPosX - that.startX, duration, -that.x, that.scrollerW - that.wrapperW + that.x, that.options.bounce ? that.wrapperW : 0 ) : momentumX;
momentumY = newPosY ? that._momentum( newPosY - that.startY, duration, -that.y, (that.maxScrollY < 0 ? that.scrollerH - that.wrapperH + that.y - that.minScrollY : 0), that.options.bounce ? that.wrapperH : 0 ) : momentumY;
newPosX = that.x + momentumX.dist;
newPosY = that.y + momentumY.dist;
if ( (that.x > 0 && newPosX > 0) || (that.x < that.maxScrollX && newPosX < that.maxScrollX) ) momentumX = { dist:0, time:0 };
if ( (that.y > that.minScrollY && newPosY > that.minScrollY) || (that.y < that.maxScrollY && newPosY < that.maxScrollY) ) momentumY = { dist:0, time:0 };
}
if ( momentumX.dist || momentumY.dist ) {
newDuration = m.max( m.max( momentumX.time, momentumY.time ), 10 );
// Do we need to snap?
if ( that.options.snap ) {
distX = newPosX - that.absStartX;
distY = newPosY - that.absStartY;
if ( m.abs( distX ) < that.options.snapThreshold && m.abs( distY ) < that.options.snapThreshold ) {
that.scrollTo( that.absStartX, that.absStartY, 200 );
}
else {
snap = that._snap( newPosX, newPosY );
newPosX = snap.x;
newPosY = snap.y;
newDuration = m.max( snap.time, newDuration );
}
}
that.scrollTo( m.round( newPosX ), m.round( newPosY ), newDuration );
if ( that.options.onTouchEnd ) that.options.onTouchEnd.call( that, e );
return;
}
// Do we need to snap?
if ( that.options.snap ) {
distX = newPosX - that.absStartX;
distY = newPosY - that.absStartY;
if ( m.abs( distX ) < that.options.snapThreshold && m.abs( distY ) < that.options.snapThreshold ) that.scrollTo( that.absStartX, that.absStartY, 200 );
else {
snap = that._snap( that.x, that.y );
if ( snap.x != that.x || snap.y != that.y ) that.scrollTo( snap.x, snap.y, snap.time );
}
if ( that.options.onTouchEnd ) that.options.onTouchEnd.call( that, e );
return;
}
that._resetPos( 200 );
if ( that.options.onTouchEnd ) that.options.onTouchEnd.call( that, e );
},
_resetPos:function ( time ) {
var that = this,
resetX = that.x >= 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x,
resetY = that.y >= that.minScrollY || that.maxScrollY > 0 ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y;
if ( resetX == that.x && resetY == that.y ) {
if ( that.moved ) {
that.moved = false;
if ( that.options.onScrollEnd ) that.options.onScrollEnd.call( that ); // Execute custom code on scroll end
}
if ( that.hScrollbar && that.options.hideScrollbar ) {
if ( vendor == 'webkit' ) that.hScrollbarWrapper.style[transitionDelay] = '300ms';
that.hScrollbarWrapper.style.opacity = '0';
}
if ( that.vScrollbar && that.options.hideScrollbar ) {
if ( vendor == 'webkit' ) that.vScrollbarWrapper.style[transitionDelay] = '300ms';
that.vScrollbarWrapper.style.opacity = '0';
}
return;
}
that.scrollTo( resetX, resetY, time || 0 );
},
_wheel:function ( e ) {
var that = this,
wheelDeltaX, wheelDeltaY,
deltaX, deltaY,
deltaScale;
if ( 'wheelDeltaX' in e ) {
wheelDeltaX = e['wheelDeltaX'] / 12;
wheelDeltaY = e['wheelDeltaY'] / 12;
}
else if ( 'wheelDelta' in e ) {
wheelDeltaX = wheelDeltaY = e['wheelDelta'] / 12;
}
else if ( 'detail' in e ) {
wheelDeltaX = wheelDeltaY = -e['detail'] * 3;
}
else {
return;
}
if ( that.options.wheelAction == 'zoom' ) {
deltaScale = that.scale * Math.pow( 2, 1 / 3 * (wheelDeltaY ? wheelDeltaY / Math.abs( wheelDeltaY ) : 0) );
if ( deltaScale < that.options.zoomMin ) deltaScale = that.options.zoomMin;
if ( deltaScale > that.options.zoomMax ) deltaScale = that.options.zoomMax;
if ( deltaScale != that.scale ) {
if ( !that.wheelZoomCount && that.options.onZoomStart ) that.options.onZoomStart.call( that, e );
that.wheelZoomCount++;
that.zoom( e.pageX, e.pageY, deltaScale, 400 );
setTimeout( function () {
that.wheelZoomCount--;
if ( !that.wheelZoomCount && that.options.onZoomEnd ) that.options.onZoomEnd.call( that, e );
}, 400 );
}
return;
}
deltaX = that.x + wheelDeltaX;
deltaY = that.y + wheelDeltaY;
if ( deltaX > 0 ) deltaX = 0;
else if ( deltaX < that.maxScrollX ) deltaX = that.maxScrollX;
if ( deltaY > that.minScrollY ) deltaY = that.minScrollY;
else if ( deltaY < that.maxScrollY ) deltaY = that.maxScrollY;
if ( that.maxScrollY < 0 ) {
that.scrollTo( deltaX, deltaY, 0 );
}
},
_transitionEnd:function ( e ) {
var that = this;
if ( e.target != that.scroller ) return;
that._unbind( TRNEND_EV );
that._startAni();
},
/**
*
* Utilities
*
*/
_startAni:function () {
var that = this,
startX = that.x, startY = that.y,
startTime = Date.now(),
step, easeOut,
animate;
if ( that.animating ) return;
if ( !that.steps.length ) {
that._resetPos( 400 );
return;
}
step = that.steps.shift();
if ( step.x == startX && step.y == startY ) step.time = 0;
that.animating = true;
that.moved = true;
if ( that.options.useTransition ) {
that._transitionTime( step.time );
that._pos( step.x, step.y );
that.animating = false;
if ( step.time ) that._bind( TRNEND_EV );
else that._resetPos( 0 );
return;
}
animate = function () {
var now = Date.now(),
newX, newY;
if ( now >= startTime + step.time ) {
that._pos( step.x, step.y );
that.animating = false;
if ( that.options.onAnimationEnd )
that.options.onAnimationEnd( that ); // Execute custom code on animation end
that._startAni();
return;
}
now = (now - startTime) / step.time - 1;
easeOut = m.sqrt( 1 - now * now );
newX = (step.x - startX) * easeOut + startX;
newY = (step.y - startY) * easeOut + startY;
that._pos( newX, newY, true );
if ( that.animating ) that.aniTime = nextFrame( animate );
};
animate();
},
_transitionTime:function ( time ) {
time += 'ms';
this.scroller.style[transitionDuration] = time;
if ( this.hScrollbar ) this.hScrollbarIndicator.style[transitionDuration] = time;
if ( this.vScrollbar ) this.vScrollbarIndicator.style[transitionDuration] = time;
},
_momentum:function ( dist, time, maxDistUpper, maxDistLower, size ) {
var deceleration = 0.0006,
speed = m.abs( dist ) / time,
newDist = (speed * speed) / (2 * deceleration),
newTime = 0, outsideDist = 0;
// Proportinally reduce speed if we are outside of the boundaries
if ( dist > 0 && newDist > maxDistUpper ) {
outsideDist = size / (6 / (newDist / speed * deceleration));
maxDistUpper = maxDistUpper + outsideDist;
speed = speed * maxDistUpper / newDist;
newDist = maxDistUpper;
}
else if ( dist < 0 && newDist > maxDistLower ) {
outsideDist = size / (6 / (newDist / speed * deceleration));
maxDistLower = maxDistLower + outsideDist;
speed = speed * maxDistLower / newDist;
newDist = maxDistLower;
}
newDist = newDist * (dist < 0 ? -1 : 1);
newTime = speed / deceleration;
return { dist:newDist, time:m.round( newTime ) };
},
_offset:function ( el ) {
var left = -el.offsetLeft,
top = -el.offsetTop;
while ( el = el.offsetParent ) {
left -= el.offsetLeft;
top -= el.offsetTop;
}
if ( el != this.wrapper ) {
left *= this.scale;
top *= this.scale;
}
return { left:left, top:top };
},
_snap:function ( x, y ) {
var that = this,
i, l,
page, time,
sizeX, sizeY;
// Check page X
page = that.pagesX.length - 1;
for ( i = 0, l = that.pagesX.length; i < l; i++ ) {
if ( x >= that.pagesX[i] ) {
page = i;
break;
}
}
if ( page == that.currPageX && page > 0 && that.dirX < 0 ) page--;
x = that.pagesX[page];
sizeX = m.abs( x - that.pagesX[that.currPageX] );
sizeX = sizeX ? m.abs( that.x - x ) / sizeX * 500 : 0;
that.currPageX = page;
// Check page Y
page = that.pagesY.length - 1;
for ( i = 0; i < page; i++ ) {
if ( y >= that.pagesY[i] ) {
page = i;
break;
}
}
if ( page == that.currPageY && page > 0 && that.dirY < 0 ) page--;
y = that.pagesY[page];
sizeY = m.abs( y - that.pagesY[that.currPageY] );
sizeY = sizeY ? m.abs( that.y - y ) / sizeY * 500 : 0;
that.currPageY = page;
// Snap with constant speed (proportional duration)
time = m.round( m.max( sizeX, sizeY ) ) || 200;
return { x:x, y:y, time:time };
},
_bind:function ( type, el, bubble ) {
(el || this.scroller).addEventListener( type, this, !!bubble );
},
_unbind:function ( type, el, bubble ) {
(el || this.scroller).removeEventListener( type, this, !!bubble );
},
/**
*
* Public methods
*
*/
destroy:function () {
var that = this;
that.scroller.style[transform] = '';
// Remove the scrollbars
that.hScrollbar = false;
that.vScrollbar = false;
that._scrollbar( 'h' );
that._scrollbar( 'v' );
// Remove the event listeners
if ( that.options.useTransition ) that._unbind( TRNEND_EV );
if ( that.options.onDestroy ) that.options.onDestroy.call( that );
},
_changeMaxes:function () {
var that = this;
var _elem = that.api.ReaderModeDiv;
that.scrollerW = m.round( _elem.offsetWidth );
that.scrollerH = m.round( _elem.offsetHeight + that.minScrollY );
that.maxScrollX = that.wrapperW - that.scrollerW;
that.maxScrollY = that.wrapperH - that.scrollerH + that.minScrollY;
console.log("that.maxScrollY " + that.maxScrollY);
console.log("that.maxScrollX " + that.maxScrollX);
that._scrollbar( 'h' );
that._scrollbar( 'v' );
},
refresh:function ( bIsNoReaderAttack ) {
var that = this,
offset,
i, l,
els,
pos = 0,
page = 0;
if ( that.scale < that.options.zoomMin )
that.scale = that.options.zoomMin;
that.wrapperW = ((that.wrapper.width) || 1) >> 0;
that.wrapperH = ((that.wrapper.height) || 1) >> 0;
that.minScrollY = 0;
that.scrollerW = that.api.m_dScrollX_max;
that.scrollerH = that.api.m_dScrollY_max;
var _oldMaxX = that.maxScrollX;
var _oldMaxY = that.maxScrollY;
var _oldX = that.x;
var _oldY = that.y;
that.maxScrollX = -that.api.m_dScrollX_max;
that.maxScrollY = -that.api.m_dScrollY_max;
that.x = -that.api.m_dScrollX;
that.y = -that.api.m_dScrollY;
if ( that.api.ReaderModeDiv != null && undefined === bIsNoReaderAttack ) {
var _elem = that.api.ReaderModeDiv;
that.scrollerW = m.round( _elem.offsetWidth );
that.scrollerH = m.round( _elem.offsetHeight + that.minScrollY );
that.maxScrollX = that.wrapperW - that.scrollerW;
that.maxScrollY = that.wrapperH - that.scrollerH + that.minScrollY;
// теперь посмотрим
/*
that.y = 0;
if (0 < that.api.m_dScrollY_max)
{
that.y = (that.api.m_dScrollY * that.maxScrollY / that.api.m_dScrollY_max) >> 0;
}
*/
that.x = 0;
that.y = 0;
if ( _oldMaxX < 0 ) {
that.x = (_oldX * that.maxScrollX / _oldMaxX) >> 0;
if ( that.x > 0 )
that.x = 0;
if ( that.x < that.maxScrollX )
that.x = that.maxScrollX;
}
if ( _oldMaxY < 0 ) {
that.y = (_oldY * that.maxScrollY / _oldMaxY) >> 0;
if ( that.y > 0 )
that.y = 0;
if ( that.y < that.maxScrollY )
that.y = that.maxScrollY;
}
}
that.dirX = 0;
that.dirY = 0;
if ( that.options.onRefresh ) that.options.onRefresh.call( that );
that.hScroll = that.options.hScroll && that.maxScrollX < 0;
that.vScroll = that.options.vScroll && (!that.options.bounceLock && !that.hScroll || that.scrollerH >= that.wrapperH);
that.hScrollbar = that.hScroll && that.options.hScrollbar;
that.vScrollbar = that.vScroll && that.options.vScrollbar && that.scrollerH >= that.wrapperH;
offset = that._offset( that.wrapper );
that.wrapperOffsetLeft = -offset.left;
that.wrapperOffsetTop = -offset.top;
// Prepare snap
if ( typeof that.options.snap == 'string' ) {
that.pagesX = [];
that.pagesY = [];
els = that.scroller.querySelectorAll( that.options.snap );
for ( i = 0, l = els.length; i < l; i++ ) {
pos = that._offset( els[i] );
pos.left += that.wrapperOffsetLeft;
pos.top += that.wrapperOffsetTop;
that.pagesX[i] = pos.left < that.maxScrollX ? that.maxScrollX : pos.left * that.scale;
that.pagesY[i] = pos.top < that.maxScrollY ? that.maxScrollY : pos.top * that.scale;
}
}
else if ( that.options.snap ) {
that.pagesX = [];
while ( pos >= that.maxScrollX ) {
that.pagesX[page] = pos;
pos = pos - that.wrapperW;
page++;
}
if ( that.maxScrollX % that.wrapperW ) that.pagesX[that.pagesX.length] = that.maxScrollX - that.pagesX[that.pagesX.length - 1] + that.pagesX[that.pagesX.length - 1];
pos = 0;
page = 0;
that.pagesY = [];
while ( pos >= that.maxScrollY ) {
that.pagesY[page] = pos;
pos = pos - that.wrapperH;
page++;
}
if ( that.maxScrollY % that.wrapperH ) that.pagesY[that.pagesY.length] = that.maxScrollY - that.pagesY[that.pagesY.length - 1] + that.pagesY[that.pagesY.length - 1];
}
// Prepare the scrollbars
that._scrollbar( 'h' );
that._scrollbar( 'v' );
if ( !that.zoomed && that.scroller ) {
that.scroller.style[transitionDuration] = '0';
that._resetPos( 400 );
}
},
scrollTo:function ( x, y, time, relative ) {
var that = this,
step = x,
i, l;
that.stop();
if ( !step.length ) step = [
{ x:x, y:y, time:time, relative:relative }
];
for ( i = 0, l = step.length; i < l; i++ ) {
if ( step[i].relative ) {
step[i].x = that.x - step[i].x;
step[i].y = that.y - step[i].y;
}
that.steps.push( { x:step[i].x, y:step[i].y, time:step[i].time || 0 } );
}
that._startAni();
},
scrollToElement:function ( el, time ) {
var that = this, pos;
el = el.nodeType ? el : that.scroller.querySelector( el );
if ( !el ) return;
pos = that._offset( el );
pos.left += that.wrapperOffsetLeft;
pos.top += that.wrapperOffsetTop;
pos.left = pos.left > 0 ? 0 : pos.left < that.maxScrollX ? that.maxScrollX : pos.left;
pos.top = pos.top > that.minScrollY ? that.minScrollY : pos.top < that.maxScrollY ? that.maxScrollY : pos.top;
time = time === undefined ? m.max( m.abs( pos.left ) * 2, m.abs( pos.top ) * 2 ) : time;
that.scrollTo( pos.left, pos.top, time );
},
scrollToPage:function ( pageX, pageY, time ) {
var that = this, x, y;
time = time === undefined ? 400 : time;
if ( that.options.onScrollStart ) that.options.onScrollStart.call( that );
if ( that.options.snap ) {
pageX = pageX == 'next' ? that.currPageX + 1 : pageX == 'prev' ? that.currPageX - 1 : pageX;
pageY = pageY == 'next' ? that.currPageY + 1 : pageY == 'prev' ? that.currPageY - 1 : pageY;
pageX = pageX < 0 ? 0 : pageX > that.pagesX.length - 1 ? that.pagesX.length - 1 : pageX;
pageY = pageY < 0 ? 0 : pageY > that.pagesY.length - 1 ? that.pagesY.length - 1 : pageY;
that.currPageX = pageX;
that.currPageY = pageY;
x = that.pagesX[pageX];
y = that.pagesY[pageY];
}
else {
x = -that.wrapperW * pageX;
y = -that.wrapperH * pageY;
if ( x < that.maxScrollX ) x = that.maxScrollX;
if ( y < that.maxScrollY ) y = that.maxScrollY;
}
that.scrollTo( x, y, time );
},
disable:function () {
this.stop();
this._resetPos( 0 );
this.enabled = false;
// If disabled after touchstart we make sure that there are no left over events
this._unbind( CANCEL_EV, window );
},
enable:function () {
this.enabled = true;
},
stop:function () {
if ( this.options.useTransition ) this._unbind( TRNEND_EV );
else cancelFrame( this.aniTime );
this.steps = [];
this.moved = false;
this.animating = false;
},
zoom:function ( x, y, scale, time ) {
var that = this,
relScale = scale / that.scale;
if ( !that.options.useTransform ) return;
that.zoomed = true;
time = time === undefined ? 200 : time;
x = x - that.wrapperOffsetLeft - that.x;
y = y - that.wrapperOffsetTop - that.y;
that.x = x - x * relScale + that.x;
that.y = y - y * relScale + that.y;
that.scale = scale;
that.refresh();
that.x = that.x > 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x;
that.y = that.y > that.minScrollY ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y;
that.scroller.style[transitionDuration] = time + 'ms';
that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + scale + ')' + translateZ;
that.zoomed = false;
},
isReady:function () {
return !this.moved && !this.zoomed && !this.animating;
}
};
function prefixStyle( style ) {
if ( vendor === '' ) return style;
style = style.charAt( 0 ).toUpperCase() + style.substr( 1 );
return vendor + style;
}
dummyStyle = null; // for the sake of it
window.CTouchScroll = CTouchScroll;
window.asc_sdk_transform = prefixStyle( 'transform' );
window.asc_sdk_transitionProperty = prefixStyle( 'transitionProperty' );
window.asc_sdk_transitionDuration = prefixStyle( 'transitionDuration' );
window.asc_sdk_transformOrigin = prefixStyle( 'transformOrigin' );
window.asc_sdk_transitionTimingFunction = prefixStyle( 'transitionTimingFunction' );
window.asc_sdk_transitionDelay = prefixStyle( 'transitionDelay' );
window.asc_sdk_cssVendor = cssVendor;
})( window, document );
/**
* Created with JetBrains WebStorm.
* User: Dmitry.Shahtanov
* Date: 03.02.14
* Time: 14:26
* To change this template use File | Settings | File Templates.
*/
"use strict";
function CMobileTouchManager()
{
this.AnimateScroll = false;
this.AnimateZoom = false;
this.bIsTextSelected = false;
this.bIsTextSelecting = false;
this.LogicDocument = null;
this.DrawingDocument = null;
this.HtmlPage = null;
this.Mode = 0;
this.ReadingGlassTime = 750;
this.TimeDown = 0;
this.DownPoint = null;
this.DownPointOriginal = {X : 0, Y : 0};
this.MoveAfterDown = false;
this.MoveMinDist = 10;
this.RectSelect1 = null;
this.RectSelect2 = null;
this.PageSelect1 = 0;
this.PageSelect2 = 0;
this.CheckFirstRect = true;
this.TrackTargetEps = 20;
this.ScrollH = 0;
this.ScrollV = 0;
this.ZoomDistance = 0;
this.ZoomValue = 100;
this.ZoomValueMin = 50;
this.ZoomValueMax = 300;
this.iScroll = null;
this.TableMovePoint = null;
this.TableHorRulerPoints = null;
this.TableVerRulerPoints = null;
this.TableStartTrack_Check = false;
this.TableRulersRectOffset = 5;
this.TableRulersRectSize = 20;
this.TableCurrentMoveDir = -1;
this.TableCurrentMovePos = -1;
this.TableCurrentMoveValue = 0;
this.TableCurrentMoveValueOld = 0;
this.TableCurrentMoveValueMin = null;
this.TableCurrentMoveValueMax = null;
this.ShowMenuTimerId = -1;
}
CMobileTouchManager.prototype = {
Init : function(ctrl)
{
/*this.HtmlPage = ctrl;
this.LogicDocument = ctrl.m_oLogicDocument;
this.DrawingDocument = ctrl.m_oDrawingDocument;*/
this.iScroll = new window.CTouchScroll(ctrl,{hScrollbar:false,vScrollbar:true,momentum:false}/*, { onAnimationEnd : function(param) {
param.api.MobileTouchManager.OnScrollAnimationEnd();
} }*/);
// LoadMobileImages();
},
MoveCursorToPoint : function(e)
{
check_MouseMoveEvent(e);
var pos = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
var old_click_count = global_mouseEvent.ClickCount;
global_mouseEvent.ClickCount = 1;
var nearPos = this.LogicDocument.Get_NearestPos(pos.Page, pos.X, pos.Y);
this.DrawingDocument.NeedScrollToTargetFlag = true;
this.LogicDocument.OnMouseDown(global_mouseEvent, nearPos.X, nearPos.Y, pos.Page);
this.LogicDocument.OnMouseUp(global_mouseEvent, nearPos.X, nearPos.Y, pos.Page);
this.DrawingDocument.NeedScrollToTargetFlag = false;
global_mouseEvent.ClickCount = old_click_count;
},
onTouchStart : function(e)
{
this.iScroll._start(e);
e.preventDefault();
e.returnValue = false;
return false;
// if (null != this.DrawingDocument.m_oDocumentRenderer)
// return this.onTouchStart_renderer(e);
//
// check_MouseDownEvent(e.touches ? e.touches[0] : e, true);
// global_mouseEvent.LockMouse();
// this.HtmlPage.m_oApi.asc_fireCallback("asc_onHidePopMenu");
this.ScrollH = this.HtmlPage.m_dScrollX;
this.ScrollV = this.HtmlPage.m_dScrollY;
this.TableCurrentMoveValueMin = null;
this.TableCurrentMoveValueMax = null;
this.MoveAfterDown = false;
this.TimeDown = new Date().getTime();
/* var bIsKoefPixToMM = false;
var _matrix = this.DrawingDocument.TextMatrix;
if (_matrix && global_MatrixTransformer.IsIdentity(_matrix))
_matrix = null;*/
// проверим на попадание в селект - это может произойти на любом mode
/* if (null != this.RectSelect1 && null != this.RectSelect2)
{
var pos1 = null;
var pos4 = null;
if (!_matrix)
{
pos1 = this.DrawingDocument.ConvertCoordsToCursor3(this.RectSelect1.x, this.RectSelect1.y, this.PageSelect1);
pos4 = this.DrawingDocument.ConvertCoordsToCursor3(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h, this.PageSelect2);
}
else
{
var _xx1 = _matrix.TransformPointX(this.RectSelect1.x, this.RectSelect1.y);
var _yy1 = _matrix.TransformPointY(this.RectSelect1.x, this.RectSelect1.y);
var _xx2 = _matrix.TransformPointX(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
var _yy2 = _matrix.TransformPointY(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
pos1 = this.DrawingDocument.ConvertCoordsToCursor3(_xx1, _yy1, this.PageSelect1);
pos4 = this.DrawingDocument.ConvertCoordsToCursor3(_xx2, _yy2, this.PageSelect2);
}
if (Math.abs(pos1.X - global_mouseEvent.X) < this.TrackTargetEps && Math.abs(pos1.Y - global_mouseEvent.Y) < this.TrackTargetEps)
{
this.Mode = MobileTouchMode.Select;
this.DragSelect = 1;
}
else if (Math.abs(pos4.X - global_mouseEvent.X) < this.TrackTargetEps && Math.abs(pos4.Y - global_mouseEvent.Y) < this.TrackTargetEps)
{
this.Mode = MobileTouchMode.Select;
this.DragSelect = 2;
}
}
else
{
var _xOffset = this.HtmlPage.X;
var _yOffset = this.HtmlPage.Y;
if (true === this.HtmlPage.m_bIsRuler)
{
_xOffset += (5 * g_dKoef_mm_to_pix);
_yOffset += (7 * g_dKoef_mm_to_pix);
}
var _eps = this.TrackTargetEps;
var bIsTable = false;
var _table_outline_dr = this.DrawingDocument.TableOutlineDr;
if (this.TableMovePoint != null && _table_outline_dr)
{
var _Transform = _table_outline_dr.TableMatrix;
var _PageNum = _table_outline_dr.CurrentPageIndex;
if (!_Transform || global_MatrixTransformer.IsIdentity(_Transform))
{
var _x = global_mouseEvent.X - _xOffset;
var _y = global_mouseEvent.Y - _yOffset;
var posLT = this.DrawingDocument.ConvertCoordsToCursorWR(this.TableMovePoint.X, this.TableMovePoint.Y, _PageNum);
var _offset = this.TableRulersRectSize + this.TableRulersRectOffset;
if (_x > (posLT.X - _offset - _eps) && _x < (posLT.X - this.TableRulersRectOffset + _eps) &&
_y > (posLT.Y - _offset - _eps) && _y < (posLT.Y - this.TableRulersRectOffset + _eps))
{
this.Mode = MobileTouchMode.TableMove;
bIsTable = true;
}
if (!bIsTable)
{
if (_y > (posLT.Y - _offset - _eps) && _y < (posLT.Y - this.TableRulersRectOffset + _eps))
{
var _len = this.TableHorRulerPoints.length;
var _indexF = -1;
var _minF = 1000000;
for (var i = 0; i < _len; i++)
{
var posM1 = this.DrawingDocument.ConvertCoordsToCursorWR(this.TableHorRulerPoints[i].C, this.TableMovePoint.Y, _PageNum);
var _dist = Math.abs(_x - posM1.X);
if (_minF > _dist)
{
_indexF = i;
_minF = _dist;
}
}
if (_minF < _eps)
{
var _p = this.TableHorRulerPoints[_indexF];
this.TableCurrentMoveDir = 0;
this.TableCurrentMovePos = _indexF;
this.TableCurrentMoveValue = _p.X;
this.TableCurrentMoveValueOld = this.TableCurrentMoveValue;
this.Mode = MobileTouchMode.TableRuler;
if (_indexF == 0)
{
this.TableCurrentMoveValueMin = this.TableMovePoint.X;
}
else
{
this.TableCurrentMoveValueMin = this.TableHorRulerPoints[_indexF - 1].X + this.TableHorRulerPoints[_indexF - 1].W;
}
if (_indexF < (_len - 1))
{
this.TableCurrentMoveValueMax = this.TableHorRulerPoints[_indexF + 1].X;
}
else
{
this.TableCurrentMoveValueMax = null;
}
bIsTable = true;
}
}
if (!bIsTable && _x >= (posLT.X - _offset - _eps) && _x <= (posLT.X - this.TableRulersRectOffset + _eps))
{
var _len = this.TableVerRulerPoints.length;
var _indexF = -1;
var _minF = 1000000;
for (var i = 0; i < _len; i++)
{
var posM1 = this.DrawingDocument.ConvertCoordsToCursorWR(this.TableMovePoint.X, this.TableVerRulerPoints[i].Y, _PageNum);
var posM2 = this.DrawingDocument.ConvertCoordsToCursorWR(this.TableMovePoint.X, this.TableVerRulerPoints[i].Y + this.TableVerRulerPoints[i].H, _PageNum);
if (_y >= (posM1.Y - _eps) && _y <= (posM2.Y + _eps))
{
var _dist = Math.abs(_y - ((posM1.Y + posM2.Y) / 2));
if (_minF > _dist)
{
_indexF = i;
_minF = _dist;
}
}
}
if (_indexF != -1)
{
var _p = this.TableVerRulerPoints[_indexF];
this.TableCurrentMoveDir = 1;
this.TableCurrentMovePos = _indexF;
this.TableCurrentMoveValue = _p.Y;
this.TableCurrentMoveValueOld = this.TableCurrentMoveValue;
this.Mode = MobileTouchMode.TableRuler;
if (_indexF == 0)
{
this.TableCurrentMoveValueMin = this.TableMovePoint.Y;
}
else
{
this.TableCurrentMoveValueMin = this.TableVerRulerPoints[_indexF - 1].Y + this.TableVerRulerPoints[_indexF - 1].H;
}
if (_indexF < (_len - 1))
{
this.TableCurrentMoveValueMax = this.TableVerRulerPoints[_indexF + 1].Y;
}
else
{
this.TableCurrentMoveValueMax = null;
}
bIsTable = true;
}
}
}
}
else
{
var pos = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
if (pos.Page == _PageNum)
{
var _invert = global_MatrixTransformer.Invert(_Transform);
var _posx = _invert.TransformPointX(pos.X, pos.Y);
var _posy = _invert.TransformPointY(pos.X, pos.Y);
var _koef = g_dKoef_pix_to_mm * 100 / this.HtmlPage.m_nZoomValue;
var _eps1 = this.TrackTargetEps * _koef;
var _offset1 = this.TableRulersRectOffset * _koef;
var _offset2 = _offset1 + this.TableRulersRectSize * _koef;
if ((_posx >= (this.TableMovePoint.X - _offset2 - _eps1)) && (_posx <= (this.TableMovePoint.X - _offset1 + _eps1)) &&
(_posy >= (this.TableMovePoint.Y - _offset2 - _eps1)) && (_posy <= (this.TableMovePoint.Y - _offset1 + _eps1)))
{
this.Mode = MobileTouchMode.TableMove;
bIsTable = true;
}
if (!bIsTable)
{
if (_posy > (this.TableMovePoint.Y - _offset2 - _eps1) && _posy < (this.TableMovePoint.Y - _offset1 + _eps1))
{
var _len = this.TableHorRulerPoints.length;
for (var i = 0; i < _len; i++)
{
var _p = this.TableHorRulerPoints[i];
if (_posx > (_p.X - _eps1) && _posx < (_p.X + _p.W + _eps1))
{
this.TableCurrentMoveDir = 0;
this.TableCurrentMovePos = i;
this.TableCurrentMoveValue = this.TableHorRulerPoints[i].X;
this.TableCurrentMoveValueOld = this.TableCurrentMoveValue;
this.Mode = MobileTouchMode.TableRuler;
if (i == 0)
{
this.TableCurrentMoveValueMin = this.TableMovePoint.X;
}
else
{
this.TableCurrentMoveValueMin = this.TableHorRulerPoints[i - 1].X + this.TableHorRulerPoints[i - 1].W;
}
if (i < (_len - 1))
{
this.TableCurrentMoveValueMax = this.TableHorRulerPoints[i + 1].X;
}
else
{
this.TableCurrentMoveValueMax = null;
}
bIsTable = true;
break;
}
}
}
if (!bIsTable && _posx >= (this.TableMovePoint.X - _offset2 - _eps1) && _posx <= (this.TableMovePoint.X - _offset1 + _eps1))
{
var _len = this.TableVerRulerPoints.length;
for (var i = 0; i < _len; i++)
{
var _p = this.TableVerRulerPoints[i];
if (_posy >= (_p.Y - _eps1) && _posy <= (_p.Y + _p.H + _eps1))
{
this.TableCurrentMoveDir = 1;
this.TableCurrentMovePos = i;
this.TableCurrentMoveValue = this.TableVerRulerPoints[i].Y;
this.TableCurrentMoveValueOld = this.TableCurrentMoveValue;
this.Mode = MobileTouchMode.TableRuler;
if (i == 0)
{
this.TableCurrentMoveValueMin = this.TableMovePoint.Y;
}
else
{
this.TableCurrentMoveValueMin = this.TableVerRulerPoints[i - 1].Y + this.TableVerRulerPoints[i - 1].H;
}
if (i < (_len - 1))
{
this.TableCurrentMoveValueMax = this.TableVerRulerPoints[i + 1].Y;
}
else
{
this.TableCurrentMoveValueMax = null;
}
bIsTable = true;
break;
}
}
}
}
}
}
}
if (!bIsTable)
{
var pos = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
var dKoef = (100 * g_dKoef_pix_to_mm / this.HtmlPage.m_nZoomValue);
global_mouseEvent.KoefPixToMM = 5;
if (this.LogicDocument.DrawingObjects.isPointInDrawingObjects2(pos.X, pos.Y, pos.Page))
{
bIsKoefPixToMM = true;
this.Mode = MobileTouchMode.FlowObj;
}
else
{
this.Mode = MobileTouchMode.None;
}
global_mouseEvent.KoefPixToMM = 1;
}
}*/
if (e.touches && 2 == e.touches.length)
{
this.Mode = MobileTouchMode.Zoom;
}
switch (this.Mode)
{
case MobileTouchMode.None:
{
this.Mode = MobileTouchMode.Scroll;
this.DownPoint = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
this.DownPointOriginal.X = global_mouseEvent.X;
this.DownPointOriginal.Y = global_mouseEvent.Y;
this.iScroll._start(e);
break;
}
case MobileTouchMode.Scroll:
{
// ничего не меняем, просто перемещаем точку
this.DownPoint = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
this.DownPointOriginal.X = global_mouseEvent.X;
this.DownPointOriginal.Y = global_mouseEvent.Y;
this.iScroll._start(e);
break;
}
case MobileTouchMode.Select:
{
if (1 == this.DragSelect)
{
global_mouseEvent.Button = 0;
if (!_matrix)
{
this.LogicDocument.OnMouseDown(global_mouseEvent, this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h / 2, this.PageSelect2);
}
else
{
var __X = _matrix.TransformPointX(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h / 2);
var __Y = _matrix.TransformPointY(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h / 2);
this.LogicDocument.OnMouseDown(global_mouseEvent, __X, __Y, this.PageSelect2);
}
var pos1 = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
this.LogicDocument.OnMouseMove(global_mouseEvent, pos1.X, pos1.Y, pos1.Page);
}
else if (2 == this.DragSelect)
{
global_mouseEvent.Button = 0;
if (!_matrix)
{
this.LogicDocument.OnMouseDown(global_mouseEvent, this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h / 2, this.PageSelect1);
}
else
{
var __X = _matrix.TransformPointX(this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h / 2);
var __Y = _matrix.TransformPointY(this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h / 2);
this.LogicDocument.OnMouseDown(global_mouseEvent, __X, __Y, this.PageSelect1);
}
var pos4 = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
this.LogicDocument.OnMouseMove(global_mouseEvent, pos4.X, pos4.Y, pos4.Page);
}
break;
}
case MobileTouchMode.InlineObj:
{
break;
}
case MobileTouchMode.FlowObj:
{
// так как был уже check, нужно уменьшить количество кликов
if (global_mouseEvent.ClickCount > 0)
global_mouseEvent.ClickCount--;
if (bIsKoefPixToMM)
{
global_mouseEvent.KoefPixToMM = 5;
}
this.HtmlPage.onMouseDown(e.touches ? e.touches[0] : e);
global_mouseEvent.KoefPixToMM = 1;
break;
}
case MobileTouchMode.Zoom:
{
this.HtmlPage.NoneRepaintPages = true;
var _x1 = (e.touches[0].pageX !== undefined) ? e.touches[0].pageX : e.touches[0].clientX;
var _y1 = (e.touches[0].pageY !== undefined) ? e.touches[0].pageY : e.touches[0].clientY;
var _x2 = (e.touches[1].pageX !== undefined) ? e.touches[1].pageX : e.touches[1].clientX;
var _y2 = (e.touches[1].pageY !== undefined) ? e.touches[1].pageY : e.touches[1].clientY;
this.ZoomDistance = Math.sqrt((_x1 - _x2)*(_x1 - _x2) + (_y1 - _y2)*(_y1 - _y2));
this.ZoomValue = this.HtmlPage.m_nZoomValue;
break;
}
case MobileTouchMode.Cursor:
{
this.Mode = MobileTouchMode.Scroll;
this.DownPoint = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
break;
}
case MobileTouchMode.TableMove:
{
// так как был уже check, нужно уменьшить количество кликов
if (global_mouseEvent.ClickCount > 0)
global_mouseEvent.ClickCount--;
this.HtmlPage.onMouseDown(e.touches ? e.touches[0] : e);
break;
}
case MobileTouchMode.TableRuler:
{
this.HtmlPage.OnUpdateOverlay();
break;
}
}
if (this.HtmlPage.m_oApi.isViewMode)
{
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
return false;
}
},
onTouchMove : function(e)
{
this.iScroll._move(e);
e.preventDefault();
e.returnValue = false;
return false;
/* if (null != this.DrawingDocument.m_oDocumentRenderer)
return this.onTouchMove_renderer(e);
if (this.Mode != MobileTouchMode.FlowObj && this.Mode != MobileTouchMode.TableMove)
check_MouseMoveEvent(e.touches ? e.touches[0] : e);*/
if (!this.MoveAfterDown)
{
if (Math.abs(this.DownPointOriginal.X - global_mouseEvent.X) > this.MoveMinDist ||
Math.abs(this.DownPointOriginal.Y - global_mouseEvent.Y) > this.MoveMinDist)
{
this.MoveAfterDown = true;
}
}
switch (this.Mode)
{
case MobileTouchMode.Cursor:
{
var pos = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
var old_click_count = global_mouseEvent.ClickCount;
global_mouseEvent.ClickCount = 1;
var nearPos = this.LogicDocument.Get_NearestPos(pos.Page, pos.X, pos.Y);
this.DrawingDocument.NeedScrollToTargetFlag = true;
global_mouseEvent.Type = g_mouse_event_type_down;
this.LogicDocument.OnMouseDown(global_mouseEvent, nearPos.X, nearPos.Y + nearPos.Height / 2, pos.Page);
global_mouseEvent.Type = g_mouse_event_type_up;
this.LogicDocument.OnMouseUp(global_mouseEvent, nearPos.X, nearPos.Y + nearPos.Height / 2, pos.Page);
this.DrawingDocument.NeedScrollToTargetFlag = false;
global_mouseEvent.ClickCount = old_click_count;
break;
}
case MobileTouchMode.Scroll:
{
var _newTime = new Date().getTime();
if ((_newTime - this.TimeDown) > this.ReadingGlassTime && !this.MoveAfterDown)
{
this.Mode = MobileTouchMode.Cursor;
var pos = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
var old_click_count = global_mouseEvent.ClickCount;
global_mouseEvent.ClickCount = 1;
var nearPos = this.LogicDocument.Get_NearestPos(pos.Page, pos.X, pos.Y);
this.DrawingDocument.NeedScrollToTargetFlag = true;
global_mouseEvent.Type = g_mouse_event_type_down;
this.LogicDocument.OnMouseDown(global_mouseEvent, nearPos.X, nearPos.Y, pos.Page);
global_mouseEvent.Type = g_mouse_event_type_up;
this.LogicDocument.OnMouseUp(global_mouseEvent, nearPos.X, nearPos.Y, pos.Page);
this.DrawingDocument.NeedScrollToTargetFlag = false;
global_mouseEvent.ClickCount = old_click_count;
}
else
{
var _offsetX = global_mouseEvent.X - this.DownPointOriginal.X;
var _offsetY = global_mouseEvent.Y - this.DownPointOriginal.Y;
this.iScroll._move(e);
/*
if (_offsetX != 0 && this.HtmlPage.m_dScrollX_max > 0)
{
this.HtmlPage.m_oScrollHorApi.scrollToX(this.ScrollH - _offsetX);
}
if (_offsetY != 0 && this.HtmlPage.m_dScrollY_max > 0)
{
this.HtmlPage.m_oScrollVerApi.scrollToY(this.ScrollV - _offsetY);
}*/
e.preventDefault();
e.returnValue = false;
}
break;
}
case MobileTouchMode.Zoom:
{
if (2 != e.touches.length)
{
this.Mode = MobileTouchMode.None;
return;
}
var _x1 = (e.touches[0].pageX !== undefined) ? e.touches[0].pageX : e.touches[0].clientX;
var _y1 = (e.touches[0].pageY !== undefined) ? e.touches[0].pageY : e.touches[0].clientY;
var _x2 = (e.touches[1].pageX !== undefined) ? e.touches[1].pageX : e.touches[1].clientX;
var _y2 = (e.touches[1].pageY !== undefined) ? e.touches[1].pageY : e.touches[1].clientY;
var zoomCurrentDist = Math.sqrt((_x1 - _x2)*(_x1 - _x2) + (_y1 - _y2)*(_y1 - _y2));
if (zoomCurrentDist == 0)
zoomCurrentDist = 1;
var _zoomFix = this.ZoomValue / 100;
var _zoomCur = _zoomFix * (zoomCurrentDist / this.ZoomDistance);
_zoomCur = (_zoomCur * 100) >> 0;
if (_zoomCur < this.ZoomValueMin)
_zoomCur = this.ZoomValueMin;
else if (_zoomCur > this.ZoomValueMax)
_zoomCur = this.ZoomValueMax;
this.HtmlPage.m_oApi.zoom(_zoomCur);
break;
}
case MobileTouchMode.InlineObj:
{
break;
}
case MobileTouchMode.FlowObj:
{
this.HtmlPage.onMouseMove(e.touches ? e.touches[0] : e);
break;
}
case MobileTouchMode.Select:
{
// во время движения может смениться порядок ректов
global_mouseEvent.ClickCount = 1;
var pos = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
this.LogicDocument.OnMouseMove(global_mouseEvent, pos.X, pos.Y, pos.Page);
break;
}
case MobileTouchMode.TableMove:
{
this.HtmlPage.onMouseMove(e.touches ? e.touches[0] : e);
break;
}
case MobileTouchMode.TableRuler:
{
var pos = this.DrawingDocument.ConvertCoordsFromCursorPage(global_mouseEvent.X, global_mouseEvent.Y, this.DrawingDocument.TableOutlineDr.CurrentPageIndex);
var _Transform = null;
if (this.DrawingDocument.TableOutlineDr)
_Transform = this.DrawingDocument.TableOutlineDr.TableMatrix;
if (_Transform && !global_MatrixTransformer.IsIdentity(_Transform))
{
var _invert = _Transform.CreateDublicate();
_invert.Invert();
var __x = _invert.TransformPointX(pos.X, pos.Y);
var __y = _invert.TransformPointY(pos.X, pos.Y);
pos.X = __x;
pos.Y = __y;
}
if (this.TableCurrentMoveDir == 0)
{
this.TableCurrentMoveValue = pos.X;
if (null != this.TableCurrentMoveValueMin)
{
if (this.TableCurrentMoveValueMin > this.TableCurrentMoveValue)
this.TableCurrentMoveValue = this.TableCurrentMoveValueMin;
}
if (null != this.TableCurrentMoveValueMax)
{
if (this.TableCurrentMoveValueMax < this.TableCurrentMoveValue)
this.TableCurrentMoveValue = this.TableCurrentMoveValueMax;
}
}
else
{
this.TableCurrentMoveValue = pos.Y;
if (null != this.TableCurrentMoveValueMin)
{
if (this.TableCurrentMoveValueMin > this.TableCurrentMoveValue)
this.TableCurrentMoveValue = this.TableCurrentMoveValueMin;
}
if (null != this.TableCurrentMoveValueMax)
{
if (this.TableCurrentMoveValueMax < this.TableCurrentMoveValue)
this.TableCurrentMoveValue = this.TableCurrentMoveValueMax;
}
}
this.HtmlPage.OnUpdateOverlay();
break;
}
default:
break;
}
},
onTouchEnd : function(e)
{
this.iScroll._end(e);
e.preventDefault();
e.returnValue = false;
return;
if (null != this.DrawingDocument.m_oDocumentRenderer)
return this.onTouchEnd_renderer(e);
if (this.Mode != MobileTouchMode.FlowObj && this.Mode != MobileTouchMode.TableMove)
check_MouseUpEvent(e.changedTouches ? e.changedTouches[0] : e);
this.ScrollH = this.HtmlPage.m_dScrollX;
this.ScrollV = this.HtmlPage.m_dScrollY;
switch (this.Mode)
{
case MobileTouchMode.Cursor:
{
// ничего не делаем. курсор уже установлен
this.Mode = MobileTouchMode.None;
break;
}
case MobileTouchMode.Scroll:
{
if (!this.MoveAfterDown)
{
global_mouseEvent.Button = 0;
var pos = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
this.LogicDocument.OnMouseDown(global_mouseEvent, pos.X, pos.Y, pos.Page);
global_mouseEvent.Type = g_mouse_event_type_up;
this.LogicDocument.OnMouseUp(global_mouseEvent, pos.X, pos.Y, pos.Page);
this.LogicDocument.Document_UpdateInterfaceState();
var horRuler = this.HtmlPage.m_oHorRuler;
var _oldRulerType = horRuler.CurrentObjectType;
this.LogicDocument.Document_UpdateRulersState();
if (horRuler.CurrentObjectType != _oldRulerType)
this.HtmlPage.OnUpdateOverlay();
this.LogicDocument.Update_CursorType(pos.X, pos.Y, pos.Page, global_mouseEvent);
this.HtmlPage.m_oApi.asc_fireCallback("asc_onTapEvent", e);
}
else
{
// нужно запускать анимацию скролла, если она есть
// TODO:
this.iScroll._end(e);
}
this.Mode = MobileTouchMode.None;
break;
}
case MobileTouchMode.Zoom:
{
// здесь нужно запускать отрисовку, если есть анимация зума
this.HtmlPage.NoneRepaintPages = false;
this.HtmlPage.m_bIsFullRepaint = true;
this.HtmlPage.OnScroll();
this.Mode = MobileTouchMode.None;
break;
}
case MobileTouchMode.InlineObj:
{
// TODO:
break;
}
case MobileTouchMode.FlowObj:
{
// TODO:
this.HtmlPage.onMouseUp(e.changedTouches ? e.changedTouches[0] : e);
this.Mode = MobileTouchMode.None;
break;
}
case MobileTouchMode.Select:
{
// ничего не нужно делать
this.DragSelect = 0;
this.Mode = MobileTouchMode.None;
break;
}
case MobileTouchMode.TableMove:
{
this.HtmlPage.onMouseUp(e.changedTouches ? e.changedTouches[0] : e);
this.Mode = MobileTouchMode.None;
break;
}
case MobileTouchMode.TableRuler:
{
this.HtmlPage.StartUpdateOverlay();
this.Mode = MobileTouchMode.None;
var _xOffset = this.HtmlPage.X;
var _yOffset = this.HtmlPage.Y;
if (true === this.HtmlPage.m_bIsRuler)
{
_xOffset += (5 * g_dKoef_mm_to_pix);
_yOffset += (7 * g_dKoef_mm_to_pix);
}
var pos = this.DrawingDocument.ConvertCoordsFromCursorPage(global_mouseEvent.X, global_mouseEvent.Y, this.DrawingDocument.TableOutlineDr.CurrentPageIndex);
var _Transform = null;
if (this.DrawingDocument.TableOutlineDr)
_Transform = this.DrawingDocument.TableOutlineDr.TableMatrix;
if (_Transform && !global_MatrixTransformer.IsIdentity(_Transform))
{
var _invert = _Transform.CreateDublicate();
_invert.Invert();
var __x = _invert.TransformPointX(pos.X, pos.Y);
var __y = _invert.TransformPointY(pos.X, pos.Y);
pos.X = __x;
pos.Y = __y;
}
if (this.TableCurrentMoveDir == 0)
{
this.TableCurrentMoveValue = pos.X;
if (null != this.TableCurrentMoveValueMin)
{
if (this.TableCurrentMoveValueMin > this.TableCurrentMoveValue)
this.TableCurrentMoveValue = this.TableCurrentMoveValueMin;
}
if (null != this.TableCurrentMoveValueMax)
{
if (this.TableCurrentMoveValueMax < this.TableCurrentMoveValue)
this.TableCurrentMoveValue = this.TableCurrentMoveValueMax;
}
var _markup = this.HtmlPage.m_oHorRuler.m_oTableMarkup;
_markup.Cols[this.TableCurrentMovePos] += (this.TableCurrentMoveValue - this.TableCurrentMoveValueOld);
_markup.Cols[this.TableCurrentMovePos] = Math.max(_markup.Cols[this.TableCurrentMovePos], 1);
_markup.Table.Update_TableMarkupFromRuler(_markup, true, this.TableCurrentMovePos + 1);
}
else
{
this.TableCurrentMoveValue = pos.Y;
if (null != this.TableCurrentMoveValueMin)
{
if (this.TableCurrentMoveValueMin > this.TableCurrentMoveValue)
this.TableCurrentMoveValue = this.TableCurrentMoveValueMin;
}
if (null != this.TableCurrentMoveValueMax)
{
if (this.TableCurrentMoveValueMax < this.TableCurrentMoveValue)
this.TableCurrentMoveValue = this.TableCurrentMoveValueMax;
}
var _markup = this.HtmlPage.m_oHorRuler.m_oTableMarkup;
_markup.Rows[this.TableCurrentMovePos].H += (this.TableCurrentMoveValue - this.TableCurrentMoveValueOld);
_markup.Table.Update_TableMarkupFromRuler(_markup, false, this.TableCurrentMovePos + 1);
}
this.HtmlPage.OnUpdateOverlay();
this.HtmlPage.EndUpdateOverlay();
break;
}
default:
break;
}
this.iScroll._scrollbar('h');
this.iScroll._scrollbar('v');
if (this.HtmlPage.m_oApi.isViewMode)
{
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
return false;
}
// если есть селект - то показать меню
this.CheckSelectEnd(true);
},
onTouchStart_renderer : function(e)
{
check_MouseDownEvent(e.touches ? e.touches[0] : e, true);
global_mouseEvent.LockMouse();
this.ScrollH = this.HtmlPage.m_dScrollX;
this.ScrollV = this.HtmlPage.m_dScrollY;
this.MoveAfterDown = false;
if (e.touches && 2 == e.touches.length)
{
this.Mode = MobileTouchMode.Zoom;
}
switch (this.Mode)
{
case MobileTouchMode.None:
{
this.Mode = MobileTouchMode.Scroll;
this.DownPoint = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
this.DownPointOriginal.X = global_mouseEvent.X;
this.DownPointOriginal.Y = global_mouseEvent.Y;
this.iScroll._start(e);
break;
}
case MobileTouchMode.Scroll:
{
// ничего не меняем, просто перемещаем точку
this.DownPoint = this.DrawingDocument.ConvertCoordsFromCursor2(global_mouseEvent.X, global_mouseEvent.Y);
this.DownPointOriginal.X = global_mouseEvent.X;
this.DownPointOriginal.Y = global_mouseEvent.Y;
this.iScroll._start(e);
break;
}
case MobileTouchMode.Zoom:
{
this.HtmlPage.NoneRepaintPages = true;
var _x1 = (e.touches[0].pageX !== undefined) ? e.touches[0].pageX : e.touches[0].clientX;
var _y1 = (e.touches[0].pageY !== undefined) ? e.touches[0].pageY : e.touches[0].clientY;
var _x2 = (e.touches[1].pageX !== undefined) ? e.touches[1].pageX : e.touches[1].clientX;
var _y2 = (e.touches[1].pageY !== undefined) ? e.touches[1].pageY : e.touches[1].clientY;
this.ZoomDistance = Math.sqrt((_x1 - _x2)*(_x1 - _x2) + (_y1 - _y2)*(_y1 - _y2));
this.ZoomValue = this.HtmlPage.m_nZoomValue;
break;
}
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
},
onTouchMove_renderer : function(e)
{
check_MouseMoveEvent(e.touches ? e.touches[0] : e);
if (!this.MoveAfterDown)
{
if (Math.abs(this.DownPointOriginal.X - global_mouseEvent.X) > this.MoveMinDist ||
Math.abs(this.DownPointOriginal.Y - global_mouseEvent.Y) > this.MoveMinDist)
{
this.MoveAfterDown = true;
}
}
switch (this.Mode)
{
case MobileTouchMode.Scroll:
{
var _offsetX = global_mouseEvent.X - this.DownPointOriginal.X;
var _offsetY = global_mouseEvent.Y - this.DownPointOriginal.Y;
this.iScroll._move(e);
break;
}
case MobileTouchMode.Zoom:
{
if (2 != e.touches.length)
{
this.Mode = MobileTouchMode.None;
return;
}
var _x1 = (e.touches[0].pageX !== undefined) ? e.touches[0].pageX : e.touches[0].clientX;
var _y1 = (e.touches[0].pageY !== undefined) ? e.touches[0].pageY : e.touches[0].clientY;
var _x2 = (e.touches[1].pageX !== undefined) ? e.touches[1].pageX : e.touches[1].clientX;
var _y2 = (e.touches[1].pageY !== undefined) ? e.touches[1].pageY : e.touches[1].clientY;
var zoomCurrentDist = Math.sqrt((_x1 - _x2)*(_x1 - _x2) + (_y1 - _y2)*(_y1 - _y2));
if (zoomCurrentDist == 0)
zoomCurrentDist = 1;
var _zoomFix = this.ZoomValue / 100;
var _zoomCur = _zoomFix * (zoomCurrentDist / this.ZoomDistance);
_zoomCur = (_zoomCur * 100) >> 0;
if (_zoomCur < this.ZoomValueMin)
_zoomCur = this.ZoomValueMin;
else if (_zoomCur > this.ZoomValueMax)
_zoomCur = this.ZoomValueMax;
this.HtmlPage.m_oApi.zoom(_zoomCur);
break;
}
default:
break;
}
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
},
onTouchEnd_renderer : function(e)
{
check_MouseUpEvent(e.changedTouches ? e.changedTouches[0] : e);
this.ScrollH = this.HtmlPage.m_dScrollX;
this.ScrollV = this.HtmlPage.m_dScrollY;
switch (this.Mode)
{
case MobileTouchMode.Scroll:
{
this.iScroll._end(e);
this.Mode = MobileTouchMode.None;
if (!this.MoveAfterDown)
{
this.HtmlPage.m_oApi.asc_fireCallback("asc_onTapEvent", e);
}
break;
}
case MobileTouchMode.Zoom:
{
// здесь нужно запускать отрисовку, если есть анимация зума
this.HtmlPage.NoneRepaintPages = false;
this.HtmlPage.m_bIsFullRepaint = true;
this.HtmlPage.OnScroll();
this.Mode = MobileTouchMode.None;
break;
}
default:
break;
}
this.iScroll._scrollbar('h');
this.iScroll._scrollbar('v');
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
},
CheckSelectEnd : function(bIsAttack)
{
var _bIsRet = false;
if (!bIsAttack)
_bIsRet = this.IsTrackingCurrent;
if (_bIsRet)
return;
if (null != this.RectSelect1 && null != this.RectSelect2 && !this.HtmlPage.m_oApi.isViewMode)
{
var _matrix = this.DrawingDocument.TextMatrix;
var pos1 = null;
var pos4 = null;
if (!_matrix || global_MatrixTransformer.IsIdentity(_matrix))
{
pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect1.x, this.RectSelect1.y, this.PageSelect1);
pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h, this.PageSelect2);
}
else
{
var _x1 = _matrix.TransformPointX(this.RectSelect1.x, this.RectSelect1.y);
var _y1 = _matrix.TransformPointY(this.RectSelect1.x, this.RectSelect1.y);
var _x2 = _matrix.TransformPointX(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
var _y2 = _matrix.TransformPointY(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(_x1, _y1, this.PageSelect1);
pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(_x2, _y2, this.PageSelect2);
}
var _x = (pos1.X + pos4.X) >> 1;
var _y = pos1.Y;
if (!this.iScroll.animating)
this.SendShowMenu(_x, _y);
}
},
CheckZoomCriticalValues : function(zoomMin)
{
if (zoomMin !== undefined)
{
this.ZoomValueMin = zoomMin;
return;
}
var w = this.HtmlPage.m_oEditor.AbsolutePosition.R - this.HtmlPage.m_oEditor.AbsolutePosition.L;
var Zoom = 100;
if (0 != this.HtmlPage.m_dDocumentPageWidth)
{
Zoom = 100 * (w - 10) / this.HtmlPage.m_dDocumentPageWidth;
if (Zoom < 5)
Zoom = 5;
if (this.HtmlPage.m_oApi.isMobileVersion)
{
var _w = this.HtmlPage.m_oEditor.HtmlElement.width;
if (this.bIsRetinaSupport)
{
_w >>= 1;
}
Zoom = 100 * _w * g_dKoef_pix_to_mm / this.HtmlPage.m_dDocumentPageWidth;
}
}
var _new_value = (Zoom - 0.5) >> 0;
this.ZoomValueMin = _new_value;
if (this.ZoomValue < this.ZoomValueMin)
{
this.ZoomValue = this.ZoomValueMin;
this.HtmlPage.m_oApi.zoom(this.ZoomValue);
}
},
Resize : function()
{
if (this.iScroll != null)
this.iScroll.refresh(true);
},
SendShowMenu : function(x, y)
{
if (-1 != this.ShowMenuTimerId)
{
clearTimeout(this.ShowMenuTimerId);
}
var that = this;
that.ShowMenuTimerId = setTimeout(function(){ that.HtmlPage.m_oApi.asc_fireCallback("asc_onShowPopMenu", x, y); }, 500);
},
OnScrollAnimationEnd : function()
{
if (this.HtmlPage.m_oApi.isViewMode)
return;
if (null != this.RectSelect1 && null != this.RectSelect2)
{
var pos1 = null;
var pos4 = null;
var _matrix = this.DrawingDocument.TextMatrix;
if (!_matrix || global_MatrixTransformer.IsIdentity(_matrix))
{
pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect1.x, this.RectSelect1.y, this.PageSelect1);
pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h, this.PageSelect2);
}
else
{
var _x1 = _matrix.TransformPointX(this.RectSelect1.x, this.RectSelect1.y);
var _y1 = _matrix.TransformPointY(this.RectSelect1.x, this.RectSelect1.y);
var _x2 = _matrix.TransformPointX(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
var _y2 = _matrix.TransformPointY(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(_x1, _y1, this.PageSelect1);
pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(_x2, _y2, this.PageSelect2);
}
var _x = (pos1.X + pos4.X) >> 1;
var _y = pos1.Y;
this.SendShowMenu(_x, _y);
}
},
CheckSelect : function(overlay)
{
if (null == this.RectSelect1 || null == this.RectSelect2)
return;
var _matrix = this.DrawingDocument.TextMatrix;
if (!_matrix || global_MatrixTransformer.IsIdentity(_matrix))
{
var pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect1.x, this.RectSelect1.y, this.PageSelect1);
var pos2 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h, this.PageSelect1);
var pos3 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y, this.PageSelect2);
var pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h, this.PageSelect2);
var ctx = overlay.m_oContext;
ctx.strokeStyle = "#1B63BA";
ctx.moveTo(pos1.X >> 0, pos1.Y >> 0);
ctx.lineTo(pos2.X >> 0, pos2.Y >> 0);
ctx.moveTo(pos3.X >> 0, pos3.Y >> 0);
ctx.lineTo(pos4.X >> 0, pos4.Y >> 0);
ctx.lineWidth = 2;
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "rgba(0, 0, 0, 0.5)";
overlay.AddEllipse(pos1.X, pos1.Y - 5, 6.5);
overlay.AddEllipse(pos4.X, pos4.Y + 5, 6.5);
ctx.fill();
ctx.beginPath();
ctx.fillStyle = "#FFFFFF";
overlay.AddEllipse(pos1.X, pos1.Y - 5, 6);
overlay.AddEllipse(pos4.X, pos4.Y + 5, 6);
ctx.fill();
ctx.beginPath();
ctx.fillStyle = "#1B63BA";
overlay.AddEllipse(pos1.X, pos1.Y - 5, 5);
overlay.AddEllipse(pos4.X, pos4.Y + 5, 5);
ctx.fill();
/*
ctx.beginPath();
ctx.fillStyle = "#FFFFFF";
overlay.AddEllipse(pos1.X, pos1.Y - 5, 2);
overlay.AddEllipse(pos4.X, pos4.Y + 5, 2);
ctx.fill();
*/
}
else
{
var _xx11 = _matrix.TransformPointX(this.RectSelect1.x, this.RectSelect1.y);
var _yy11 = _matrix.TransformPointY(this.RectSelect1.x, this.RectSelect1.y);
var _xx12 = _matrix.TransformPointX(this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h);
var _yy12 = _matrix.TransformPointY(this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h);
var _xx21 = _matrix.TransformPointX(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y);
var _yy21 = _matrix.TransformPointY(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y);
var _xx22 = _matrix.TransformPointX(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
var _yy22 = _matrix.TransformPointY(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
var pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(_xx11, _yy11, this.PageSelect1);
var pos2 = this.DrawingDocument.ConvertCoordsToCursorWR(_xx12, _yy12, this.PageSelect1);
var pos3 = this.DrawingDocument.ConvertCoordsToCursorWR(_xx21, _yy21, this.PageSelect2);
var pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(_xx22, _yy22, this.PageSelect2);
var ctx = overlay.m_oContext;
ctx.strokeStyle = "#1B63BA";
ctx.moveTo(pos1.X, pos1.Y);
ctx.lineTo(pos2.X, pos2.Y);
ctx.moveTo(pos3.X, pos3.Y);
ctx.lineTo(pos4.X, pos4.Y);
ctx.lineWidth = 2;
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "rgba(0, 0, 0, 0.5)";
overlay.AddEllipse(pos1.X, pos1.Y - 5, 6.5);
overlay.AddEllipse(pos4.X, pos4.Y + 5, 6.5);
ctx.fill();
ctx.beginPath();
ctx.fillStyle = "#FFFFFF";
overlay.AddEllipse(pos1.X, pos1.Y - 5, 6);
overlay.AddEllipse(pos4.X, pos4.Y + 5, 6);
ctx.fill();
ctx.beginPath();
ctx.fillStyle = "#1B63BA";
overlay.AddEllipse(pos1.X, pos1.Y - 5, 5);
overlay.AddEllipse(pos4.X, pos4.Y + 5, 5);
ctx.fill();
}
},
CheckSelect2 : function(overlay)
{
if (null == this.RectSelect1 || null == this.RectSelect2)
return;
var _matrix = this.DrawingDocument.TextMatrix;
if (!_matrix || global_MatrixTransformer.IsIdentity(_matrix))
{
var pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect1.x, this.RectSelect1.y, this.PageSelect1);
var pos2 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h, this.PageSelect1);
var pos3 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y, this.PageSelect2);
var pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h, this.PageSelect2);
var ctx = overlay.m_oContext;
ctx.strokeStyle = "#1B63BA";
ctx.moveTo(pos1.X >> 0, pos1.Y >> 0);
ctx.lineTo(pos2.X >> 0, pos2.Y >> 0);
ctx.moveTo(pos3.X >> 0, pos3.Y >> 0);
ctx.lineTo(pos4.X >> 0, pos4.Y >> 0);
ctx.lineWidth = 2;
ctx.stroke();
ctx.beginPath();
if (!window.g_table_track_round.asc_complete)
return;
var _w = window.g_table_track_round.width;
var _h = window.g_table_track_round.height;
var _x1 = (pos1.X - (_w / 2)) >> 0;
var _y1 = (pos1.Y - 5 - (_h / 2)) >> 0;
var _x2 = (pos4.X - (_w / 2)) >> 0;
var _y2 = (pos4.Y + 5 - (_h / 2)) >> 0;
ctx.drawImage(window.g_table_track_round, _x1, _y1);
ctx.drawImage(window.g_table_track_round, _x2, _y2);
overlay.CheckRect(_x1, _y1, _w, _h);
overlay.CheckRect(_x2, _y2, _w, _h);
}
else
{
var _xx11 = _matrix.TransformPointX(this.RectSelect1.x, this.RectSelect1.y);
var _yy11 = _matrix.TransformPointY(this.RectSelect1.x, this.RectSelect1.y);
var _xx12 = _matrix.TransformPointX(this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h);
var _yy12 = _matrix.TransformPointY(this.RectSelect1.x, this.RectSelect1.y + this.RectSelect1.h);
var _xx21 = _matrix.TransformPointX(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y);
var _yy21 = _matrix.TransformPointY(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y);
var _xx22 = _matrix.TransformPointX(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
var _yy22 = _matrix.TransformPointY(this.RectSelect2.x + this.RectSelect2.w, this.RectSelect2.y + this.RectSelect2.h);
var pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(_xx11, _yy11, this.PageSelect1);
var pos2 = this.DrawingDocument.ConvertCoordsToCursorWR(_xx12, _yy12, this.PageSelect1);
var pos3 = this.DrawingDocument.ConvertCoordsToCursorWR(_xx21, _yy21, this.PageSelect2);
var pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(_xx22, _yy22, this.PageSelect2);
var ctx = overlay.m_oContext;
ctx.strokeStyle = "#1B63BA";
ctx.moveTo(pos1.X, pos1.Y);
ctx.lineTo(pos2.X, pos2.Y);
ctx.moveTo(pos3.X, pos3.Y);
ctx.lineTo(pos4.X, pos4.Y);
ctx.lineWidth = 2;
ctx.stroke();
ctx.beginPath();
if (!window.g_table_track_round.asc_complete)
return;
var ex01 = _matrix.TransformPointX(0, 0);
var ey01 = _matrix.TransformPointY(0, 0);
var ex11 = _matrix.TransformPointX(0, 1);
var ey11 = _matrix.TransformPointY(0, 1);
var _len = Math.sqrt((ex11 - ex01)*(ex11 - ex01) + (ey11 - ey01)*(ey11 - ey01));
if (_len == 0)
_len = 0.01;
var ex = 5 * (ex11 - ex01) / _len;
var ey = 5 * (ey11 - ey01) / _len;
var _w = window.g_table_track_round.width;
var _h = window.g_table_track_round.height;
var _x1 = (pos1.X - ex - (_w / 2)) >> 0;
var _y1 = (pos1.Y - ey - (_h / 2)) >> 0;
var _x2 = (pos4.X + ex - (_w / 2)) >> 0;
var _y2 = (pos4.Y + ey - (_h / 2)) >> 0;
ctx.drawImage(window.g_table_track_round, _x1, _y1);
ctx.drawImage(window.g_table_track_round, _x2, _y2);
overlay.CheckRect(_x1, _y1, _w, _h);
overlay.CheckRect(_x2, _y2, _w, _h);
}
},
CheckTableRules : function(overlay)
{
if (this.HtmlPage.m_oApi.isViewMode)
return;
var horRuler = this.HtmlPage.m_oHorRuler;
var verRuler = this.HtmlPage.m_oVerRuler;
var _table_outline_dr = this.DrawingDocument.TableOutlineDr;
var _tableOutline = _table_outline_dr.TableOutline;
if (horRuler.CurrentObjectType != RULER_OBJECT_TYPE_TABLE || verRuler.CurrentObjectType != RULER_OBJECT_TYPE_TABLE || !_tableOutline)
{
this.TableMovePoint = null;
this.TableHorRulerPoints = null;
this.TableVerRulerPoints = null;
return;
}
var _table_markup = horRuler.m_oTableMarkup;
this.HtmlPage.CheckShowOverlay();
var _epsRects = this.TableRulersRectOffset;
var _rectWidth = this.TableRulersRectSize;
var ctx = overlay.m_oContext;
ctx.fillStyle = "#F0F0F0";
ctx.strokeStyle = "#000000";
ctx.lineWidth = 1;
var _tableW = 0;
var _cols = _table_markup.Cols;
for (var i = 0; i < _cols.length; i++)
{
_tableW += _cols[i];
}
if (!_table_outline_dr.TableMatrix || global_MatrixTransformer.IsIdentity(_table_outline_dr.TableMatrix))
{
this.TableMovePoint = { X : _tableOutline.X, Y : _tableOutline.Y };
var pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(_tableOutline.X, _tableOutline.Y, _tableOutline.PageNum);
var pos2 = this.DrawingDocument.ConvertCoordsToCursorWR(_tableOutline.X + _tableW, _tableOutline.Y, _tableOutline.PageNum);
ctx.beginPath();
var TableMoveRect_x = (pos1.X >> 0) + 0.5 - (_epsRects + _rectWidth);
var TableMoveRect_y = (pos1.Y >> 0) + 0.5 - (_epsRects + _rectWidth);
overlay.AddRect(TableMoveRect_x, TableMoveRect_y, _rectWidth, _rectWidth);
overlay.AddRect((pos1.X >> 0) + 0.5, TableMoveRect_y, (pos2.X - pos1.X) >> 0, _rectWidth);
var _count = _table_markup.Rows.length;
var _y1 = 0;
var _y2 = 0;
for (var i = 0; i < _count; i++)
{
if (i == 0)
_y1 = _table_markup.Rows[i].Y;
_y2 = _table_markup.Rows[i].Y;
_y2 += _table_markup.Rows[i].H;
}
var pos3 = this.DrawingDocument.ConvertCoordsToCursorWR(_tableOutline.X, _y1, this.DrawingDocument.m_lCurrentPage);
var pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(_tableOutline.X, _y2, this.DrawingDocument.m_lCurrentPage);
overlay.AddRect((pos1.X >> 0) + 0.5 - (_epsRects + _rectWidth), (pos3.Y >> 0) + 0.5, _rectWidth, (pos4.Y - pos3.Y) >> 0);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "#FFFFFF";
ctx.strokeStyle = "#0000FF";
var dKoef = (this.HtmlPage.m_nZoomValue * g_dKoef_mm_to_pix / 100);
var xDst = this.DrawingDocument.m_arrPages[this.DrawingDocument.m_lCurrentPage].drawingPage.left;
var yDst = this.DrawingDocument.m_arrPages[this.DrawingDocument.m_lCurrentPage].drawingPage.top;
var _oldY = _table_markup.Rows[0].Y + _table_markup.Rows[0].H;
this.TableVerRulerPoints = [];
var _rectIndex = 0;
var _x = (pos1.X >> 0) + 0.5 - (_epsRects + _rectWidth);
for (var i = 1; i <= _count; i++)
{
var _newPos = (i != _count) ? _table_markup.Rows[i].Y : _oldY;
var _p = { Y : _oldY, H : (_newPos - _oldY) };
var _r_x = _x;
var _r_y = ((yDst + dKoef * _oldY) >> 0) + 0.5;
var _r_h = ((_newPos - _oldY) * dKoef) >> 0;
overlay.AddRect(_r_x, _r_y, _rectWidth, _r_h);
this.TableVerRulerPoints[_rectIndex++] = _p;
if (i != _count)
_oldY = _table_markup.Rows[i].Y + _table_markup.Rows[i].H;
}
this.TableHorRulerPoints = [];
_rectIndex = 0;
var _col = _table_markup.X;
for (var i = 1; i <= _cols.length; i++)
{
_col += _cols[i - 1];
var _x = _col - _table_markup.Margins[i - 1].Right;
var _r = _col + ((i == _cols.length) ? 0 : _table_markup.Margins[i].Left);
var __x = ((xDst + dKoef * _x) >> 0) + 0.5;
var __r = ((xDst + dKoef * _r) >> 0) + 0.5;
overlay.AddRect(__x, TableMoveRect_y, __r - __x, _rectWidth);
this.TableHorRulerPoints[_rectIndex++] = { X : _x, W : _r - _x, C : _col };
}
ctx.fill();
ctx.stroke();
ctx.beginPath();
if (this.Mode == MobileTouchMode.TableRuler)
{
if (0 == this.TableCurrentMoveDir)
{
var _pos = this.DrawingDocument.ConvertCoordsToCursorWR(this.TableCurrentMoveValue, 0, _table_outline_dr.CurrentPageIndex);
overlay.VertLine(_pos.X, true);
}
else
{
var _pos = this.DrawingDocument.ConvertCoordsToCursorWR(0, this.TableCurrentMoveValue, _table_outline_dr.CurrentPageIndex);
overlay.HorLine(_pos.Y, true);
}
}
}
else
{
var dKoef = (this.HtmlPage.m_nZoomValue * g_dKoef_mm_to_pix / 100);
var xDst = this.DrawingDocument.m_arrPages[this.DrawingDocument.m_lCurrentPage].drawingPage.left;
var yDst = this.DrawingDocument.m_arrPages[this.DrawingDocument.m_lCurrentPage].drawingPage.top;
ctx.lineWidth = 1 / dKoef;
var _coord_transform = new CMatrix();
_coord_transform.sx = dKoef;
_coord_transform.sy = dKoef;
_coord_transform.tx = xDst;
_coord_transform.ty = yDst;
_coord_transform.Multiply(_table_outline_dr.TableMatrix, MATRIX_ORDER_PREPEND);
ctx.setTransform(_coord_transform.sx,_coord_transform.shy,_coord_transform.shx,_coord_transform.sy,_coord_transform.tx,_coord_transform.ty);
this.TableMovePoint = { X : _tableOutline.X, Y : _tableOutline.Y };
ctx.beginPath();
var _rectW = _rectWidth / dKoef;
var _offset = (_epsRects + _rectWidth) / dKoef;
ctx.rect(this.TableMovePoint.X - _offset, this.TableMovePoint.Y - _offset, _rectW, _rectW);
ctx.rect(this.TableMovePoint.X, this.TableMovePoint.Y - _offset, _tableW, _rectW);
var _count = _table_markup.Rows.length;
var _y1 = 0;
var _y2 = 0;
for (var i = 0; i < _count; i++)
{
if (i == 0)
_y1 = _table_markup.Rows[i].Y;
_y2 = _table_markup.Rows[i].Y;
_y2 += _table_markup.Rows[i].H;
}
ctx.rect(this.TableMovePoint.X - _offset, this.TableMovePoint.Y, _rectW, _y2 - _y1);
overlay.CheckRectT(this.TableMovePoint.X, this.TableMovePoint.Y, _tableW, _y2 - _y1, _coord_transform, 2 * (_epsRects + _rectWidth));
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = "#FFFFFF";
ctx.strokeStyle = "#0000FF";
var _oldY = _table_markup.Rows[0].Y + _table_markup.Rows[0].H;
_oldY -= _table_outline_dr.TableMatrix.ty;
this.TableVerRulerPoints = [];
var _rectIndex = 0;
var _xx = this.TableMovePoint.X - _offset;
for (var i = 1; i <= _count; i++)
{
var _newPos = (i != _count) ? (_table_markup.Rows[i].Y - _table_outline_dr.TableMatrix.ty) : _oldY;
var _p = { Y : _oldY, H : (_newPos - _oldY) };
ctx.rect(_xx, _p.Y, _rectW, _p.H);
this.TableVerRulerPoints[_rectIndex++] = _p;
if (i != _count)
{
_oldY = _table_markup.Rows[i].Y + _table_markup.Rows[i].H;
_oldY -= _table_outline_dr.TableMatrix.ty;
}
}
this.TableHorRulerPoints = [];
_rectIndex = 0;
var _col = this.TableMovePoint.X;
for (var i = 1; i <= _cols.length; i++)
{
_col += _cols[i - 1];
var _x = _col - _table_markup.Margins[i - 1].Right;
var _r = _col + ((i == _cols.length) ? 0 : _table_markup.Margins[i].Left);
ctx.rect(_x, this.TableMovePoint.Y - _offset, _r - _x, _rectW);
this.TableHorRulerPoints[_rectIndex++] = { X : _x, W : _r - _x, C : _col };
}
ctx.fill();
ctx.stroke();
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.beginPath();
if (this.Mode == MobileTouchMode.TableRuler)
{
if (0 == this.TableCurrentMoveDir)
{
var _pos = this.DrawingDocument.ConvertCoordsToCursorWR(this.TableCurrentMoveValue, 0, _table_outline_dr.CurrentPageIndex, _table_outline_dr.TableMatrix);
overlay.VertLine(_pos.X, true);
}
else
{
var _pos = this.DrawingDocument.ConvertCoordsToCursorWR(0, this.TableCurrentMoveValue,_table_outline_dr.CurrentPageIndex, _table_outline_dr.TableMatrix);
overlay.HorLine(_pos.Y, true);
}
}
}
},
CheckTableRules2 : function(overlay)
{
if (this.HtmlPage.m_oApi.isViewMode)
return;
var horRuler = this.HtmlPage.m_oHorRuler;
var verRuler = this.HtmlPage.m_oVerRuler;
var _table_outline_dr = this.DrawingDocument.TableOutlineDr;
var _tableOutline = _table_outline_dr.TableOutline;
if (horRuler.CurrentObjectType != RULER_OBJECT_TYPE_TABLE || verRuler.CurrentObjectType != RULER_OBJECT_TYPE_TABLE || !_tableOutline)
{
this.TableMovePoint = null;
this.TableHorRulerPoints = null;
this.TableVerRulerPoints = null;
return;
}
if (!window.g_table_track_mobile_move.asc_complete || !window.g_table_track_round.asc_complete || !window.g_table_track_diamond.asc_complete)
return;
var _table_markup = horRuler.m_oTableMarkup;
this.HtmlPage.CheckShowOverlay();
var _epsRects = this.TableRulersRectOffset;
var _rectWidth = this.TableRulersRectSize;
var ctx = overlay.m_oContext;
ctx.strokeStyle = "#616161";
ctx.lineWidth = 1;
var _tableW = 0;
var _cols = _table_markup.Cols;
for (var i = 0; i < _cols.length; i++)
{
_tableW += _cols[i];
}
if (!_table_outline_dr.TableMatrix || global_MatrixTransformer.IsIdentity(_table_outline_dr.TableMatrix))
{
this.TableMovePoint = { X : _tableOutline.X, Y : _tableOutline.Y };
var pos1 = this.DrawingDocument.ConvertCoordsToCursorWR(_tableOutline.X, _tableOutline.Y, _tableOutline.PageNum);
var pos2 = this.DrawingDocument.ConvertCoordsToCursorWR(_tableOutline.X + _tableW, _tableOutline.Y, _tableOutline.PageNum);
ctx.beginPath();
var TableMoveRect_x = (pos1.X >> 0) + 0.5 - (_epsRects + _rectWidth);
var TableMoveRect_y = (pos1.Y >> 0) + 0.5 - (_epsRects + _rectWidth);
overlay.CheckPoint(TableMoveRect_x, TableMoveRect_y);
overlay.CheckPoint(TableMoveRect_x + _rectWidth, TableMoveRect_y + _rectWidth);
ctx.drawImage(window.g_table_track_mobile_move, TableMoveRect_x, TableMoveRect_y);
var gradObj = ctx.createLinearGradient((pos1.X >> 0) + 0.5, TableMoveRect_y, (pos1.X >> 0) + 0.5, TableMoveRect_y + _rectWidth);
gradObj.addColorStop(0, "#f1f1f1");
gradObj.addColorStop(1, "#dfdfdf");
ctx.fillStyle = gradObj;
overlay.AddRoundRect((pos1.X >> 0) + 0.5, TableMoveRect_y, (pos2.X - pos1.X) >> 0, _rectWidth, 4);
ctx.fill();
ctx.stroke();
ctx.beginPath();
var _count = _table_markup.Rows.length;
var _y1 = 0;
var _y2 = 0;
for (var i = 0; i < _count; i++)
{
if (i == 0)
_y1 = _table_markup.Rows[i].Y;
_y2 = _table_markup.Rows[i].Y;
_y2 += _table_markup.Rows[i].H;
}
var pos3 = this.DrawingDocument.ConvertCoordsToCursorWR(_tableOutline.X, _y1, this.DrawingDocument.m_lCurrentPage);
var pos4 = this.DrawingDocument.ConvertCoordsToCursorWR(_tableOutline.X, _y2, this.DrawingDocument.m_lCurrentPage);
var _ttX = (pos1.X >> 0) + 0.5 - (_epsRects + _rectWidth);
gradObj = ctx.createLinearGradient(_ttX, (pos3.Y >> 0) + 0.5, _ttX, (pos3.Y >> 0) + 0.5 + (pos4.Y - pos3.Y) >> 0);
gradObj.addColorStop(0, "#f1f1f1");
gradObj.addColorStop(1, "#dfdfdf");
ctx.fillStyle = gradObj;
overlay.AddRoundRect((pos1.X >> 0) + 1.5 - (_epsRects + _rectWidth), (pos3.Y >> 0) + 0.5, _rectWidth - 1, (pos4.Y - pos3.Y) >> 0, 4);
ctx.fill();
ctx.stroke();
ctx.beginPath();
var ___w = window.g_table_track_diamond.width;
var ___h = window.g_table_track_diamond.height;
var dKoef = (this.HtmlPage.m_nZoomValue * g_dKoef_mm_to_pix / 100);
var xDst = this.DrawingDocument.m_arrPages[this.DrawingDocument.m_lCurrentPage].drawingPage.left;
var yDst = this.DrawingDocument.m_arrPages[this.DrawingDocument.m_lCurrentPage].drawingPage.top;
var _oldY = _table_markup.Rows[0].Y + _table_markup.Rows[0].H;
this.TableVerRulerPoints = [];
var _rectIndex = 0;
var _x = (pos1.X >> 0) + 0.5 - (_epsRects + _rectWidth);
for (var i = 1; i <= _count; i++)
{
var _newPos = (i != _count) ? _table_markup.Rows[i].Y : _oldY;
var _p = { Y : _oldY, H : (_newPos - _oldY) };
var _r_x = _x;
var _r_y = ((yDst + dKoef * _oldY) >> 0) + 0.5;
var _r_h = ((_newPos - _oldY) * dKoef) >> 0;
var xImage = (_r_x + 1) >> 0;
var yImage = (_r_y + (_r_h / 2) - (___h / 2)) >> 0;
overlay.CheckRect(xImage, yImage, ___w, ___h);
ctx.drawImage(window.g_table_track_diamond, xImage, yImage);
this.TableVerRulerPoints[_rectIndex++] = _p;
if (i != _count)
_oldY = _table_markup.Rows[i].Y + _table_markup.Rows[i].H;
}
this.TableHorRulerPoints = [];
_rectIndex = 0;
var _col = _table_markup.X;
for (var i = 1; i <= _cols.length; i++)
{
_col += _cols[i - 1];
var _x = _col - _table_markup.Margins[i - 1].Right;
var _r = _col + ((i == _cols.length) ? 0 : _table_markup.Margins[i].Left);
var __x = ((xDst + dKoef * _x) >> 0) + 0.5;
var __r = ((xDst + dKoef * _r) >> 0) + 0.5;
var __c = ((xDst + dKoef * _col) >> 0) + 0.5;
var xImage = (__c - (___w / 2)) >> 0;
var yImage = (TableMoveRect_y + 1) >> 0;
overlay.CheckRect(xImage, yImage, ___w, ___h);
ctx.drawImage(window.g_table_track_diamond, xImage, yImage);
this.TableHorRulerPoints[_rectIndex++] = { X : _x, W : _r - _x, C : _col };
}
ctx.beginPath();
if (this.Mode == MobileTouchMode.TableRuler)
{
if (0 == this.TableCurrentMoveDir)
{
var _pos = this.DrawingDocument.ConvertCoordsToCursorWR(this.TableCurrentMoveValue, 0, _table_outline_dr.CurrentPageIndex);
overlay.VertLine(_pos.X, true);
}
else
{
var _pos = this.DrawingDocument.ConvertCoordsToCursorWR(0, this.TableCurrentMoveValue, _table_outline_dr.CurrentPageIndex);
overlay.HorLine(_pos.Y, true);
}
}
}
else
{
var dKoef = (this.HtmlPage.m_nZoomValue * g_dKoef_mm_to_pix / 100);
var xDst = this.DrawingDocument.m_arrPages[this.DrawingDocument.m_lCurrentPage].drawingPage.left;
var yDst = this.DrawingDocument.m_arrPages[this.DrawingDocument.m_lCurrentPage].drawingPage.top;
ctx.lineWidth = 1 / dKoef;
var _coord_transform = new CMatrix();
_coord_transform.sx = dKoef;
_coord_transform.sy = dKoef;
_coord_transform.tx = xDst;
_coord_transform.ty = yDst;
_coord_transform.Multiply(_table_outline_dr.TableMatrix, MATRIX_ORDER_PREPEND);
ctx.setTransform(_coord_transform.sx,_coord_transform.shy,_coord_transform.shx,_coord_transform.sy,_coord_transform.tx,_coord_transform.ty);
this.TableMovePoint = { X : _tableOutline.X, Y : _tableOutline.Y };
ctx.beginPath();
var _rectW = _rectWidth / dKoef;
var _offset = (_epsRects + _rectWidth) / dKoef;
ctx.drawImage(window.g_table_track_mobile_move, this.TableMovePoint.X - _offset, this.TableMovePoint.Y - _offset, _rectW, _rectW);
var gradObj = ctx.createLinearGradient(this.TableMovePoint.X, this.TableMovePoint.Y - _offset, this.TableMovePoint.X, this.TableMovePoint.Y - _offset + _rectW);
gradObj.addColorStop(0, "#f1f1f1");
gradObj.addColorStop(1, "#dfdfdf");
ctx.fillStyle = gradObj;
overlay.AddRoundRectCtx(ctx, this.TableMovePoint.X, this.TableMovePoint.Y - _offset, _tableW, _rectW, 5 / dKoef);
ctx.fill();
ctx.stroke();
ctx.beginPath();
var _count = _table_markup.Rows.length;
var _y1 = 0;
var _y2 = 0;
for (var i = 0; i < _count; i++)
{
if (i == 0)
_y1 = _table_markup.Rows[i].Y;
_y2 = _table_markup.Rows[i].Y;
_y2 += _table_markup.Rows[i].H;
}
gradObj = ctx.createLinearGradient(this.TableMovePoint.X - _offset, this.TableMovePoint.Y, this.TableMovePoint.X - _offset, this.TableMovePoint.X - _offset + _y2 - _y1);
gradObj.addColorStop(0, "#f1f1f1");
gradObj.addColorStop(1, "#dfdfdf");
ctx.fillStyle = gradObj;
overlay.AddRoundRectCtx(ctx, this.TableMovePoint.X - _offset, this.TableMovePoint.Y, _rectW, _y2 - _y1, 5 / dKoef);
overlay.CheckRectT(this.TableMovePoint.X, this.TableMovePoint.Y, _tableW, _y2 - _y1, _coord_transform, 2 * (_epsRects + _rectWidth));
ctx.fill();
ctx.stroke();
ctx.beginPath();
var _oldY = _table_markup.Rows[0].Y + _table_markup.Rows[0].H;
_oldY -= _table_outline_dr.TableMatrix.ty;
var ___w = window.g_table_track_diamond.width;
var ___h = window.g_table_track_diamond.height;
this.TableVerRulerPoints = [];
var _rectIndex = 0;
var _xx = this.TableMovePoint.X - _offset;
for (var i = 1; i <= _count; i++)
{
var _newPos = (i != _count) ? (_table_markup.Rows[i].Y - _table_outline_dr.TableMatrix.ty) : _oldY;
var _p = { Y : _oldY, H : (_newPos - _oldY) };
var ___y = (_p.Y + (_p.H / 2) - ((___h / dKoef) / 2));
ctx.drawImage(window.g_table_track_diamond, _xx, ___y, ___w / dKoef, ___h / dKoef);
this.TableVerRulerPoints[_rectIndex++] = _p;
if (i != _count)
{
_oldY = _table_markup.Rows[i].Y + _table_markup.Rows[i].H;
_oldY -= _table_outline_dr.TableMatrix.ty;
}
}
this.TableHorRulerPoints = [];
_rectIndex = 0;
var _col = this.TableMovePoint.X;
for (var i = 1; i <= _cols.length; i++)
{
_col += _cols[i - 1];
var _x = _col - _table_markup.Margins[i - 1].Right;
var _r = _col + ((i == _cols.length) ? 0 : _table_markup.Margins[i].Left);
var ___x = (_col - ((___w / dKoef) / 2));
ctx.drawImage(window.g_table_track_diamond, ___x, (this.TableMovePoint.Y - _offset), ___w / dKoef, ___h / dKoef);
this.TableHorRulerPoints[_rectIndex++] = { X : _x, W : _r - _x, C : _col };
}
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.beginPath();
if (this.Mode == MobileTouchMode.TableRuler)
{
if (0 == this.TableCurrentMoveDir)
{
var _pos = this.DrawingDocument.ConvertCoordsToCursorWR(this.TableCurrentMoveValue, 0, _table_outline_dr.CurrentPageIndex, _table_outline_dr.TableMatrix);
overlay.VertLine(_pos.X, true);
}
else
{
var _pos = this.DrawingDocument.ConvertCoordsToCursorWR(0, this.TableCurrentMoveValue,_table_outline_dr.CurrentPageIndex, _table_outline_dr.TableMatrix);
overlay.HorLine(_pos.Y, true);
}
}
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment