X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=public%2Fassets%2Fcommon.js;h=c0f241cf515f140289ce6e28607138bf8612cbb7;hb=b323f6811250f4ea930a3338fa88fc4ccca9e11e;hp=5424edb64468fba70f006438801b5c46d1262890;hpb=448d61289f86d1e772b9cb324144dc4ce17bec48;p=pettanr%2Fpettanr.git diff --git a/public/assets/common.js b/public/assets/common.js index 5424edb6..c0f241cf 100644 --- a/public/assets/common.js +++ b/public/assets/common.js @@ -1,6 +1,6 @@ /* * pettanR common.js - * version 0.4.1 + * version 0.4.2 * * author: itozyun */ @@ -37,10 +37,10 @@ var pettanr = ( function(){ } return {}; })(), - IS_DEBUG = IS_LOCAL === true || URL_PARAMS.debug === true, + IS_DEBUG = typeof URL_PARAMS.debug === 'boolean' ? URL_PARAMS.debug : IS_LOCAL === true, jqWindow , jqDocument , jqBody; return { - version: '0.4.1', + version: '0.4.2', init: function(){ jqWindow = $( window); jqDocument = $( document); @@ -69,8 +69,32 @@ var pettanr = ( function(){ return jqBody; }, URL_PARAMS: URL_PARAMS, + ROOT_PATH: ( function(){ + // script と html の ドメインが一致 + var _h1 = document.getElementsByTagName( 'h1')[ 0], + _a = _h1.getElementsByTagName( 'a')[ 0], + _root = _a.href.split( '\/'), + _current = document.location.href.split( '\/'), + ret = '.\/'; + for( var i=0, l=_current.length - _root.length; i 0){ - for( j=0; i document.createElement( 'IMG') + * new Image -> document.createElement( 'img') */ function loadImage( images, abspath, onLoad, onError, delay, timeout) { images = images || document.images; @@ -402,6 +435,89 @@ pettanr.util = ( function(){ IDorELM.id = ''; } return IDorELM; + }, + getElementsByClassName: function( _elm, _className, opt_tagName){ + var _all = !opt_tagName || opt_tagName === '*', + _nodes = _all === true ? ( _elm.all || _elm.getElementsByTagName( '*')) : _elm.getElementsByTagName( opt_tagName), + _node, _classes, ret = []; + for( var i=0, l = _nodes.length; i 8) return false; - var className = document.body.className, - test; - if( className && className.indexOf( 'pettanr-ActiveX-enabled') !== -1) return true; - if( className && className.indexOf( 'pettanr-ActiveX-disabled') !== -1) return false; - try { - test = new ActiveXObject('DXImageTransform.Microsoft.gradient'); - } catch( e){ - return false; + var b = document.body, + c = b.className || '', + x, + ret = pettanr.URL_PARAMS.ActiveX; + if( ret === undefined){ + if( pettanr.util.hasClassName( b, 'pettanr-ActiveX-enabled') === true) return true; + if( pettanr.util.hasClassName( b, 'pettanr-ActiveX-disabled') === true) return false; + x = document.createElement('div'); + b.appendChild(x); + x.style.cssText = 'width:1px;height:1px;filter:progid:DXImageTransform.Microsoft.Shadow()'; + ret = x.offsetHeight > 1; + b.removeChild(x); } - return !!test; + b.className += [ c !== '' ? ' ' : c, 'pettanr-ActiveX-', ret === true ? 'enabled' : 'disabled'].join( ''); + return ret; })(), VML: VML, STANDALONE: isStandAloneMode, @@ -522,10 +643,14 @@ pettanr.ua = ( function(){ pettanr.CONST = ( function(){ - var isLocal = pettanr.LOCAL === true || pettanr.URL_PARAMS.exjson === false; + var isLocal = pettanr.LOCAL === true || pettanr.URL_PARAMS.exjson === false, + RETTANR_ROOOT_PATH = 'http:\/\/pettanr.heroku.com\/'; return { - URL_ORIGINAL_PICTURES_JSON: ( isLocal === true ? 'json\/' : 'http:\/\/pettanr.heroku.com\/') + 'original_pictures.json', - URL_PANELS_JSON: ( isLocal === true ? 'json\/' : 'http:\/\/pettanr.heroku.com\/') + 'panels.json' + PETTANR_ROOT_PATH: RETTANR_ROOOT_PATH, + URL_ORIGINAL_PICTURES_JSON: ( isLocal === true ? 'json\/' : RETTANR_ROOOT_PATH) + 'original_pictures.json', + URL_PANELS_JSON: ( isLocal === true ? 'json\/' : RETTANR_ROOOT_PATH) + 'panels.json', + NS_PETTANR_COMIC: 'pettanr-comic', + RESOURCE_PICTURE_PATH: ( isLocal === true ? pettanr.ROOT_PATH : RETTANR_ROOOT_PATH) + 'resource_pictures\/' } })(); @@ -535,7 +660,7 @@ pettanr.view = ( function(){ var location = document.location.pathname, isWorkPage = location.indexOf( '\/work.html') !== -1 || location.indexOf( '\work.html') !== -1, deep = location.indexOf( '\/diary\/') !== -1 || - location.indexOf( '\/text\/') !== -1 || + location.indexOf( '\/test\/') !== -1 || location.indexOf( '\/help\/') !== -1 || location.indexOf( '\/sitemap\/') !== -1 || location.indexOf( '\/wiki\/') !== -1, @@ -570,7 +695,7 @@ pettanr.view = ( function(){ el.style.position = 'absolute'; el.style.left = el.style.top = '0px'; el.style.width = el.style.height ='100%'; - el.style.overflow = 'hidden'; + //el.style.overflow = 'hidden'; el.hspace = el.vspace = el.marginheight = el.marginwidth = 0; _body.appendChild(el); @@ -655,55 +780,71 @@ pettanr.view = ( function(){ LoginUserNavi = ( function(){ return { show: function(){ - var index = ( function( a){ - var node = a.parentNode.getElementsByTagName( 'a'), - l = node.length; - for( var i=0; i= 8) data.RenderingVersion = ua.ieRenderingVersion; - data.browserType = ua.STANDALONE === true ? 'Standalone' : 'bundle'; - if( ua.ieVersion < 9) { - data.vml = ua.VML; - } else { - data.svg = ua.SVG; + + if( pettanr.IS_IFRAME === true){ + var _nodes = document.getElementsByTagName( 'a'), + _a, _href; + for(var i=0, l = _nodes.length; i= 8) data.RenderingVersion = ua.ieRenderingVersion; + data.browserType = ua.STANDALONE === true ? 'Standalone' : 'bundle'; + if( ua.ieVersion < 9) { + data.vml = ua.VML; + } else { + data.svg = ua.SVG; + } + } + data.RenderingMode = ua.isStanderdMode === true ? 'Standerd' : 'Quirks'; + + for( var key in data){ + elmDt = document.createElement( 'dt'); + elmDt.innerHTML = key; + elmDd = document.createElement( 'dd'); + elmDd.innerHTML = '' + data[ key]; + if( !data[ key]) elmDd.style.color = 'red'; + elmDl.appendChild( elmDt); + elmDl.appendChild( elmDd); + } + } else { + var _debug = document.getElementById( 'debug'); + if( _debug){ + pettanr.util.removeAllChildren( _debug); + _debug.parentNode.removeChild( _debug); + } } } @@ -712,10 +853,7 @@ pettanr.view = ( function(){ origin = document.createElement('a'), items = ( function(){ var ret = ['Home', 'Comic list', 'Picture', 'Setting']; - if( pettanr.DEBUG === true) { - ret.push( 'debug'); - navi.style.width = '400px'; - } + pettanr.DEBUG === true && ret.push( 'debug'); return ret; })(), l = items.length, @@ -727,6 +865,7 @@ pettanr.view = ( function(){ item.onclick = LoginUserNavi.show; navi.appendChild( item); } + navi.style.width = ( ( item.offsetWidth || 80) * l) +'px'; location = origin = item = null; /* debug info */ @@ -1065,7 +1204,7 @@ pettanr.overlay = ( function(){ } })(); /* - * + * */ function close(){ @@ -1129,15 +1268,6 @@ pettanr.overlay = ( function(){ * KEY * * - EDITABLE_TEXT_CONTROL - * - EditableTextClass - * .update: function, - * .show: function, - * .hide: function, - * .start: function, - * .finish: finish, - * .enabled: function, - * .index: function, - * .instance: function * * .SHIFT_DOWN_EVENT: 'shiftDown', * .SHIFT_UP_EVENT: 'shiftUp', @@ -1146,9 +1276,8 @@ pettanr.overlay = ( function(){ * .SPACE_DOWN_EVENT: 'spaceDown', * .SPACE_UP_EVENT: 'spaceUp', * .init: function, - * .addKeyDownEvent: function, + * .addKeyDownEvent: function, * .keyEventDispatcher: function, - * .createEditableText: function, * * ショートカットキーの監視とテキスト入力(input, textarea)、チェックボックスを管理する。 * キー入力はdocumentで受けて、テキスト編集中(input, textarea)はそちらにキーイベント流す。 @@ -1162,171 +1291,6 @@ pettanr.key = ( function(){ shiftEnabled = false, ctrlEnabled = false; - var EDITABLE_TEXT_CONTROL = ( function(){ - var EDITABLE_TEXT_TABLE = {}, - currentText = null; - - var EditableTextClass = function( WRAPPER_ELM, ON_UPDATE_FUNCTION, GROUP_ID){ - var ELM = WRAPPER_ELM.children( '.editable-value').eq( 0), - value = ELM.html(), - jqInput, - index = EDITABLE_TEXT_TABLE[ GROUP_ID].length, - instance, - enabled = true, - A = $( '').html( value).click( function(e){ - instance = instance || EDITABLE_TEXT_TABLE[ GROUP_ID][ index]; - EDITABLE_TEXT_CONTROL.start( instance); - A.hide(); - jqInput = $( '').val( value); - ELM.append( jqInput); - jqInput.focus().select(); - e.preventDefault(); - return false; - }); - ELM.addClass( 'editable-text').html( A); - - return { - update: function( _value){ - value = _value !== undefined ? _value : value; - A.html( value); - jqInput && jqInput.val( value); - currentText === instance && this.finish(); - }, - show: function(){ - enabled === false && WRAPPER_ELM.show(); - enabled= true; - }, - hide: function(){ - enabled === true && WRAPPER_ELM.hide(); - enabled = false; - }, - start: function(){ - !jqInput && A.click(); - }, - finish: function( keep){ - var _newValue = keep === true ? value : jqInput.val(); - A.html( _newValue).show(); - jqInput.remove(); - jqInput = null; - ON_UPDATE_FUNCTION && _newValue !== value && ON_UPDATE_FUNCTION( _newValue, value); - EDITABLE_TEXT_CONTROL.finish( instance); - }, - enabled: function(){ - return enabled; - }, - index : index, - groupID: GROUP_ID - } - } - var CheckboxClass = function( WRAPPER_ELM, ON_UPDATE_FUNCTION, GROUP_ID){ - var ELM = WRAPPER_ELM.children( '.checkbox-value').eq( 0), - value = ELM.html(), - jqInput, - index = EDITABLE_TEXT_TABLE[ GROUP_ID].length, - instance, - enabled = true, - A = $( '').html( value).click( function(e){ - instance = instance || EDITABLE_TEXT_TABLE[ GROUP_ID][ index]; - EDITABLE_TEXT_CONTROL.start( instance); - A.hide(); - jqInput = $( '').val( value); - ELM.append( jqInput); - jqInput.focus().select(); - e.preventDefault(); - return false; - }); - ELM.addClass( 'editable-text').html( A); - - function finish(keep){ - if(keep === true){ - - } else { - _finish( jqInput.val()); - } - function _finish( VALUE_NEW){ - value = VALUE_NEW; - A.html( VALUE_NEW).show(); - jqInput.remove(); - jqInput = null; - ON_UPDATE_FUNCTION && VALUE_NEW !== value && ON_UPDATE_FUNCTION( VALUE_NEW, value); - EDITABLE_TEXT_CONTROL.finish( instance); - } - } - return { - update: function( _value){ - value = _value !== undefined ? _value : value; - A.html( value); - jqInput && jqInput.val( value); - currentText === instance && finish(); - }, - show: function(){ - enabled === false && WRAPPER_ELM.show(); - enabled= true; - }, - hide: function(){ - enabled === true && WRAPPER_ELM.hide(); - enabled = false; - }, - start: function(){ - !jqInput && A.click(); - }, - finish: finish, - enabled: function(){ - return enabled; - }, - groupID: GROUP_ID - } - } - return { - createEditableText: function( ELM, ON_UPDATE_FUNCTION, GROUP_ID){ - if( GROUP_ID && !EDITABLE_TEXT_TABLE[ GROUP_ID]) EDITABLE_TEXT_TABLE[ GROUP_ID] = []; - var ret = EditableTextClass.apply( {}, [ ELM, ON_UPDATE_FUNCTION, GROUP_ID]); - GROUP_ID && EDITABLE_TEXT_TABLE[ GROUP_ID].push( ret); - return ret; - }, - createCheckbox: function( ELM, ON_UPDATE_FUNCTION, GROUP_ID){ - - }, - start: function( _currentText){ - currentText !== _currentText && currentText && currentText.finish(); - currentText = _currentText; - }, - finish: function( _currentText){ - if( currentText !== _currentText) return; - currentText = null - }, - keyEventRellay: function( e){ - if( e.type === 'keyup') return false; - if( currentText === null) return false; - - var keyCode = e.keyCode; - if( keyCode === 13 || keyCode === 27 || keyCode === 9 || keyCode === 18 || e.altKey === true){ // 13.return 27.esc 9.tab 18.alt - var _groupID = currentText.groupID, - _index = currentText.index; - currentText.finish( keyCode === 27); - keyCode === 9 && _groupID && EDITABLE_TEXT_CONTROL.tabShift( _groupID, _index, e.shiftKey === true ? -1 : 1); - keyCode === 13 && _groupID && EDITABLE_TEXT_CONTROL.tabShift( _groupID, _index, 1); - } - return true; - }, - tabShift: function( _groupID, _index, _way){ - var GROUP_ARRAY = EDITABLE_TEXT_TABLE[ _groupID] || [], - l = GROUP_ARRAY.length, - i = _index +_way; - if( l < 2) return; - while( i !== _index){ - i = i < 0 ? - l -1 : - i === l ? 0 : i; // 0 < i < l - if( GROUP_ARRAY[ i].enabled() === true) break; - i += _way; - } - if( i === _index) return; - setTimeout( function(){ GROUP_ARRAY[ i].start();}, 0); - } - } - })(); - function keyHit( e){ log.html( [ e.keyCode, e.shiftKey, e.ctrlKey, e.altKey, e.type].join( ',')); //keyOperationChatcher.val( ''); @@ -1336,7 +1300,7 @@ pettanr.key = ( function(){ overlayEnabled = pettanr.overlay.visible === true, currentViewID = overlayEnabled === true ? pettanr.overlay.currentID : pettanr.view.currentID; if( callback === 'keypress') callback = 'keydown'; - if( EDITABLE_TEXT_CONTROL.keyEventRellay( e) === false){ + if( pettanr.form.keyEventRellay( e) === false){ var shift = e.shiftKey, ctrl = e.ctrlKey, l = KEYEVENT_ARRAY.length, @@ -1425,8 +1389,6 @@ pettanr.key = ( function(){ keyEventDispatcher: function(){ return keyOperationChatcher; }, - createEditableText: EDITABLE_TEXT_CONTROL.createEditableText, - createCheckbox: EDITABLE_TEXT_CONTROL.createCheckbox, shiftEnabled: function(){ return shiftEnabled; }, @@ -1441,52 +1403,55 @@ pettanr.key = ( function(){ * * keyEventRellay * form -> overlay -> view - * + * */ pettanr.form = ( function(){ var FORM_GROUP_TABLE = {}, currentID = null, currentItem = null, - ELM_INPUT_TEXT = document.createElement( 'input'); - ELM_INPUT_TEXT.type = 'text'; + ELM_A_ORIGIN = ( function(){ + var ret = document.createElement( 'a'); + ret.href = '#'; + return ret; + })(), + ELM_INPUT_TEXT = ( function(){ + var ret = document.createElement( 'input'); + ret.type = 'text'; + return ret; + })(); var InputTextClass = function( WRAPPER_ELM, ON_UPDATE_FUNCTION, GROUP_ID, validater){ validater = typeof validater === 'function' ? validater : null; - var elmValue, + var elmValue = pettanr.util.getElementsByClassName( WRAPPER_ELM, 'editable-value')[ 0], value, - index = EDITABLE_TEXT_TABLE[ GROUP_ID].length, + index = GROUP_ID ? FORM_GROUP_TABLE[ GROUP_ID].length : -1, instance, focus = false, visible = true, enabled = true, - elmA; - var _nodes = WRAPPER_ELM.getElementsByTagName('*'), - l = nodes.length, - _elm; - for(var i=0; i 6) return BACKEND; if( pettanr.ua.VML === true) return IS_VML; if( pettanr.FLASH === true) return IS_FLASH; if( pettanr.SILVERLIGHT === true) return IS_SILVERLIGHT; if( pettanr.ua.ACTIVEX === true) return IS_ACTIVEX_SERVER; return IS_SERVER; - })(); + })(), + ReversibleImageClass, + ReversibleImageClassWithPingfix; var XBackendReversibleImageClass = ( function(){ var CLASS_NAME = 'reversible-image-container', @@ -1899,7 +1888,7 @@ pettanr.image = ( function(){ w = _w !== undefined ? _w : w; h = _h !== undefined ? _h : h; if( loaded === false) return; - elmImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'v' : 'h'))) : ''; + elmImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'h' : 'v'))) : ''; } return { elm : elmWrap, @@ -1948,7 +1937,7 @@ pettanr.image = ( function(){ //if( flipH !== _flipH || flipV !== _flipV){ vmlImg.parentNode === elmWrap && elmWrap.removeChild( vmlImg); //} - vmlImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'v' : 'h'))) : ''; + vmlImg.className = w < 0 || h < 0 ? ( 'img-flip-' + ( w < 0 && h < 0 ? 'vh' : ( w < 0 ? 'h' : 'v'))) : ''; elmWrap.appendChild( vmlImg); } return { @@ -2002,19 +1991,388 @@ pettanr.image = ( function(){ } })(); +/* + * bind : 出版 + */ +pettanr.bind = ( function(){ + var BIND_WORKER_ARRAY = [], + NAMESPACE_CLASSNAME = pettanr.CONST.NS_PETTANR_COMIC + '-', + RESOURCE_PICTURE_PATH = pettanr.CONST.RESOURCE_PICTURE_PATH, + ELM_DETECT_WIDTH = ( function(){ + var ret = document.createElement( 'div'); + ret.style.cssText = 'width: auto;height: 0;padding: 0;margin: 0;display: block;visibility: hidden;float: none;position: static;'; + return ret; + })(); + + /* + * original + * http://d.hatena.ne.jp/uupaa/20090720/1248097177 + */ + var ResizeAgentClass = function( onResizeFunction, opt_elmCheck){ + var _globalLock = 0, + _size = { w: 0, h: 0 }; + _ie = !!document.all, + _quirks = (document.compatMode || "") !== "CSS1Compat", + _ieroot = _quirks ? "body" : "documentElement"; + _root = opt_elmCheck ? opt_elmCheck : ( _ie ? document[_ieroot] : window); + + function getInnerSize() { + return { + w: _root.innerWidth || _root.clientWidth, + h: _root.innerHeight || _root.clientHeight + }; + } + + function loop() { + if (!_globalLock++) { + var size = getInnerSize(); + if (_size.w !== size.w || _size.h !== size.h) { // resized + _size = size; // update + onResizeFunction( _size); + } + setTimeout( unlock, 0); // delay unlock + } + setTimeout(loop, 500); + } + function unlock(){ + _globalLock = 0; + } + loop(); + } + + + var ElementBuilder = ( function(){ + var ELM_TITLE_ORIGN = ( function(){ + + })(), + ELM_TEXT_ORIGN = ( function(){ + var _table = document.createElement( 'table'), + _tr = document.createElement( 'tr'); + _table.appendChild( _tr); + _tr.appendChild( document.createElement( 'td')); + _table.cellspacing = '0'; + return _table; + })(); + + function buildComicElement(){ + + } + + function buildPanelElement( elmTarget, json, noClassnameMode){ + var _elmPanel = document.createElement( 'div'), + _style = { + "border-width": typeof json.border === 'number' ? json.border + 'px' : 0, + width: json.width + 'px', + height: json.height + 'px' + }, + _cssText = [], + _comicElements = json.panel_elements || [], + _comicElement, _elmImgWrap, _rImg, _rPic, _balloon, _elmBalloonWrap, _elmText; + if( noClassnameMode === true){ + + } else { + _elmPanel.className = NAMESPACE_CLASSNAME + 'panel'; + } + for( var _key in _style){ + _cssText.push( _key + ':' + _style[ _key]); + } + _elmPanel.style.cssText = _cssText.join( ';'); + elmTarget.appendChild( _elmPanel); + + for( var i=0, l=_comicElements.length; i 1){ + var _cssTexts = _elm.style.cssText.split( ';'), _css, + _separate, + _cssObject = {}, _target, _value, _number, _type, _new, + j; + for(var i=0, l=_cssTexts.length; i= 3){ + _target = _css.substr( 0, _separate +1); + _value = _css.substr( _separate +1); + /* + * ie filter + */ + if( _target === FILTER){ + for( j=0; j<_numAttributes; ++j){ + if( _targetAttributes[ j] === OPACITY){ + + + + break; + } + } + /* + * other + */ + } else { + _number = '' + parseFloat( _value); + _type = _value.indexOf( _number); + _type = _type > 0 ? _value.substr( _type + _number.length) : ''; + for( j=0; j<_numAttributes; ++j){ + if( _targetAttributes[ j] === _target){ + _cssTexts[ i] = [ _target, ':', _updateParameters[ j], _type].join( ''); + break; + } + } + } + } + } + _elm.style.cssText = _cssTexts.join( ';'); + return; + } + /* + * 一度に update する Attributes が少ない場合、cssText は使用しない. + */ + + } + + var AnimationTaskClass = function( ELM, currentParameters, offsetParameters, endParameters, targetAttributes, onComplete, onEnterFrame, numFrames){ + var l = targetAttributes.length; + return { + elm: ELM, + onEnterFrame: function(){ + var _updateCss = {}; + if( numFrames === 1){ + for( var i=0; i