Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jsfw = function () {
- _self=this;
- //-------------------------------------
- // init object
- //-------------------------------------
- this.init=function() {
- this.helper = new this.f_helper();
- window.onload=this.Handlers.win_load;
- }
- //-------------------------------------
- // startup object
- //-------------------------------------
- this.startup=function() {
- this.setup_common_Events();
- this.setupEvents('window');
- this.doc = new this.f_doc();
- //this.setupEvents('this.doc.test_element');
- }
- //-------------------------------------
- // setup common events
- //-------------------------------------
- this.setup_common_Events=function() {
- window.onscroll= this.Handlers.window_scroll;
- window.onresize= this.Handlers.window_resize;
- window.onselectstart = this.Handlers.select_start;
- window.oncontextmenu = this.Handlers.context_menu;
- window.onkeydown = this.Handlers.key_down;
- window.onkeypress = this.Handlers.key_press;
- window.onkeyup = this.Handlers.key_up;
- this.helper.add_event(document,'mousewheel',this.Handlers.mouse_wheel);
- }
- //-------------------------------------
- // setup events
- //-------------------------------------
- this.setupEvents=function(el_string) {
- var el = eval(el_string);
- el.onmousemove= this.Handlers.mouse_move;
- el.onmousedown= this.Handlers.mouse_down;
- el.onmouseup= this.Handlers.mouse_up;
- el.onmouseover= this.Handlers.mouse_over;
- el.onmouseout= this.Handlers.mouse_out;
- };
- //-------------------------------------------------
- // event handlers
- //-------------------------------------------------
- this.Handlers= {
- //---------------------window load
- win_load: function() {
- _self.startup();
- },
- //--------------------------mouse move
- mouse_move: function(e) {
- s_ev = _self.helper.get_event_info(e, this);
- //_self.helper.show_event_info(e, this, 'mouse_move', this.suffix);
- //----------------mouse coords (considering scroll)
- var pageX = s_ev.s_event.clientX +
- (document.documentElement && document.documentElement.scrollLeft ||
- document.body && document.body.scrollLeft || 0) -
- (document.documentElement.clientLeft || 0);
- var pageY = s_ev.s_event.clientY +
- (document.documentElement && document.documentElement.scrollTop ||
- document.body && document.body.scrollTop || 0) -
- (document.documentElement.clientTop || 0);
- //-------------------------mouse coords
- _self.doc.status.mouse_coords =
- s_ev.s_event.clientX+'-'+
- s_ev.s_event.clientY+' ('+pageX+'-'+pageY+')';
- },
- //---------------------------------mouse down
- mouse_down: function(e) {
- _self.helper.show_event_info(e, this, 'mouse_down', this.suffix);
- //--------------------------mouse button
- _self.doc.status.mouse_button = _self.helper.get_mouse_button(e);
- _self.helper.stop_event(e);
- },
- //----------------------------------mouse up
- mouse_up: function(e) {
- _self.helper.show_event_info(e, this, 'mouse_up', this.suffix);
- _self.doc.status.mouse_button = _self.helper.get_mouse_button(e);
- },
- //------------------------------window scroll
- window_scroll: function(e) {
- _self.helper.show_event_info(e, this, 'window_scroll' );
- },
- //-------------------------------window resize
- window_resize: function(e) {
- _self.helper.show_event_info(e, this, 'window_resize');
- },
- //-------------------------------mouse wheel
- mouse_wheel: function(e) {
- s_ev = _self.helper.get_event_info(e, this);
- _self.helper.show_event_info(e, this, 'mouse_wheel')
- //------------------set wheel delta
- _self.doc.status.wheel_delta=
- s_ev.s_event.wheelDelta;
- },
- //----------------------------------select start
- select_start: function(e) {
- _self.helper.show_event_info(e, this, 'select_start');
- },
- //---------------------------------context menu
- context_menu: function(e) {
- _self.helper.show_event_info(e, this, 'context_menu');
- },
- //----------------------------------key down
- key_down: function(e) {
- s_ev = _self.helper.get_event_info(e, this);
- //---------------key and char codes
- _self.doc.status.key_code = s_ev.s_event.keyCode;
- _self.doc.status.alt_key = s_ev.s_event.altKey;
- _self.doc.status.ctrl_key = s_ev.s_event.ctrlKey;
- //_self.doc.status.char_code = s_ev.s_event.charCode;
- _self.helper.show_event_info(e, this, 'key_down');
- },
- //-----------------------------------key press
- key_press: function(e) {
- s_ev = _self.helper.get_event_info(e, this);
- //---------------key and char codes
- //_self.doc.status.key_code = s_ev.s_event.keyCode;
- _self.doc.status.char_code = s_ev.s_event.charCode;
- //---------------alt and ctrl keys
- _self.helper.show_event_info(e, this, 'key_press');
- },
- //-----------------------------------key up
- key_up: function(e) {
- s_ev = _self.helper.get_event_info(e, this);
- //---------------key and char codes
- _self.doc.status.key_code = s_ev.s_event.keyCode;
- //_self.doc.status.char_code = s_ev.s_event.charCode;
- _self.helper.show_event_info(e, this, 'key_up');
- },
- //-----------------------------------mouse over
- mouse_over: function(e) {
- _self.helper.show_event_info(e, this, 'mouse_over', this.suffix);
- },
- //-----------------------------------mouse out
- mouse_out: function(e) {
- _self.helper.show_event_info(e, this, 'mouse_out', this.suffix);
- }
- }
- //----------------------------------------------------------
- // doc glob obj
- //----------------------------------------------------------
- this.f_doc=function() {
- _dself=this;
- //-------------------------doc status
- this.status = {
- page_width:'',
- page_height:'',
- scroll_page_width:'',
- scroll_page_height:'',
- //-------------------------
- window_outer_width:'',
- window_outer_height:'',
- window_inner_width:'',
- window_inner_height:'',
- window_x_position:'',
- window_y_position:'',
- //-------------------------
- screen_width:'',
- screen_height:'',
- screen_avail_width:'',
- screen_avail_height:'',
- screen_color_depth:'',
- //-------------------------
- navigator_appname:'',
- navigator_appversion:'',
- navigator_cookieenabled:'',
- navigator_platform:'',
- navigator_useragent:'',
- //-------------------------
- scroll_left:'',
- scroll_top:'',
- //-------------------------
- mouse_coords:'',
- mouse_button:'',
- wheel_delta:'',
- key_code:'',
- char_code:'',
- alt_key:'',
- ctrl_key:'',
- //-------------------------
- current_time:''
- }
- //------------------------doc initialization
- this.init = function () {
- //-----------------------------------active info
- var inf_els = [
- {info_caption: 'scroll left: ', info_id: 'scroll_left'},
- {info_caption: 'scroll top: ', info_id: 'scroll_top'},
- {info_caption: 'mouse coords: ', info_id: 'mouse_coords'},
- {info_caption: 'mouse button: ', info_id: 'mouse_button'},
- {info_caption: 'wheel delta: ', info_id: 'wheel_delta'},
- {info_caption: 'key code: ', info_id: 'key_code'},
- {info_caption: 'char code: ', info_id: 'char_code'},
- {info_caption: 'alt key: ', info_id: 'alt_key'},
- {info_caption: 'ctrl key: ', info_id: 'ctrl_key'},
- {info_caption: 'current time: ', info_id: 'current_time'}
- ];
- this.active_info_element= _self.helper.crInfoBlock('active info', inf_els);
- //--------------------------------------events info
- var inf_els = [
- {info_caption: 'current event: ', info_id: 'current_event'},
- {info_caption: 'event target: ', info_id: 'event_target'},
- {info_caption: 'event target id: ', info_id: 'event_target_id'},
- {info_caption: 'event catcher: ', info_id: 'event_catcher'},
- {info_caption: 'event catcher id: ', info_id: 'event_catcher_id'},
- {info_caption: 'event type: ', info_id: 'event_type'},
- {info_caption: 'event rel target: ', info_id: 'event_reltarget'},
- {info_caption: 'event rel target id: ', info_id: 'event_reltarget_id'}
- ];
- this.events_info_element= _self.helper.crInfoBlock('event info', inf_els );
- var suffix='4';
- this.events_info_element_alt = _self.helper.crInfoBlock('event info alt', inf_els,suffix);
- //-------------------------------common info
- var inf_els = [
- {info_caption: 'page width: ', info_id: 'page_width'},
- {info_caption: 'page height: ', info_id: 'page_height'},
- {info_caption: 'scroll page width: ', info_id: 'scroll_page_width'},
- {info_caption: 'scroll page height: ', info_id: 'scroll_page_height'},
- {info_caption: 'window outer width: ', info_id: 'window_outer_width'},
- {info_caption: 'window outer height: ', info_id: 'window_outer_height'},
- {info_caption: 'window inner width: ', info_id: 'window_inner_width'},
- {info_caption: 'window inner height: ', info_id: 'window_inner_height'},
- {info_caption: 'window X: ', info_id: 'window_x_position'},
- {info_caption: 'window Y: ', info_id: 'window_y_position'}
- ];
- this.common_info_element= _self.helper.crInfoBlock('common info', inf_els );
- //---------------------------------system info
- info_els = [
- {info_caption: 'screen width: ', info_id: 'screen_width'},
- {info_caption: 'screen height: ', info_id: 'screen_height'},
- {info_caption: 'screen available width: ', info_id: 'screen_avail_width'},
- {info_caption: 'screen available height: ', info_id: 'screen_avail_height'},
- {info_caption: 'screen color depth: ', info_id: 'screen_color_depth'},
- {info_caption: 'navigator app name: ', info_id: 'navigator_appname'},
- {info_caption: 'navigator app version: ', info_id: 'navigator_appversion'},
- {info_caption: 'navigator cookie enabled: ', info_id: 'navigator_cookieenabled'},
- {info_caption: 'navigator platform: ', info_id: 'navigator_platform'},
- {info_caption: 'navigator user agent: ', info_id: 'navigator_useragent'},
- ]
- this.system_info_element = _self.helper.crInfoBlock('system info', info_els);
- //---------------------------------block position info
- info_els = [
- {info_caption: 'offset Left: ', info_id: 'offset_left'},
- {info_caption: 'offset Top: ', info_id: 'offset_top'},
- {info_caption: 'offset Width ', info_id: 'offset_width'},
- {info_caption: 'offset Height: ', info_id: 'offset_height'},
- {info_caption: 'offset parent: ', info_id: 'offset_parent'},
- {info_caption: 'rect Left: ', info_id: 'rect_left'},
- {info_caption: 'rect Top: ', info_id: 'rect_top'},
- {info_caption: 'rect Right ', info_id: 'rect_right'},
- {info_caption: 'rect Bottom: ', info_id: 'rect_bottom'}
- ]
- this.position_info_element = _self.helper.crInfoBlock('position info', info_els);
- //-----------------------------------------------test block
- this.test_element=_self.helper.crEl('test_block');
- this.test_element.style['top']='300px';
- this.test_element.style['left']='500px';
- this.test_element.suffix=suffix;
- _self.helper.addPar(this.test_element,'test');
- _self.DDrop.attach(this.test_element);
- //------------------------------------------test block with table
- this.table_test_element = _self.helper.crInfoBlock('Table tests', []);
- info_tab = {
- tbodies : {nrows:3, ncols:5},
- thead: {nrows:1, ncols: 4},
- tfoot: {nrows:1, ncols:3}
- }
- var tabel= _self.helper.draw_table (info_tab);
- this.table_test_element.appendChild(tabel);
- //-------------------------------------test block with form
- this.form_test_element = _self.helper.crInfoBlock('Form tests',[]);
- var testform = _self.helper.draw_form();
- el= this.form_test_element;
- el.appendChild(testform);
- el.style['height']=(window.innerHeight-el.offsetTop-5)+'px';
- }
- //-----------------------------------------------------
- // update status
- //-----------------------------------------------------
- this.update_status = function () {
- //----------------------------document width and height without scroll
- this.status.page_width =
- document.documentElement.clientWidth;
- this.status.page_height =
- document.documentElement.clientHeight;
- //---------------------------document width and height with scroll
- this.status.scroll_page_width =
- Math.max(document.documentElement.scrollWidth,
- document.documentElement.clientWidth);
- this.status.scroll_page_height =
- Math.max(document.documentElement.scrollHeight,
- document.documentElement.clientHeight);
- //-----------------------window inner and outer width and height
- this.status.window_outer_width = window.outerWidth;
- this.status.window_outer_height = window.outerHeight;
- this.status.window_inner_width = window.innerWidth;
- this.status.window_inner_height = window.innerHeight;
- //-----------------------window position
- this.status.window_x_position = window.screenLeft;
- this.status.window_y_position = window.screenTop;
- //----------------------screen width, height and depth
- this.status.screen_width = screen.width;
- this.status.screen_height = screen.height;
- this.status.screen_avail_width = screen.availWidth;
- this.status.screen_avail_height = screen.availHeight;
- this.status.screen_color_depth = screen.colorDepth; //pixelDepth
- //---------------------browser info
- this.status.navigator_appname = navigator.appName;
- this.status.navigator_appversion = navigator.appVersion;
- this.status.navigator_cookieenabled = navigator.cookieEnabled;
- this.status.navigator_platform = navigator.platform;
- this.status.navigator_useragent = navigator.userAgent;
- //--------------------current time
- var d = new Date();
- this.status.current_time = d.getDay()+'.'+d.getMonth()+'.'+d.getFullYear()+' '+
- d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
- }
- //-----------------------------------------------------
- // update quick status
- //-----------------------------------------------------
- this.update_quick_status = function () {
- //-----------------------------scroll left
- this.status.scroll_left =
- window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
- //---------------------IE<8
- this.status.scroll_left-= document.documentElement.clientLeft || document.body.clientLeft;
- //-----------------------------scroll top
- this.status.scroll_top =
- window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
- //---------------------IE<8
- this.status.scroll_top-= document.documentElement.clientTop || document.body.clientTop;
- //window.innerWidth
- //document.documentElement.offsetWidth || document.body.offsetWidth
- }
- //--------------------------------------------------------------
- // show status
- //--------------------------------------------------------------
- this.show_status = function () {
- _self.helper.put_info('page_width', this.status.page_width);
- _self.helper.put_info('page_height', this.status.page_height);
- _self.helper.put_info('scroll_page_width', this.status.scroll_page_width);
- _self.helper.put_info('scroll_page_height', this.status.scroll_page_height);
- _self.helper.put_info('window_outer_width', this.status.window_outer_width);
- _self.helper.put_info('window_outer_height', this.status.window_outer_height);
- _self.helper.put_info('window_inner_width', this.status.window_inner_width);
- _self.helper.put_info('window_inner_height', this.status.window_inner_height);
- _self.helper.put_info('window_x_position', this.status.window_x_position);
- _self.helper.put_info('window_y_position', this.status.window_y_position);
- _self.helper.put_info('screen_width', this.status.screen_width);
- _self.helper.put_info('screen_height', this.status.screen_height);
- _self.helper.put_info('screen_avail_width', this.status.screen_avail_width);
- _self.helper.put_info('screen_avail_height', this.status.screen_avail_height);
- _self.helper.put_info('screen_color_depth', this.status.screen_color_depth);
- _self.helper.put_info('navigator_appname', this.status.navigator_appname);
- _self.helper.put_info('navigator_appversion', this.status.navigator_appversion);
- _self.helper.put_info('navigator_cookieenabled', this.status.navigator_cookieenabled);
- _self.helper.put_info('navigator_platform', this.status.navigator_platform);
- _self.helper.put_info('navigator_useragent', this.status.navigator_useragent);
- }
- //--------------------------------------------------------------
- // show quick status
- //--------------------------------------------------------------
- this.show_quick_status= function () {
- _self.helper.put_info('mouse_coords', this.status.mouse_coords);
- _self.helper.put_info('mouse_button', this.status.mouse_button);
- _self.helper.put_info('wheel_delta', this.status.wheel_delta);
- _self.helper.put_info('key_code', this.status.key_code);
- _self.helper.put_info('char_code', this.status.char_code);
- _self.helper.put_info('alt_key', this.status.alt_key);
- _self.helper.put_info('ctrl_key', this.status.ctrl_key);
- _self.helper.put_info('scroll_left', this.status.scroll_left);
- _self.helper.put_info('scroll_top', this.status.scroll_top);
- _self.helper.put_info('current_time', this.status.current_time);
- }
- this.init();
- this.status_interval =
- setInterval( function() {_dself.update_status();_dself.show_status();}, 400);
- this.quick_status_interval =
- setInterval( function() {_dself.update_quick_status();_dself.show_quick_status();},100);
- }
- //-------------------------------------------------------
- // helper obj
- //-------------------------------------------------------
- this.f_helper= function() {
- this.num_infoblocks=0;
- this.num_all=0;
- this.event_attachment_type='listener';
- _hself = this;
- //--------------------------get event related info
- this.get_event_info = function (ev, in_catcher) {
- ev = ev || event
- var target = ev.target || ev.srcElement;
- var catcher = in_catcher;
- var evtype = ev.type;
- if (!ev.relatedTarget && ev.fromElement)
- var relatedTarget = (ev.fromElement==ev.target) ? ev.toElement : ev.fromElement;
- else
- var relatedTarget = ev.relatedTarget;
- return {
- s_event : ev,
- s_type : evtype,
- s_target : target,
- s_reltarget : relatedTarget,
- s_catcher : catcher
- }
- }
- //--------------------------------show event info
- this.show_event_info = function (ev, in_catcher, instr, suffix) {
- s_ev = _hself.get_event_info(ev, in_catcher);
- _hself.put_info('current_event'+(suffix || ''), s_ev.s_event+ ' '+instr);
- _hself.put_info('event_target'+(suffix || ''),s_ev.s_target);
- _hself.put_info('event_target_id'+(suffix || ''), s_ev.s_target.id);
- _hself.put_info('event_catcher'+(suffix || ''),s_ev.s_catcher);
- _hself.put_info('event_catcher_id'+(suffix || ''),s_ev.s_catcher.id);
- _hself.put_info('event_type'+(suffix || ''),s_ev.s_type);
- _hself.put_info('event_reltarget'+(suffix || ''),s_ev.s_reltarget);
- _hself.put_info('event_reltarget_id'+(suffix || ''),(s_ev.s_reltarget ? s_ev.s_reltarget.id : ''));
- }
- //-----------------------------get element coords
- this.get_coords_info = function (el) {
- var offset_left = el.offsetLeft;
- var offset_top = el.offsetTop;
- var offset_width = el.offsetWidth;
- var offset_height = el.offsetHeight;
- var offset_parent = el.offsetParent;
- var xScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
- var yScroll = document.documentElement.scrollTop || document.body.scrollTop;
- var xClient = document.documentElement.clientLeft || document.body.clientLeft;
- var yClient = document.documentElement.clientTop || document.body.clientTop;
- var z_rect= el.getBoundingClientRect();
- var rect_left = z_rect.left + xScroll - xClient;
- var rect_top = z_rect.top + yScroll - yClient;
- var rect_right = z_rect.right + xScroll - xClient;
- var rect_bottom = z_rect.bottom + yScroll - yClient;
- return {
- c_offset_left : offset_left,
- c_offset_top : offset_top,
- c_offset_width : offset_width,
- c_offset_height : offset_height,
- c_offset_parent : offset_parent,
- c_rect_left : rect_left,
- c_rect_top : rect_top,
- c_rect_right : rect_right,
- c_rect_bottom : rect_bottom
- }
- }
- //---------------------------------show element coords
- this.show_coords_info = function (el) {
- var coords = _hself.get_coords_info(el);
- _hself.put_info('offset_left', coords.c_offset_left);
- _hself.put_info('offset_top', coords.c_offset_top);
- _hself.put_info('offset_width', coords.c_offset_width);
- _hself.put_info('offset_height', coords.c_offset_height);
- _hself.put_info('offset_parent', coords.c_offset_parent);
- _hself.put_info('rect_left', coords.c_rect_left);
- _hself.put_info('rect_top', coords.c_rect_top);
- _hself.put_info('rect_right', coords.c_rect_right);
- _hself.put_info('rect_bottom', coords.c_rect_bottom);
- }
- //-------------------------------get mouse button
- this.get_mouse_button = function (ev) {
- ev = ev || event;
- if (!ev.which && ev.button) {
- if (ev.button & 1) ev.which=1
- else if (ev.button & 4) ev.which=2
- else if (ev.button & 2) ev.which=3;
- }
- return ev.which;
- }
- //-----------------------------------------------draw table
- this.draw_table = function (inf) {
- function draw_section(section, nrows, ncols) {
- for (var i=0; i<nrows; i++) {
- var row = section.insertRow(i);
- for (var j=0; j<ncols; j++) {
- var cell=row.insertCell(j);
- cell.innerHTML=i+'<sup>'+j+'</sup>';
- }
- }
- }
- var el =document.createElement('TABLE');
- if (inf.tbodies)
- draw_section(el.tBodies[0] && el.tBodies[el.tBodies.length-1] || el,
- inf.tbodies.nrows,
- inf.tbodies.ncols);
- if (inf.thead)
- draw_section(el.createTHead(), inf.thead.nrows, inf.thead.ncols);
- if (inf.tfoot)
- draw_section(el.createTFoot(), inf.tfoot.nrows, inf.tfoot.ncols);
- return el;
- }
- //-----------------------------------------------draw form
- this.draw_form = function () {
- function addInput(type,name,value,text,id) {
- var p_el = document.createElement('P');
- switch (type.toUpperCase()) {
- case 'TEXTAREA':
- var el = document.createElement('TEXTAREA');
- break;
- default:
- var el = document.createElement('INPUT');
- el.type=type;
- }
- el.name=name;
- el.id=id;
- el.value=value;
- p_el.appendChild(el);
- var tx=document.createTextNode(text);
- switch (type.toUpperCase()) {
- case 'CHECKBOX':
- case 'RADIO':
- p_el.appendChild(tx);
- break;
- default:
- p_el.insertBefore(tx,el);
- }
- this.appendChild(p_el);
- }
- //-------------------------------
- function addSelect(name, values, captions, id) {
- var p_el=document.createElement('P');
- var el = document.createElement('SELECT');
- el.name=name;
- el.id==id;
- //------------------
- for (var i=0; i<values.length; i++) {
- var o = new Option (captions[i], values[i], false, false);
- try {
- el.add(o, null)
- }
- catch(e) {
- el.add(o);
- }
- }
- //------------------
- p_el.appendChild(el);
- this.appendChild(p_el);
- }
- //-------------------------------
- var el = document.createElement('FORM');
- addInput.call(el, 'TEXT','z_name', '','Input your name', 'el_name');
- addInput.call(el, 'CHECKBOX', 'z_interests[]','', 'books', 'el_books');
- addInput.call(el, 'CHECKBOX', 'z_interests[]','', 'movies', 'el_movies');
- addInput.call(el, 'RADIO', 'gender','', 'male', 'el_male');
- addInput.call(el, 'RADIO', 'gender','', 'female', 'el_female');
- addSelect.call(el, 'country', ['n_us','n_uk','n_russia','n_china'],
- ['US','UK','Russia','China'], 'el_country');
- return el;
- }
- //---------------------------create element;
- this.crEl= function (className, inel) {
- var el=document.createElement('DIV');
- el.className=className;
- this.num_all++;
- el.id='element-'+this.num_all;
- if (inel)
- inel.appendChild(el);
- else
- document.body.appendChild(el);
- return el;
- }
- //--------------------------add Paragraph;
- this.addPar = function (inel, intext) {
- var el = document.createElement('P');
- var tx = document.createTextNode(intext);
- el.appendChild(tx);
- this.num_all++;
- el.id='paragraph-'+this.num_all;
- inel.appendChild(el);
- return el
- }
- //----------------------------create Info block
- this.crInfoBlock = function (caption_text, info_els, suffix) {
- this.num_infoblocks++;
- var el = this.crEl('info_service');
- el.id='info-'+this.num_infoblocks;
- var capEl= this.crEl('info_service_caption', el);
- capEl.id='infocaption-'+this.num_infoblocks;
- this.addPar(capEl, caption_text);
- for (var i=0; i<info_els.length; i++) {
- var subel=this.crEl('info_service_block',el);
- subel.info_caption=info_els[i].info_caption;
- subel.id=info_els[i].info_id + (suffix || '');
- this.put_info(subel.id);
- }
- this.arrange_info_blocks();
- return el;
- };
- //-----------------put info into specific info element
- this.put_info = function (element_id, intext) {
- var el=document.getElementById(element_id);
- if (!el) return;
- if (!intext)
- intext='';
- if (!el.hasChildNodes())
- var inpar = this.addPar(el);
- else
- var inpar = el.firstChild;
- inpar.innerHTML='<b>'+el.info_caption+'</b>'+intext;
- };
- //-----------------------------arrange info blocks
- this.arrange_info_blocks = function () {
- var els = document.body.childNodes;
- var cw=0;
- var ch=0;
- for (var i=0; i<els.length; i++) {
- if ((els[i].nodeName.toUpperCase()=='DIV') &&
- (els[i].className.indexOf('info_service')!=-1)) {
- if (cw+els[i].offsetWidth>=screen.availWidth) {
- cw=0;
- ch+=els[i].offsetHeight+3;
- }
- els[i].style.left = cw+'px';
- els[i].style.top = ch +'px';
- cw+=els[i].offsetWidth+3;
- }
- }
- }
- //------------------------------setup event handler
- this.add_event = function (el, ev, handler) {
- if (this.event_attachment_type!='listener') {
- var ev4 = eval('on'+ev);
- el.ev4 = handler;
- return;
- }
- try {
- el.addEventListener(ev, handler, false);
- } catch (e) {
- el.attachEvent('on'+ev, handler);
- }
- };
- //------------------------------remove event handler
- this.remove_event = function(el,ev, handler) {
- if (this.event_attachment_type!='listener') {
- var ev4 = eval('on'+ev);
- el.ev4 = null;
- return;
- }
- try {
- el.removeEventListener(ev,handler, false);
- } catch (e) {
- el.detachEvent('on'+ev,handler);
- }
- };
- //--------------------------prevent default behavior
- this.cancel_event = function (ev) {
- try {
- ev.preventDefault();
- } catch(e) {
- ev.returnValue=false;
- }
- };
- //------------------------stop event propagation
- this.stop_event = function(ev) {
- try {
- ev.stopPropagation();
- } catch(e) {
- ev.cancelBubble=true;
- }
- };
- //--------------------get element rectangle
- this.getRect = function(el, newCoords) {
- return { left: newCoords[0] || el.offsetLeft,
- top: newCoords[1] || el.offsetTop,
- right: (newCoords[0] || el.offsetLeft) + el.offsetWidth,
- bottom: (newCoords[1] || el.offsetTop) + el.offsetHeight}
- };
- //---------------------check if el coords fit screen
- this.checkRect = function(el, newCoords) {
- var rect=this.getRect(el, newCoords);
- if ((rect.top<0) || (rect.left<0) ||
- (rect.right > screen.availWidth-20) || (rect.bottom > screen.availHeight-50))
- return false
- else
- return true;
- }
- }
- //-----------------------------------------------------------------
- // drag and drop handler
- //-----------------------------------------------------------------
- this.DDrop = {
- //------------------------
- attach: function (el) {
- //_self.helper.event_attachment_type='base';
- _self.helper.add_event(el,'mousedown', this.mouse_down);
- _self.helper.add_event(el,'mousemove',this.mouse_move);
- _self.helper.add_event(el,'mouseup',this.mouse_up);
- _self.helper.add_event(el,'mouseover', this.mouse_over);
- _self.helper.add_event(el,'mouseout', this.mouse_out);
- },
- //------------------------
- detach: function (el) {
- //_self.helper.event_attachment_type='base';
- _self.helper.remove_event(el, 'mousedown', this.mouse_down);
- _self.helper.remove_event(el,'mousemove',this.mouse_move);
- _self.helper.remove_event(el,'mouseup',this.mouse_up);
- _self.helper.remove_event(el,'mouseover',this.mouse_over);
- _self.helper.remove_event(el,'mouseout', this.mouse_out);
- },
- //------------------------
- //--------------------------mouse down event
- mouse_down: function(e) {
- e = e || event;
- //var target = e.target || e.srcElement;
- var target=this;
- _self.helper.show_event_info(e, this, 'mouse_down', this.suffix);
- target.Xdiff = e.clientX - target.offsetLeft;
- target.Ydiff = e.clientY - target.offsetTop;
- target.pressed=true;
- target.style['z-index']=1000;
- _self.helper.cancel_event(e);
- },
- //-------------------------mouse move event
- mouse_move:function(e) {
- e = e || event;
- //var target = e.target || e.srcElement;
- var target = this;
- //_self.helper.show_event_info(e, this, 'mouse_move', this.suffix);
- //----------------show position of target
- _self.helper.show_coords_info (target);
- var x = e.clientX - target.Xdiff;
- var y = e.clientY - target.Ydiff;
- if ((target.pressed) && (_self.helper.checkRect(target,[x,y]))) {
- target.style.left= x +'px';
- target.style.top= y +'px';
- }
- target.style.cursor='pointer';
- },
- //-------------------------mouse up event
- mouse_up:function(e) {
- e = e || event;
- //var target = e.target || e.srcElement;
- var target=this;
- _self.helper.show_event_info(e, this, 'mouse_up', this.suffix);
- if (target.pressed)
- target.pressed=false;
- },
- //-------------------------mouse over
- mouse_over: function(e) {
- e = e || event;
- //var target = e.target || e.srcElement;
- var target=this;
- _self.helper.show_event_info(e, this, 'mouse_over', this.suffix);
- target.style.cursor='pointer';
- },
- //-----------------------------mouse out event
- mouse_out: function(e) {
- e = e || event;
- //var target = e.target || e.srcElement;
- var target = this;
- _self.helper.show_event_info(e, this, 'mouse_out', this.suffix);
- target.style.cursor='default';
- if (target.pressed)
- target.pressed=false;
- }
- }
- //--------------------------------
- //--------------------------------
- this.init();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement