/*\r
* pettanR peta.common.js\r
- * version 0.5.50\r
+ * version 0.5.51\r
* \r
* author:\r
* itozyun\r
* \r
*/\r
pettanr.newBalloon = ( function(){\r
- var TEMPLETES = {};\r
+ var TEMPLETES = [];\r
\r
- var STROKE_WIDTH = 1.2,\r
+ var PICTURE_PATH = pettanr.CONST.SYSTEM_PICTURE_PATH,\r
+ STROKE_WIDTH = 1.2,\r
IS_VML = UA.isIE === true && UA.ieVersion < 9,\r
ELM_BALLOON_ORIGIN = ( function(){\r
var ret;\r
BalloonClass;\r
\r
if( vectorEnabled === true ){\r
- BalloonClass = function( templete ){\r
+ BalloonClass = function( klass ){\r
this.elm = ELM_BALLOON_ORIGIN.cloneNode( true );\r
this.path = this.elm.getElementsByTagName( IS_VML === true ? 'shape' : 'path' )[ 0 ];\r
this.klass = klass;\r
update : function( /* w, h [, angle, ,,, ] */ ){\r
var id = this.getPictureID.call( this.klass, arguments );\r
if( id !== 0 && !id ) return false;\r
- this.elm.src = pettanr.CONST.SYSTEM_PICTURE_PATH + id + '.gif';\r
+ this.elm.src = PICTURE_PATH + id + '.gif';\r
},\r
destroy : function(){\r
this.elm.parentNode && this.elm.parentNode.removeChild( this.elm );\r
};\r
};\r
\r
- /*\r
+ /* js を持たず ハッシュに格納したデータと 1枚以上の system picture から描画を行う\r
* http://sourceforge.jp/projects/pettanr/wiki/HowToMakeSpeechBalloon\r
*/\r
var NonVectorBalloonClass = function( templete ){\r
//this.defaultW = templete.default_width;\r
//this.defaultH = templete.default_height;\r
//this.sizeCount = templete.size_count;\r
- this.wOffset = templete.width_offset;\r
- this.hOffset = templete.height_offset;\r
- this.wStep = templete.width_step;\r
- this.hStep = templete.height_step;\r
+ this.wOffset = templete.speech_balloon.width_offset;\r
+ this.hOffset = templete.speech_balloon.height_offset;\r
+ this.wStep = templete.speech_balloon.width_step;\r
+ this.hStep = templete.speech_balloon.height_step;\r
// r_offset\r
// r_steps\r
\r
- var obj = templete.balloon_template_attributes, v, p;\r
- \r
- if( templete.size_count && 1 < templete.size_count ){\r
+ var obj = templete, v, p;\r
+ // 2013.3.31 itozyun's memo\r
+ // 以下の使いやすく加工する処理は pettanr.balloon.register() 内に移動してもよさそう\r
+ // new TempleteClass( templeteJson );\r
+ // NonVectorBalloon.templete.defaultW みたいにアクセス\r
+ if( templete.speech_balloon.size_count && 1 < templete.speech_balloon.size_count ){\r
this.picIDs = []; // system picture id list\r
- for( p in obj ){\r
- v = obj[ v ];\r
- this.picIDs[ v.size ] = v.system_picture_id;\r
+ for( p in templete ){\r
+ if( p === 'speech_balloon' ) continue;\r
+ v = obj[ p ];\r
+ this.picIDs[ this.picIDs.length ] = v.balloon.system_picture_id;\r
}; \r
} else {\r
for( p in obj ){\r
- v = obj[ v ];\r
- this.picID = v.system_picture_id;\r
+ if( p === 'speech_balloon' ) continue;\r
+ v = obj[ p ];\r
+ this.picID = v.balloon.system_picture_id;\r
+ break;\r
};\r
};\r
};\r
args : null,\r
picIDs : null,\r
picID : 0,\r
- path : pettanr.CONST.SYSTEM_PICTURE_PATH,\r
+ src : 0,\r
+ w : 0,\r
+ h : 0,\r
update : function( w, h /* [, angle, ,,, ] */ ){\r
var l, id, _w, _h;\r
if( this.picIDs ){\r
l = this.picIDs.length - 1;\r
_w = _w < 0 ? 0 : ( _w > l ? l : _w );\r
_h = _h < 0 ? 0 : ( _h > l ? l : _h );\r
- id = this.picIDs[ _w > _h ? _w : _h ];\r
+ id = this.picIDs[ Math.floor( _w > _h ? _w : _h ) ];\r
} else {\r
id = this.picID;\r
};\r
- \r
- this.elm.src = this.path + id + '.gif';\r
- this.size.width = w + 'px';\r
- this.size.height = h + 'px';\r
+ if( this.src !== id ){\r
+ this.elm.src = PICTURE_PATH + id + '.gif';\r
+ this.src = id;\r
+ };\r
+ if( this.w !== w ){\r
+ this.size.width = w + 'px';\r
+ this.w = w;\r
+ };\r
+ if( this.h !== h ){\r
+ this.size.height = h + 'px';\r
+ this.h = h;\r
+ };\r
},\r
- destory : function(){\r
+ destroy : function(){\r
this.elm.parentNode && this.elm.parentNode.removeChild( this.elm );\r
}\r
};\r
* balloon_templetes.json 取得時に呼ばれる\r
* className は存在しない場合もある \r
*/\r
- register : function( name, templete ){\r
+ register : function( id, name, templete ){\r
templete = $.parseJSON( templete );\r
if( !TEMPLETES[ name ] ){\r
- TEMPLETES[ name ] = templete.speech_balloon;\r
+ TEMPLETES[ name ] = templete;\r
+ TEMPLETES[ id ] = templete;\r
};\r
},\r
- create : function( name ){\r
- if( Type.isString( name ) === true && name in window ){\r
- return new BalloonClass( window[ name ] );\r
+ create : function( idOrName, w, h /* [, angle, ,,, ] */ ){\r
+ var ret;\r
+ if( Type.isString( idOrName ) === true && idOrName in window ){\r
+ ret = new BalloonClass( window[ idOrName ] );\r
+ } else {\r
+ ret = new NonVectorBalloonClass( TEMPLETES[ idOrName ] );\r
};\r
- return new NonVectorBalloonClass( TEMPLETES[ name ] );\r
+ ret.update( w, h /* [, angle, ,,, ] */ );\r
+ return ret;\r
},\r
isTemplete : function( templete ){\r
\r
'z-index:', data.z, ';'\r
].join( '' );\r
\r
- balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail );\r
+ //balloon = pettanr.balloon.createBalloon( data.width, data.height, data.tail );\r
+ balloon = pettanr.newBalloon.create( data.id, data.width, data.height, data.tail );\r
elmBalloonWrap.appendChild( balloon.elm );\r
\r
elmBalloonWrap.appendChild( elmText );\r