X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.4.x%2Fjavascripts%2Fcommon.js;h=13120a328453cc2f19c2dab531db11e69b46dcef;hb=080ecdb578eb49a116464aefc6b86bd5b6f6da38;hp=2033f3756563e9c288357fd60047e38b6106b8ee;hpb=42094f53d85db163552da7e26c3306bb955208f9;p=pettanr%2FclientJs.git diff --git a/0.4.x/javascripts/common.js b/0.4.x/javascripts/common.js index 2033f37..13120a3 100644 --- a/0.4.x/javascripts/common.js +++ b/0.4.x/javascripts/common.js @@ -1,10 +1,71 @@ /* * pettanR common.js - * version 0.4.4 + * version 0.4.12 * * author: itozyun */ +/* + * http://pettanr.sourceforge.jp/test/type.html + */ + var Type = { + isObject : function(v) { + return typeof v === 'object'; + }, + isFunction : function(v) { + return typeof v === 'function'; + }, + isArray : function(v) { + return Object.prototype.toString.call(v) === "[object Array]"; + }, + isBoolean : function(v) { + return typeof v === 'boolean'; + }, + isString : function(v) { + return typeof v === 'string'; + }, + isNumber : function(v) { + return typeof v === 'number'; + }, + isHTMLElement : ( 'HTMLElement' in window ? + function(v){ + return v instanceof HTMLElement + } : + function(v) { + if( Type.isObject(v) === false ){ + return false; + } + var r; + if(v && v.nodeType === 1){ + try{ + r = v.cloneNode(false); + } catch(n) { + return false; + } + if(r === v) return false; + try{ + r.nodeType = 9; + return r.nodeType === 1; + } catch(n) {} + return true; + } + return false; + } + ), + /* + isElementCollection : function(v) { + return (Object.prototype.toString.call(v) === "[object HTMLCollection]"); + }, + */ + isNull : function(v) { + return v === null; + }, + isUndefined : function(v) { + return typeof v === 'undefined'; + } + }; + + var pettanr = ( function(){ var FUNCTION_ARRAY = [], URL = document.location.href.split( '#')[ 0], @@ -40,7 +101,7 @@ var pettanr = ( function(){ IS_DEBUG = typeof URL_PARAMS.debug === 'boolean' ? URL_PARAMS.debug : IS_LOCAL === true, jqWindow , jqDocument , jqBody; return { - version: '0.4.4', + version: '0.4.11', init: function(){ jqWindow = $( window); jqDocument = $( document); @@ -143,16 +204,24 @@ pettanr.util = ( function(){ nodeNoscript = noscript = null; function cleanCommnetNode( _targetElm){ - _targetElm = _targetElm || document; - var _nodes = _targetElm.all || _targetElm.getElementsByTagName( '*'), - _array = [], - _elm; - for(var i=0, l = _nodes.length; i array + for( i=0, l=_children.length; i' : 'iframe'); + + if( ua.isIE){ + el.onreadystatechange = detect; + } else { + // iron(chrome) の場合、append の前に onload を指定しないと onload が呼ばれない + el.onload = onLoad; + //setTimeout( asynkCallback, 0 ); + } + + document.body.appendChild( el); + el.id = el.name = id; + el.setAttribute( 'name', id); + el.style.cssText = 'width:1px;height:1px;visibility:hidden;position:absolute;top:1px;left:1px;'; + // http://d.hatena.ne.jp/onozaty/20070830/p1 + // [JavaScript]IE6ではJavaScriptで動的に作成したiframeに対してsubmitできない(IE7は未確認) ->解決 + el.contentWindow.name = id; + + window[id] = el; + + function detect(){ + if ( this.readyState === "complete") { + this.onreadystatechange = new Function(); + this.onreadystatechange = null; + setTimeout( asynkCallback, 0 ); + } + } + function onLoad(){ + el.onload = null; + setTimeout( asynkCallback, 0 ); + } + function asynkCallback(){ + callback( el ); + } } } })(); @@ -586,7 +680,7 @@ pettanr.ua = ( function(){ if( pettanr.util.hasClassName( b, ns + disabled) === true) return false; x = document.createElement('div'); b.appendChild(x); - x.style.cssText = 'width:1px;height:1px;filter:progid:DXImageTransform.Microsoft.Shadow()'; + x.style.cssText = 'width:1px;height:1px;line-height:1px;filter:progid:DXImageTransform.Microsoft.Shadow()'; ret = x.offsetHeight > 1; b.removeChild(x); } @@ -664,18 +758,24 @@ pettanr.ua = ( function(){ pettanr.CONST = ( function(){ var isLocal = pettanr.LOCAL === true || pettanr.URL_PARAMS.exjson === false, isLocalhost = document.location.href.indexOf( 'http:\/\/localhost:3000\/' ) === 0, - RETTANR_ROOT_PATH = isLocalhost === true ? 'http:\/\/localhost:3000\/' : 'http:\/\/pettanr.heroku.com\/'; + PETTANR_ROOT_PATH = isLocalhost === true ? 'http:\/\/localhost:3000\/' : 'http:\/\/pettanr.heroku.com\/'; return { - PETTANR_ROOT_PATH: RETTANR_ROOT_PATH, - URL_ORIGINAL_PICTURES_JSON: ( isLocal === true ? 'json\/' : RETTANR_ROOT_PATH) + 'original_pictures.json', - URL_PANELS_JSON: ( isLocal === true ? 'json\/' : RETTANR_ROOT_PATH) + 'panels.json', + PETTANR_ROOT_PATH: PETTANR_ROOT_PATH, + URL_ORIGINAL_PICTURES_JSON: ( isLocal === true ? 'json\/' : PETTANR_ROOT_PATH) + 'original_pictures.json', + URL_RESOURCE_PICTURES_JSON: ( isLocal === true ? 'json\/' : PETTANR_ROOT_PATH) + 'resource_pictures.json', + URL_COMICS_JSON: ( isLocal === true ? 'json\/' : PETTANR_ROOT_PATH) + 'comics.json', + URL_PANELS_JSON: ( isLocal === true ? 'json\/' : PETTANR_ROOT_PATH) + 'panels.json', NS_PETTANR_COMIC: 'pettanr-comic', - RESOURCE_PICTURE_PATH: ( isLocal === true ? pettanr.ROOT_PATH : RETTANR_ROOT_PATH) + 'resource_pictures\/' + RESOURCE_PICTURE_PATH: ( isLocal === true ? pettanr.ROOT_PATH : PETTANR_ROOT_PATH) + 'resource_pictures\/', + CREATE_COMIC_JS: isLocal === true ? 'js\/create_new_comic.js' : PETTANR_ROOT_PATH + 'comics\/new.js', + CREATE_PANEL_JS: isLocal === true ? 'js\/create_new_panel.js' : PETTANR_ROOT_PATH + 'panels\/new.js', + UPLOAD_PICTURE_JS: isLocal === true ? 'js\/upload_picture.js' : PETTANR_ROOT_PATH + 'original_pictures\/new.js', + RESISTER_ARTIST_JS: isLocal === true ? 'js\/register_artist.js' : PETTANR_ROOT_PATH + 'artists\/new.js', + JQUERY_URL: isLocal === true ? 'javascripts\/jquery-1.6.2.min.js' : PETTANR_ROOT_PATH + 'assets\/jquery-162_min.js' } })(); - pettanr.view = ( function(){ /* create iframe overlay for user console */ var location = document.location.pathname, @@ -787,7 +887,7 @@ pettanr.view = ( function(){ origin.href = '#'; for(var i=0; i LIMIT_FILESIZE ? [ THUMB_PATH, data.id, '.', data.ext].join( '') : null, - reversibleImage = null, - actualW, actualH, - onEnterFlag = false; - JQ_ICON_WRAP.children( 'div').eq( 0).html( data.filesize + 'bytes'); - jqContainer.append( JQ_ICON_WRAP.css( { left: INDEX * itemW})); - - function onLoad( url, _imgW, _imgH){ - if( reversibleImage === null) { - alert( url); - return; - } - actualW = _imgW || 64; - actualH = _imgH || 64; - JQ_ICON_WRAP.children( 'div').eq( 1).html( actualW +'x' +actualH); - var zoom = 128 /( actualW > actualH ? actualW : actualH), - _h = Math.floor( actualH *zoom), - _w = Math.floor( actualW *zoom); - reversibleImage.elm.style.width = _w +'px'; - reversibleImage.elm.style.height = _h +'px'; - reversibleImage.elm.style.margin = Math.floor( itemH /2 -_h /2)+'px 0 0'; - reversibleImage.resize( _w, _h); - JQ_ICON_WRAP.click( onClick); - } - - function onClick( e){ - pettanr.overlay.hide(); - if (onUpdateFunction) { - if( LOW_SRC === null){ - onUpdateFunction( SRC, actualW, actualH); - } else { - onCloseUpdate( onUpdateFunction); // close()で値が消えるので、クロージャに保持 - } - } - close(); - } - - function onCloseUpdate( onUpdate){ - pettanr.util.loadImage( SRC, - function( _abspath, imgW, imgH){ - onUpdate( SRC, imgW, imgH); - onUpdate = null; - }, - function( _abspath){ - onUpdate( SRC, data.width || 64, data.height || 64); - onUpdate = null; - } - ); - } - - return { - onEnter: function(){ - if( onEnterFlag === true) return; - reversibleImage = pettanr.image.createReversibleImage( LOW_SRC || SRC, itemW, itemH, onLoad); - JQ_ICON_WRAP.children( 'img').replaceWith( reversibleImage.elm); - onEnterFlag = true; - }, - destroy: function(){ - reversibleImage && reversibleImage.destroy(); - JQ_ICON_WRAP.remove(); - reversibleImage = JQ_ICON_WRAP = null; - delete this.destroy; - } - } - } - - function close(){ - jqContainer.stop().animate( { - height: 0, - top: Math.floor( windowH /2) - }, function(){ - jqWrap.hide() - }); - while( ICON_ARRAY.length > 0){ - ICON_ARRAY.shift().destroy(); - } - onEnterInterval !== null && window.clearTimeout( onEnterInterval); - onUpdateFunction = onEnterInterval = null; - } - function onEnterShowImage(){ - var l = ICON_ARRAY.length, - _start = -wrapX /itemW -1, - _end = _start + winW /itemW +1; - for( var i=0; i 0 ? 0 : wrapX < winW -containerW ? winW -containerW : wrapX; - jqContainer.css( { left: wrapX}); - - onEnterInterval !== null && window.clearTimeout( onEnterInterval); - onEnterInterval = window.setTimeout( onEnterShowImage, 500); - } - //e.stopPropagation(); - return false; - } - return { - init: function(){ - this.jqWrap = jqWrap = $( '#image-gruop-wrapper').hide(); - jqContainer = $( '#image-icon-container').mousewheel( onMouseWheel); - containerH = pettanr.util.getElementSize( jqContainer.get( 0)).height; - jqItemOrigin = $( $( '#imageGruopItemTemplete').remove().html()); - var itemSize = pettanr.util.getElementSize( jqItemOrigin.get( 0)); - itemW = itemSize.width; - itemH = itemSize.height; - jqName = $( '#gruop-name-display'); - jqButton = $( '#image-gruop-button').click( onCloseClick); - buttonW = pettanr.util.getElementSize( jqButton.get( 0)).width; - - delete IMAGE_GROUP_EXPROLER.init; - }, - jqWrap: null, - show: function( _folder, _onUpdateFunction){ - this.init !== undefined && this.init(); - - folder = _folder; - onUpdateFunction = _onUpdateFunction; - pettanr.overlay.show( this); - - var l = _folder.getChildFileLength(); - for( var i=0; i containerW ? winW : containerW, - h = windowH > containerH ? containerH : windowH; - - jqWrap.show(); - jqContainer.css( { - width: w, - height: 0, - left: 0, - top: Math.floor( windowH /2) - }).stop().animate( { - height: h, - top: Math.floor( windowH /2 -h /2) - }); - - jqButton.css( { - left: Math.floor( winW /2 -buttonW /2), - top: Math.floor( windowH /2 +containerH /2 +10) - }); - - onEnterShowImage(); - }, - onWindowResize: function( _windowW, _windowH){ - var w = _windowW > containerW ? _windowW : containerW, - h = _windowH > containerH ? containerH : _windowH, - offsetW = Math.floor( _windowW /2 -winW /2); - winW = _windowW; - if( offsetW <= 0){ // smaller - jqContainer.css( { - left: offsetW, - width: w - }).animate( { - left: 0, - top: Math.floor( _windowH /2 -h /2) - }); - } else { - jqContainer.css( { // bigger - left: 0, - width: w, - borderLeftWidth: offsetW - }).animate( { - top: Math.floor( _windowH /2 -h /2), - borderLeftWidth: 0 - }); - } - jqButton.css( { - left: Math.floor( _windowW /2 -buttonW /2), - top: Math.floor( _windowH /2 +containerH /2 +10) - }); - onEnterShowImage(); - }, - onClose: close, - ID: 'imageGroupExproler' - } - })(); - /* - * - */ - function close(){ currentOverlay && currentOverlay.onClose && currentOverlay.onClose(); pettanr.overlay.hide(); @@ -1186,6 +1088,24 @@ pettanr.overlay = ( function(){ windowH = _windowH; // 先にeditorのcanvasを確定する。 currentOverlay && currentOverlay.onWindowResize && setTimeout( asyncResize, 0); + }, + resisterOverlay: function( _basicPane){ + pettanr.view.resisterAsBasicPane( _basicPane); + // OverlayAPI + return { + show: function( _basicPane ){ + + }, + hide: function( _basciPane ){ + + }, + isCurrent: function( _basicPane ){ + + } + } + }, + isOverlay: function( _basicPane ){ + } } })(); @@ -1386,7 +1306,7 @@ pettanr.form = ( function(){ instance = this; delete this.init; }, - update: function( _value){ + value: function( _value){ if( _value !== undefined){ elmA.innerHTML = _value; value = _value; @@ -1396,6 +1316,7 @@ pettanr.form = ( function(){ } } currentItem === instance && this.finish(); + return value; }, start: function(){ onClick(); @@ -1412,7 +1333,64 @@ pettanr.form = ( function(){ ON_UPDATE_FUNCTION && _newValue !== value && ON_UPDATE_FUNCTION( _newValue, value); finish( instance); - + value = _newValue; + focus = false; + }, + enabled: function(){ + return enabled; + }, + visible: function( _visible){ + if( _visible === true){ + WRAPPER_ELM.style.display = ''; + visible = true; + } else + if( _visible === false){ + WRAPPER_ELM.style.display = 'none'; + visible = false; + } + return visible; + }, + index : index, + groupID: GROUP_ID + } + } + + var FileInputClass = function( WRAPPER_ELM, ON_UPDATE_FUNCTION, GROUP_ID, validater, elmFileInput){ + validater = typeof validater === 'function' ? validater : null; + + var elmFilePath = pettanr.util.getElementsByClassName( WRAPPER_ELM, 'file-path')[ 0], + value, + index = GROUP_ID ? FORM_GROUP_TABLE[ GROUP_ID].length : -1, + instance, + focus = false, + visible = true, + enabled = true, + elmFileInput = WRAPPER_ELM.getElementsByTagName('input')[0] || elmFileInput || document.createElement( 'input'); + elmFileInput.type = 'file'; + elmFileInput.style.visivility = 'hidden'; + + WRAPPER_ELM.onclick = onClick; + elmFileInput.onchenge = onChange; + + function onClick( e){ + focus = true; + start( instance); + elmFileInput.click(); + return false; + } + + function onChange(){ + elmFilePath.innerHTML = elmFileInput.value; + } + return { + init: function(){ + instance = this; + delete this.init; + }, + start: function(){ + onClick(); + }, + finish: function( keep){ focus = false; }, enabled: function(){ @@ -1488,6 +1466,15 @@ pettanr.form = ( function(){ _groupID && FORM_GROUP_TABLE[ _groupID].push( ret); return ret; }, + createFileInput: function( _elm, _onUpdate, _groupID, _validater, _elmFileInput){ + if( typeof _groupID === 'string' && !FORM_GROUP_TABLE[ _groupID]){ + FORM_GROUP_TABLE[ _groupID] = []; + } + var ret = FileInputClass( _elm, _onUpdate, _groupID, _validater, _elmFileInput); + ret.init(); + _groupID && FORM_GROUP_TABLE[ _groupID].push( ret); + return ret; + }, createCheckBox: function(){ },