📄 events.js
字号:
/*
Copyright 2006 Christian Gross http://www.devspace.com
From the book Ajax Patterns and Best Practices
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
function DecoupledNavigation() {
}
function DecoupledNavigation_call( evt, action, data, presentation) {
evt = (evt) ? evt : ((event) ? event : null);
if ( evt) {
var elem = (evt.target) ? evt.target :
((evt.srcElement) ? evt.srcElement : null);
if ( elem) {
var obj = new Object();
obj.event = evt;
obj.parent = this;
obj.element = elem;
obj.state = new Object();
obj.presentation = presentation;
if ( (action) != null) {
if ( action( obj) != true) {
return false;
}
}
obj.isRemote = false;
if ( (data) != null) {
if ( data( obj) != true) {
return false;
}
}
if ( obj.isRemote == false && (presentation) != null) {
if ( presentation( obj, obj.state) != true) {
return false;
}
}
return true;
}
}
return true;
}
function DecoupledNavigation_InitializeRemote( obj) {
obj.async = new Asynchronous();
obj.complete = function( obj, status, statusText, responseText, responseXML) {}
obj.openCallback = function( xmlhttp) {}
obj.async.openCallback = function( xmlhttp) {
obj.openCallback( xmlhttp);
};
obj.async.complete = function( status, statusText, responseText, responseXML) {
if ( (obj.complete) != null) {
if ( obj.complete( obj, status, statusText, responseText, responseXML) == true) {
if ( (obj.presentation) != null) {
obj.presentation( obj, obj.state);
}
}
}
}
obj.isRemote = true;
}
DecoupledNavigation.prototype.call = DecoupledNavigation_call;
DecoupledNavigation.prototype.initializeRemote = DecoupledNavigation_InitializeRemote;
// ********
// Controls
// Simple injection control
function TextState( ctrlId, text) {
this.id = ctrlId;
this.text = text;
}
function InjectHTML( evtData, state) {
document.getElementById( state.id).innerHTML = state.text;
}
//*******************
// Draggable layer
/**************************************************************
Dragable layer creator
By Mark Wilton-Jones 14/10/2002
v1.0.2 updated 21/07/2005 for mouseup-over-chrome click-release
***************************************************************
Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use
To use:
Inbetween the <head> tags, put:
<script src="PATH TO SCRIPT/draglayer.js" type="text/javascript" language="javascript1.2"></script>
To create a dragable layer put:
<script type="text/javascript" language="javascript1.2"><!--
createDragableLayer(
'This layer is dragable', //contents of dragable layer (can contain HTML etc.)
10, //left coordinate of dragable layer
100, //top coordinate of dragable layer
150, //width of dragable layer
30, //optional: height of dragable layer (use null for default)
'#ff0000' //optional: background colour of dragable layer (use null for default)
);
//--></script>
___________________________________________________________________________________________*/
function createDragableLayer(layerContent,leftPos,topPos,layerWidth,layerHeight,layerBG) {
if ( document.layers ) {
document.write( '<layer left="'+leftPos+'" top="'+topPos+'" width="'+layerWidth+'" '+(layerHeight?('height="'+layerHeight+'" '):'')+(layerBG?('bgcolor="'+layerBG+'" '):'')+'onmouseover="this.captureEvents(Event.MOUSEDOWN);this.onmousedown=dragIsDown;">'+layerContent+'</layer>' );
} else {
document.write( '<div style="position:absolute;left:'+leftPos+'px;top:'+topPos+'px;width:'+layerWidth+'px;'+(layerHeight?('height:'+layerHeight+'px;'):'')+(layerBG?('background-color:'+layerBG+';'):'')+'" onmouseover="this.onmousedown=dragIsDown;" ondragstart="return false;" onselectstart="return false;">'+layerContent+'</div>' );
}
}
function dragMousePos(e) {
//get the position of the mouse
if ( !e ) {
e = window.event;
}if ( !e || ( typeof( e.pageX ) != 'number' && typeof( e.clientX ) != 'number' ) ) {
return [0,0];
}
if ( typeof( e.pageX ) == 'number' ) {
var xcoord = e.pageX; var ycoord = e.pageY;
} else {
var xcoord = e.clientX; var ycoord = e.clientY;
if ( !( ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) || ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) || window.navigator.vendor == 'KDE' ) ) {
if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) {
xcoord += document.documentElement.scrollLeft; ycoord += document.documentElement.scrollTop;
} else if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) {
xcoord += document.body.scrollLeft; ycoord += document.body.scrollTop;
}
}
}
return [xcoord,ycoord];
}
function dragIsDown(e) {
//make note of starting positions and detect mouse movements
if ( ( e && ( e.which > 1 || e.button > 1 ) ) || ( window.event && ( window.event.which > 1 || window.event.button > 1 ) ) ) {
return false;
}
if ( document.onmouseup == dragIsMove ) {
document.onmousemove = storeMOUSEMOVE; document.onmouseup = window.storeMOUSEUP;
} //mouseup was over chrome
window.msStartCoord = dragMousePos(e); window.lyStartCoord = this.style?[parseInt(this.style.left),parseInt(this.style.top)]:[parseInt(this.left),parseInt(this.top)];
if ( document.captureEvents && Event.MOUSEMOVE ) {
document.captureEvents(Event.MOUSEMOVE); document.captureEvents(Event.MOUSEUP);
}
window.storeMOUSEMOVE = document.onmousemove; window.storeMOUSEUP = document.onmouseup; window.storeLayer = this;
document.onmousemove = dragIsMove; document.onmouseup = dragIsMove; return false;
}
function dragIsMove(e) {
//move the layer to its newest position
var msMvCo = dragMousePos(e); if ( !e ) {
e = window.event ? window.event : ( new Object() );
}
var newX = window.lyStartCoord[0] + ( msMvCo[0] - window.msStartCoord[0] );
var newY = window.lyStartCoord[1] + ( msMvCo[1] - window.msStartCoord[1] );
//reset the mouse monitoring as before - delay needed by Gecko to stop jerky response (hence two functions instead of one)
//as long as the Gecko user does not release one layer then click on another within 1ms (!) this will cause no problems
if ( e.type && e.type.toLowerCase() == 'mouseup' ) {
document.onmousemove = storeMOUSEMOVE; document.onmouseup = window.storeMOUSEUP;
}
if ( navigator.product == 'Gecko' ) {
window.setTimeout('dragIsMove2('+newX+','+newY+');',1);
} else {
dragIsMove2(newX,newY);
}
}
function dragIsMove2(x,y) { var oPix = ( document.childNodes ? 'px' : 0 ), theLayer = ( window.storeLayer.style ? window.storeLayer.style : window.storeLayer ); theLayer.left = x + oPix; theLayer.top = y + oPix;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -