');
// Customized
if ( _style == 'simple' ) {
this.mat.append(this.temp.selectable);
} else {
this.mat.append(this.temp.simpleBox);
}
// Customized end
this.mat.attr({
id: this.attrs.id+'_mat'
}).addClass(_style).addClass(this.attrs.cl);
}
// For rebuilding
if ( this.generatedFlg) {
this.mat.empty();
if ( _style == 'simple' ) {
this.mat.append(this.temp.selectable);
} else {
this.mat.append(this.temp.simpleBox);
}
}
this._div = $('
');
if ( has_optgroup ) {
this.mat.addClass('otpgroup');
var _optgroup = $('optgroup', this.target);
var _option = [];
for ( var i=0; i<_optgroup.length; i++ ) {
_option[i] = $('option', _optgroup[i]);
}
var _dl = $('
');
for ( var i=0; i<_optgroup.length; i++ ) {
var _dt = $('- ');
_dt.text($(_optgroup[i]).attr('label'));
var _dd = $('
- ');
for ( var j=0; j<_option[i].length; j++ ) {
generate_anchors($(_option[i][j]), _dd);
}
_dl.append(_dt).append(_dd);
}
this._div.append(_dl).addClass('optg');
$('div', this.mat).append(this._div);
} else {
this.mat.addClass('nooptgroup');
var _option = $('option', this.target);
for ( var i=0; i<_option.length; i++ ) {
generate_anchors($(_option[i]), this._div);
}
$('div', this.mat).append(this._div.addClass('nooptg'));
}
// For rebuilding
if ( !this.generatedFlg ) {
$('body').append(this.mat);
this.mat.addClass('sctble_mat').css({
position: 'absolute',
zIndex: 1000,
display: 'none'
});
$('*:first-child',this.mat).addClass('first-child');
$('*:last-child',this.mat).addClass('last-child');
}
// This is for IE6 that doesn't have "max-height" properties
if ( document.all && typeof document.body.style.maxHeight == 'undefined' ) {
if ( this.conf.height < this.mat.height() ) {
$(this._div).css('height', this.conf.height);
}
// Other browsers
} else {
$(this._div).css('maxHeight', this.conf.height);
}
// get height of the mat
this.mat.show();
this.matHeight = this.mat.attr('offsetHeight');
this.mat.hide();
},
// Bind events
// @ 09-09-17 22:59
bind_events: function() {
var _this = this;
// Flag checking where the events was called
var is_called = true;
var set_pos = function() {
var topPos,
scrollTop = document.documentElement.scrollTop || document.body.scrollTop,
clientHeight = document.documentElement.clientHeight || document.body.clientHeight,
_pos = _this.m_input.offset();
if ( clientHeight/2 < (_pos.top - scrollTop) ) {
topPos = _pos.top - _this.matHeight + _this.conf.top - 5;
} else {
topPos = _pos.top + _this.m_input.height()*1.3 + _this.conf.top;
}
_this.mat.css({
top: topPos,
left: _pos.left + _this.conf.left
});
}
$(window).resize(function() {
set_pos();
});
// Hide all mats are displayed
var mat_hide = function() {
var _mat = $('.sctble_mat');
switch( _this.conf.out ) {
case 'slideUp':
_mat.slideUp(_this.conf.outDuration);
break;
case 'fadeOut':
_mat.fadeOut(_this.conf.outDuration);
break;
default:
_mat.hide();
break;
}
}
// Show the mat
var mat_show = function() {
mat_hide();
if ( _this.conf.set == 'slideDown' ) {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop,
clientHeight = document.documentElement.clientHeight || document.body.clientHeight,
_pos = _this.m_input.offset(),
balance = clientHeight/2 < (_pos.top - scrollTop);
if ( balance ) {
_this.mat.css('top', _pos.top + _this.conf.top - 5);
}
}
if ( _this.conf.set == 'slideDown' ) {
if ( balance ) {
_this.mat
.animate({
height: 'toggle',
top: parseInt(_this.mat.css('top')) - _this.matHeight
}, {
easing: 'swing',
duration: _this.conf.setDuration
})
.css('opacity', _this.conf.opacity);
} else {
_this.mat.slideDown(_this.conf.setDuration).css('opacity', _this.conf.opacity);
}
} else
if ( _this.conf.set == 'fadeIn' ) {
_this.mat.css({
display: 'block',
opacity: 0
}).fadeTo(_this.conf.setDuration, _this.conf.opacity);
} else {
_this.mat.show().css('opacity', _this.conf.opacity);
}
var _interval = isNaN(_this.conf.setDuration) ? null : _this.conf.setDuration+10;
if( _interval == null ) {
if ( _this.conf.setDuration.match(/slow/) ) {
interval = 610;
} else if ( _this.conf.setDuration.match(/normal/) ) {
interval = 410;
} else {
interval = 210;
}
}
var _chk = setInterval(function() {
$('a.selected', _this.mat).focus();
clearInterval(_chk);
}, _interval);
}
// Call selectable
this.m_input.click(function(event) {
if ( _this.mat.is(':visible') ) return false;
set_pos();
$(this).addClass('sctble_focus');
$('a.sctble_display').not(this).removeClass('sctble_focus');
mat_show();
event.stopPropagation();
return false;
}).keyup(function(event) {
if( is_called ){
set_pos();
mat_show();
event.stopPropagation();
} else {
is_called = true;
}
});
// Stop event propagation
this.mat.click(function(event) {
event.stopPropagation();
});
// Hide the mat
$('body, a').not('a.sctble_display').click(function(event) {
$('a.sctble_display').removeClass('sctble_focus');
mat_hide();
}).not('a').keyup(function(event) {
if ( event.keyCode=='27' ) {
$('a.sctble_focus').removeClass('sctble_focus');
is_called = false;
_this.m_input.blur();
mat_hide();
}
});
// Click value append to both dummy and change original select value
$('a', this.mat).click(function() {
var self = $(this);
_this.m_text.text(decodeURI(self.attr('href').split('#')[1]));
$('option[value="'+self.attr('name')+'"]', _this.target).attr('selected', 'selected');
$('.selected', _this.mat).removeClass('selected');
self.addClass('selected');
_this.m_input.removeClass('sctble_focus');
is_called = false;
mat_hide();
if ( _this.conf.callback && typeof _this.conf.callback=='function' ) {
_this.conf.callback.call(_this.target);
}
_this.m_input.focus();
return false;
});
// Be able to click original select label
$('label[for="'+this.attrs.id+'"]').click(function(event) {
set_pos();
_this.m_input.addClass('sctble_focus');
$('a.sctble_focus').not(_this.m_input).removeClass('sctble_focus');
mat_show();
event.stopPropagation();
return false;
});
}
}
// Extense the namespace of jQuery as method
// This function returns (the) instance(s)
$.fn.jQselectable = function(options, temp) {
if ( $(this).length>1 ) {
var _instances = [];
$(this).each(function(i) {
_instances[i] = new jQselectable(this, options, temp);
});
return _instances;
} else {
return new jQselectable(this, options, temp);
}
}
// If namespace of jQuery.fn has 'selectable', this is 'jQselectable'
// To prevent the interference of namespace
// You can call 'selectable' method by both 'jQuery.fn.selectable' and 'jQuery.fn.jQselectable' you like
if ( !jQuery.fn.selectable ) {
$.fn.selectable = $.fn.jQselectable;
}
})(jQuery);/*!
* Copyright goodsmore
* version 0.93
* Dual licensed under the MIT or GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
/*!
* オプションの使用例
* var ArticleId = $.getArticleId() ;
* $('#moshimo_sozai').getSozai( ArticleId, {
* width : 500 ,
* addclass: 'item_sozai',
* duration: 1500,
* preShow:function( el ){
* alert( '素材表示するね ちょっと待ってね♪' ) ;
* },
* onAfter:function( el ){
* alert( 'やった 素材表示できたよ♪' ) ;
* }
* });
*
* クロスドメインで利用する場合の javascriptコード例
* var ArticleId = $.getArticleId() ;
* $( '#moshimo_sozai' ).getSozai( ArticleId, { password:'パスワード' , ajaxUrl:'http://www.example.jp/get_sozai/' });
*/
(function($) {
$.extend({
getUrlParameters: function(url){
var vars = [], hash;
var hashes = url.slice(url.indexOf('?') + 1).split('&');
for( var i = 0; i < hashes.length; i++ ){
hash = hashes[i].split('=');
vars.push( hash[0] );
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlParameter: function(url,name){
return $.getUrlParameters(url)[name];
},
getArticleId: function(){
var article_id = 0
var url = $( 'a[ href ^= "http://www.moshimo.com/cart/add?"]' ).attr( 'href' ) || '' ;
if ( url.indexOf( 'article_id=' ) !== -1 ) article_id = parseInt( $.getUrlParameter( url, 'article_id' ) ) ;
return article_id ;
}
});
$.fn.reSize = function( maxwidth ,o ){
var defaults = {
bindLoad: true ,
onAfter: null
};
var option = $.extend( {},defaults, o ) ;
var _resize = function( el ) {
var width = el.width() ;
var height = el.height() ;
if ( width > maxwidth ){
var showsize = maxwidth / width ;
width = width * showsize ;
height = height * showsize ;
}
var style = ( width == 0 ) ? { 'width': maxwidth } : { 'width': width ,'height': height } ;
el.attr( style ) ;
if( $.isFunction( option.onAfter ) ) option.onAfter.call( this, el ) ;
} ;
return this.each( function(){
var el = $( this ) ;
switch( option.bindLoad ) {
case true:
el.bind( 'load', function() {
_resize( el ) ;
});
break;
case false :
_resize( el ) ;
break;
}
return ;
}) ;
};
$.fn.getSozai = function( params ){
var article_id;
var o;
var file_name = 'jquery.get_sozai.js' ;
var defaults = {
width: null,
addclass: null,
duration: null,
preShow: null,
onAfter: null,
password: '',
ajaxUrl: '',
json: null
};
for ( i= 0; i <= 1; i++ ) {
if ( typeof arguments[i] =='object' ) o = arguments[i] ;
else if ( typeof arguments[i] =='number' ) article_id = parseInt( arguments[i] ) ;
}
var option = $.extend( {},defaults, o ) ;
var url = base_url + 'ajax_load.php';
var dataType = ( option.password == '' ) ? 'json' : 'jsonp' ;
var get_article_id = function( e ) {
var article_id = 0
var defined = $( e ).attr( 'id' ) || '' ;
var id = ( defined !== '' ) ? defined.split( '_' ) : '' ;
article_id = ( defined !== '' ) ? parseInt( id[1] ) : 0 ;
return article_id ;
} ;
var showSozai = function ( el, json ) {
var width = parseInt( option.width ) || parseInt( json.width ) ;
var addclass = option.addclass || json.addclass ;
var duration = parseInt( option.duration ) || parseInt( json.duration ) ;
if( $.isFunction( option.preShow ) ) option.preShow.call( this, el ) ;
el
.html( json.sozai )
.addClass( addclass ) ;
var images = $( '#[ id ^= "' + json.sozai_id + '" ]', el ) ;
var size = images.size() ;
images.hide().wrap( '' ) ;
$.each( images, function( i, value ){
$( this ).reSize( width, {
onAfter:function( sozaj ){
sozaj.fadeIn( duration, function () {
if( ( i + 1 ) == size ) {
if( $.isFunction( option.onAfter ) ) option.onAfter.call( this, el, images ) ;
}
}) ;
}
});
});
return ;
} ;
return this.each( function(){
var el = $( this ) ;
switch( $.isPlainObject( option.json ) ) {
case true:
showSozai( el, option.json ) ;
break;
case false :
var id = article_id || get_article_id( this ) ;
if ( id > 0 ){
var parameter = 'id=' + id ;
if ( dataType == 'jsonp' ) parameter = parameter + '&password=' + encodeURIComponent( option.password ) + '&host=' + encodeURIComponent( location.hostname ) ;
var successCallback = function ( json, status ) {
if ( typeof json == 'string' ) alert ( json ) ;
if ( status !== 'error' && json.sozai ) showSozai( el, json ) ;
} ;
$.ajax({ type: 'GET', url: url, data: parameter, async : true, dataType : dataType, global: false, success : successCallback }) ;
}
break;
}
return ;
}) ;
};
})(jQuery);