/**
* JavaScript libraries for Glexa
*
* Copyright (C) 2016 VERSION2 Inc. All rights reserved.
*
*/
$(document).ready(function(){
// fixbug tinymce can not type on modal
$(document).on('focusin', function(e) {
if ($(e.target).closest(".mce-window, .moxman-window").length) {
e.stopImmediatePropagation();
}
});
// TinyMCEの入ったelementを書き換える場合、その前にTinyMCEを削除しないと再表示の際にエラーとなる場合がある。(Firefox, Edge等)
var orgHtml = $.fn.html;
$.fn.html = $.extend(function() {
if ($(this).find('.mce-tinymce').length) {
glexa.clearMCE();
}
try {
return orgHtml.apply(this, arguments);
} catch (e) {
console.log(e);
}
}, orgHtml);
});
$(function(){
// first load
// $('body').disableSelection();
// $('textarea,input').enableSelection();
});
var glexa = glexa || {
// Consts
ERROR_MSG_UNKNOWN : 'An error has occurred.',
ERROR_MSG_SERVER_ERROR : 'A server error has occurred.',
DEFAULT_MSG_DONE : 'Process has been successfully completed.',
// Properties
isLoading : false,
loadingCount : 0,
loadingOverlay : null,
currentModalZIndex : 9999,
dispModalCount : 0,
modalBuff : {},
modalCbFuncs : [],
postCallback : null,
completeCallback : null,
timerAccess : undefined,
arInput:0,
arInputDefault:0,
isTimeout:0,
// Methods
// Ajax/Loading
loading : function(isRemove) {
isRemove = isRemove ? true : false;
if (isRemove) {
glexa.loadingCount--;
if (glexa.loadingCount > 0) {
return;
}
glexa.loadingCount = 0;
} else {
glexa.loadingCount++;
}
if (isRemove) {
if (glexa.loadingOverlay != null) {
glexa.loadingOverlay.remove();
}
glexa.loadingOverlay = null
} else if (glexa.loadingOverlay == null) {
try {
glexa.loadingOverlay = getBusyOverlay("viewport", {
color : 'black',
opacity: 0.1,
text : 'loading',
style : 'text-decoration:blink;font-weight:bold;font-size:12px;color:white;z-index:9999'
}, {
color: '#666',
size : 100,
type : 'c'
});
} catch(e) {}
}
},
//ajax通信を行う
ajax : function(options) {
var action = options.action ? options.action : null;
var params = options.params ? options.params : {};
var hasFile = options.hasFile ? options.hasFile : false;
var method = options.method ? options.method : null;
var element = options.element ? options.element : null;
var isAppend = options.isAppend ? true : false;
var beforeSend = options.beforeSend ? options.beforeSend : function() {};
var onSuccess = options.onSuccess ? options.onSuccess : function(res) {};
var onError = options.onError ? options.onError : function(res) {};
var onComplete = options.onComplete ? options.onComplete : function(res) {};
var withoutLoading = options.withoutLoading ? options.withoutLoading : false;
//var isJSON = options.isJSON ? options.isJSON : null;
var isSuccess = false;
if (action) {
if (typeof params === 'string') {
params += '&action=' + action;
} else {
params.action = action;
}
}
var ajaxOptions = {
type: (method ? method : window.loadmethod ? window.loadmethod : 'post'),
url: window.urlbase,
data: params,
cache: false,
timeout: 0, // 単位はミリ秒
//dataType: (isJSON ? 'json' : 'html'),
beforeSend: function() {
if (!withoutLoading) {
glexa.loading();
}
beforeSend();
},
success: function(res) {
isSuccess = true;
//レスポンスをjsonパースできればjsonに、できなければhtmlとして扱う
var json = null;
try {
json = $.parseJSON(res);
} catch(e) {
if (res) {
json = {
success : true,
html : res
};
} else {
json = {
success : false
};
}
}
if (json.success) {
if (json.message) {
$('.div-message,.modal-body').prepend('
' + json.message + '
');
setTimeout(function() {
$('.modal-body .div-alert-success').fadeOut('slow', function() { $('.modal-body .div-alert-success').remove(); });
}, 5000);
$('.div-message .div-alert-success').off().on('click', function(){
$(this).fadeOut('slow', function(){
$('.div-message .div-alert-success').remove();
});
});
}
if (element && json.html) {
if (isAppend) {
$(element).append(json.html);
} else {
$(element).html(json.html);
}
}
onSuccess(json);
$('input').attr('autocomplete', 'off');
} else {
if (json.error) {
$('.div-message,.modal-body').prepend('' + json.error + '
');
setTimeout(function() {
$('.modal-body .div-alert-error').fadeOut('slow', function() { $('.moda-body .div-alert-error').remove(); });
}, 5000);
$('.div-message .div-alert-error').off().on('click', function(){
$(this).fadeOut('slow', function(){
$('.div-message .div-alert-error').remove();
});
});
$('#div-common-remote-modal').animate({scrollTop:0}, 100, 'swing');
}
if (json.data && json.data.elements) {
// TODO console.log(json.data.elements);
}
if (onError) {
onError(json);
}
}
},
complete: function(res) {
if (!isSuccess) {
/*
$('.div-offline').show();
glexa.openCommonAlertModal({
body : glexa.ERROR_MSG_SERVER_ERROR
});
*/
}
if (!withoutLoading) {
glexa.loading(true);
}
if (onComplete) {
onComplete();
}
},
statusCode: {
403: function() {
glexa.openCommonAlertModal({
body : glexa.ERROR_MSG_SERVER_ERROR
});
},
205: function() {
window.location.reload();
}
},
error: function() {
$('.div-offline').show();
}
};
if (hasFile) {
ajaxOptions['processData'] = false;
ajaxOptions['contentType'] = false;
}
return $.ajax(ajaxOptions);
},
//ajaxでformをsubmitする
ajaxForm : function(options) {
var form = options.form ? options.form : null;
var hasFile = options.hasFile ? options.hasFile : false;
var element = options.element ? options.element : null;
var method = options.method ? options.method : null;
var beforeSend = options.beforeSend ? options.beforeSend : function() {};
var onSuccess = options.onSuccess ? options.onSuccess : function(res) {};
var onError = options.onError ? options.onError : function(res) {};
var onComplete = options.onComplete ? options.onComplete : function(res) {};
var withoutLoading = options.withoutLoading ? options.withoutLoading : false;
if (hasFile) {
//ファイル送信がある場合
return glexa.ajax({
//action : $(form).find('input[name="action"]').val(),
params : new FormData($(form).get(0)),
method : method,
element : element,
beforeSend : beforeSend,
hasFile: true,
onSuccess : onSuccess,
onError : onError,
onComplete : onComplete,
withoutLoading: withoutLoading,
});
} else {
//ファイル送信がない場合
return glexa.ajax({
//action : $form.attr('action'),
params : $(form).serialize(),
method : method,
element : element,
beforeSend : beforeSend,
onSuccess : onSuccess,
onError : onError,
onComplete : onComplete,
withoutLoading: withoutLoading,
});
}
},
/**
* モーダル関連
*
* openCommonModal: モーダルを開く(モーダル用のHTMLは自前で準備する)
* - modal: jQueryのモーダル要素名
* - cbFunc: 閉じたときのcallback関数
*
* openCommonAlertModal: OKが表示されるモーダル
* - title: モーダルのタイトル
* - body: 表示名
* - btnOkName: OKボタンの表示名(省略でOK)
* - onOk: OKボタンが押されたときのcallback関数(省略で閉じる動作)
*
* openCommonConfirmModal: Yes,Noが表示されるモーダル
* - title: モーダルのタイトル
* - body: 表示名
* - btnYesName: OKボタンの表示名(省略でYES)
* - btnNoName: OKボタンの表示名(省略でNO)
* - onYes: Yesボタンが押されたときのcallback関数
* - onNo: Noボタンが押されたときのcallback関数(省略で閉じる動作)
*
* openRemoteModal: ajaxで内容を取得するモーダル
* - action: アクション名
* - params: URLパラメータ({}オブジェクトにて定義)
* - cbFunc: 閉じたときのcallback関数
* - onErrorMsg: エラー時のメッセージ
*
*/
openCommonModal : function(options) {
if(!options) options = {};
var modal = options.modal ? options.modal : null;
var cbFunc = options.cbFunc ? options.cbFunc : null;
var onOk = options.onOk ? options.onOk : function() {
glexa.closeCommonModal({
modal: modal
});
};
var onOpened = options.onOpened ? options.onOpened : false;
var keyboard = (options.keyboard != null) ? options.keyboard : true;
var eventInit = (options.eventInit != null) ? options.eventInit : true;
if (eventInit) {
$(modal).off('hidden.bs.modal');
}
var close_callback = function(){
if (glexa.modalBuff[modal]) {
if (typeof glexa.modalBuff[modal].cbFunc === 'function') {
(glexa.modalBuff[modal].cbFunc)();
}
delete glexa.modalBuff[modal];
}
};
if (glexa.modalBuff[modal]) {
//
//glexa.closeCommonModal(modal);
close_callback();
}
$('#btn-common-alert-modal-ok').off().on('click', onOk);
//glexa.modalCbFuncs.push(cbFunc); //モーダルを重ねる度にコールバックを登録(末尾に登録されているのが現在のモーダルのコールバックになる)
glexa.modalBuff[modal] = {
cbFunc : cbFunc,
zIndex : glexa.currentModalZIndex,
};
$(modal).css({
zIndex : glexa.currentModalZIndex
}).modal({
backdrop: 'static',
show: true,
keyboard: keyboard
});
glexa.currentModalZIndex++;
glexa.dispModalCount = Object.keys(glexa.modalBuff).length;
$(modal).on('hidden.bs.modal', function() {
close_callback();
// if (glexa.modalBuff[modal]) {
// if (typeof glexa.modalBuff[modal].cbFunc === 'function') {
// (glexa.modalBuff[modal].cbFunc)();
// }
// delete glexa.modalBuff[modal];
// }
var zIndex = glexa.currentModalZIndex - 1;
$.each(glexa.modalBuff, function(idx, value){
zIndex = Math.max(value.zIndex + 1, zIndex);
});
glexa.currentModalZIndex = zIndex;
glexa.dispModalCount = Object.keys(glexa.modalBuff).length;
if (glexa.dispModalCount > 0) {
$('body').addClass('modal-open');
} else {
glexa.dispModalCount = 0;
$('body').removeClass('modal-open');
$(document).off('keypress');
}
// その時点で開いているtimepickerを全てOFF
$('.timepicker').timepicker('hideWidget');
});
if (onOpened) {
onOpened($(modal));
}
},
//共通モーダルクローズラッパー
closeCommonModal : function(options) {
if(!options) options = {};
var modal = options.modal ? options.modal : null;
if (!modal) {
return;
}
// cbFunc = glexa.modalCbFuncs.pop(); //モーダルを閉じる度にコールバックを削除
// if (cbFunc) {
// cbFunc();
// }
// glexa.currentModalZIndex--;
// if (glexa.modalBuff[modal]) {
// if (typeof glexa.modalBuff[modal].cbFunc === 'function') {
// (glexa.modalBuff[modal].cbFunc)();
// }
// }
$(modal).modal('hide');
if ($(modal).size() > 1) {
$(modal + ':last-child').remove();
}
},
//共通アラートモーダルを開く
alert : function(body, title) {
glexa.openCommonAlertModal({
title: title,
body: body
});
},
openCommonAlertModal : function(options) {
if (!options) options = {};
var title = options.title ? options.title : '';
var body = options.body ? options.body : '';
var btnOkName = options.btnOkName ? options.btnOkName : 'OK';
var onOk = options.onOk ? options.onOk : '';
var keyboard = (options.keyboard != null) ? options.keyboard : true;
if (title) {
$('#div-common-alert-modal').attr('aria-labelledby', title);
$('#div-common-alert-modal .modal-title').html(title);
$('#div-common-alert-modal .modal-header').show();
} else {
$('#div-common-alert-modal .modal-header').hide();
}
$('#div-common-alert-modal .modal-body').html(body);
$('#btn-common-alert-modal-ok').html(btnOkName);
glexa.openCommonModal({
modal : '#div-common-alert-modal',
onOpened: function(modal) {
$(document).off('keypress').on('keypress', function(e) {
if (e.keyCode == 13) {
glexa.closeCommonAlertModal();
}
});
},
onOk: onOk,
keyboard: keyboard
});
},
//共通アラートモーダルを閉じる
closeCommonAlertModal : function(options) {
if (!options) options = {};
glexa.closeCommonModal({
modal : '#div-common-alert-modal'
});
},
//共通確認モーダルを開く
confirm : function(body, onYes, title, onNo) {
glexa.openCommonConfirmModal({
title: title,
body: body,
onYes: onYes,
onNo: onNo
});
},
openCommonConfirmModal : function(options) {
if(!options) options = {};
var modal = options.modal ? options.modal : '#div-common-confirm-modal';
var title = options.title ? options.title : ' ';
var body = options.body ? options.body : '';
var btnYesName = options.btnYesName ? options.btnYesName : false;
var btnNoName = options.btnNoName ? options.btnNoName : false;
var disableEnterKey = options.disableEnterKey ? options.disableEnterKey : false;
var onYes = options.onYes ? function(e) { if (options.onYes(e) !== false) { glexa.closeCommonConfirmModal(); } } : function() {
glexa.closeCommonConfirmModal();
};
var onNo = options.onNo ? function(e) { if (options.onNo(e) !== false) { glexa.closeCommonConfirmModal(); } } : function() {
glexa.closeCommonConfirmModal();
};
$(modal).attr('aria-labelledby', title);
$(modal + ' .modal-title').html(title);
$(modal + ' .modal-body').html(body);
if (btnYesName) {
$(modal + ' .btn-common-confirm-modal-yes').html(btnYesName)
}
if (btnNoName) {
$(modal + ' .btn-common-confirm-modal-no').html(btnNoName);
}
$(modal + ' .btn-common-confirm-modal-yes').off().on('click', onYes);
$(modal + ' .btn-common-confirm-modal-no').off().on('click', onNo)
glexa.openCommonModal({
modal : modal,
onOpened: function(object) {
if (!disableEnterKey) {
$(document).off('keypress').on('keypress', function (e) {
if (e.keyCode == 13) {
$(modal + ' .btn-common-confirm-modal-yes').trigger('click');
}
});
}
}
});
},
// 確認モーダルを閉じる
closeCommonConfirmModal : function(options) {
if(!options) options = {};
// FIXME: elementが指定されていた場合どうする? ↓は固定になってるけど。
$('#div-common-confirm-modal .btn-common-confirm-modal-yes').off();
$('#div-common-confirm-modal .btn-common-confirm-modal-no').off();
glexa.closeCommonModal({
modal : '#div-common-confirm-modal'
});
},
// 別Actionから出力されるHTMLをモーダルで開く
openRemoteModal : function(options) {
var action = options.action ? options.action : '';
var params = options.params ? options.params : {};
var disableEnterKey = options.disableEnterKey ? options.disableEnterKey : false;
var cbFunc = options.cbFunc ? options.cbFunc : null;
var onErrorMsg = options.onErrorMsg ? options.onErrorMsg : glexa.ERROR_MSG_UNKNOWN;
var method = options.method ? options.method : 'get';
$('#div-common-remote-modal').off('hidden.bs.modal');
glexa.ajax({
action : action,
params : params,
method: method,
element : '#div-common-remote-modal',
onSuccess : function(res) {
glexa.openCommonModal({
modal : '#div-common-remote-modal',
cbFunc : cbFunc,
eventInit : false,
onOpened: function() {
if (!disableEnterKey) {
$(document).off('keypress').on('keypress', function(e) {
if (e.keyCode == 13) {
if (e.target.nodeName != 'TEXTAREA') {
e.preventDefault();
$('#btn-common-alert-modal-send').trigger('click');
}
}
});
}
}
});
//モーダルクローズ時にエレメントを消去するように設定しておく
//(でないとJSが効かなくなったりする)
var $modal = $('#div-remote-modal' + ' > div:last-child');
$modal.on('hidden.bs.modal', function () {
glexa.closeRemoteModal({
modal : $modal
});
})
},
onError : function(res) {
// var errMsgs = [];
// if (res.error) {
// $.each(res.error, function(k,v) {
// if (v.msg) {
// errMsgs.push(v.msg);
// }
// });
// }
// var errMsg = errMsgs.join('
');
var errMsg = res.error;
if(errMsg){
onErrorMsg = errMsg;
}
glexa.openCommonAlertModal({
body : onErrorMsg,
onOk : function() {
glexa.closeCommonAlertModal();
glexa.closeCommonConfirmModal();
}
});
}
});
},
//リモートモーダルクローズラッパー
closeRemoteModal : function(options) {
if(!options) options = {};
var modal = options.modal ? options.modal : '#div-common-remote-modal';
//$(modal).html('');
glexa.closeCommonModal({
modal : modal
});
},
//リモートモーダルの中身を更新する
updateRemoteModal : function(options) {
var modal = options.modal ? options.modal : '';
var action = options.action ? options.action : '';
var params = options.params ? options.params : {};
var cbFunc = options.cbFunc ? options.cbFunc : null;
glexa.ajax({
action : action,
params : params,
onSuccess : function(res) {
if (res && res.html) {
$(modal).html($(res.html).html());
}
if (cbFunc) {
cbFunc();
}
}
});
},
// エレメント操作関連
inlineEditor : function(options) {
var prevValue;
if (typeof options == 'string') {
if (options == 'destroy') {
$(element).off();
$(viewElement).off();
}
return;
}
var options = options || {};
var onSuccess = options.onSuccess ? options.onSuccess : false;
var element = options.element ? options.element : '.x-inline-edit';
var viewElement = options.viewElement ? options.viewElement : 'span';
$(element).find('input,textarea').hide();
$(element).css('cursor', 'pointer');
$(element).on('click', function(e) {
$(this).find(viewElement).hide();
$(this).find('input,textarea').show();
$(this).find('input,textarea').focus();
prevValue = $(this).find('input,textarea').val();
});
$(element).find('input,textarea').off('blur keypress').on('blur keypress', function(e) {
if (e.type == 'keypress' && e.which == 13 || e.type == 'blur') {
if (onSuccess) {
if (prevValue != $(this).val()) {
onSuccess($(this));
}
}
$(this).parent().find(viewElement).html($(this).val()).show();
$(this).hide();
}
});
},
// divのopen/close
openField : function(options) {
var options = options || {};
var isSave = options.isSave ? options.isSave : true;
var isOpen = options.isOpen ? options.isOpen : false;
var element = options.element ? options.element : '.x-openclose';
var titleElement = options.titleElement ? options.titleElement : '.x-openclose-title';
var viewElement = options.viewElement ? options.viewElement : 'div';
$(element).each(function() {
var id = $(this).attr('id');
if (id && isSave) {
isOpen = glexa.localStorage.getItem(element + '-' + id) == '1' ? true : false;
}
if (isOpen) {
if ($(this).children(titleElement).find('.icon').size() == 0) {
$(this).children(titleElement).html('
' + $(this).children('.x-openclose-title').html());
}
} else {
$(this).children(viewElement).hide();
if ($(this).children(titleElement).find('.icon').size() == 0) {
$(this).children(titleElement).html('
' + $(this).children('.x-openclose-title').html());
}
}
$(this).children(titleElement).css('cursor', 'pointer');
$(this).children(titleElement).off().on('click', function(e) {
e.preventDefault();
if ($(this).next(viewElement).isVisible()) {
$(this).next(viewElement).slideUp('fast');
$(this).children('img.icon').attr('src', window.urlbase + 'common/images/icons/plus.png');
if (id && isSave) {
glexa.localStorage.setItem(element + '-' + id, 0);
}
} else {
$(this).next(viewElement).slideDown('fast');
$(this).children('img.icon').attr('src', window.urlbase + 'common/images/icons/minus.png');
if (id && isSave) {
glexa.localStorage.setItem(element + '-' + id, 1);
}
}
});
});
},
// tinyMCEをセットする
setMCE : function(options) {
var options = options || {};
var selector = options.selector ? options.selector : '.mce';
var plugin = options.plugin ? options.plugin : '';
var noneMenu = options.none_menu ? options.none_menu : false;
var extended = options.extended ? options.extended : '';
var customInit = options.modify_init ? options.modify_init : false;
if (!$('.mce-tinymce').get(0)) {
glexa.clearMCE();
}
tinymce.init({
mode : "exact",
selector: selector,
content_css : window.urlbase + "common/css/glexa_mce.css",
language : lang,
menubar : false,
convert_urls: false,
toolbar: plugin + (noneMenu ? '' : 'fontsizeselect | bold italic underline forecolor backcolor | strikethrough alignleft aligncenter alignright alignjustify | charmap table | undo redo link unlink | cleanup fullscreen code | leaui_formula'),
theme_advanced_buttons1 : '',
theme_advanced_buttons2 : '',
theme_advanced_buttons3 : '',
theme_advanced_buttons4 : '',
theme_advanced_toolbar_location : 'top',
theme_advanced_toolbar_align : 'left',
theme_advanced_statusbar_location : 'bottom',
theme_advanced_resizing : true,
extended_valid_elements : extended + 'a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],iframe[src|width|height|name|align],i/em,ruby,rb,rp,rt',
plugins : 'glexaquizfill,table,contextmenu,fullscreen,noneditable,tabfocus,visualchars,textcolor,wordcount,anchor,link,charmap,code,leaui_formula,paste',
forced_root_block : false,
accessibility_focus : false,
preformatted : true,
remove_linebreaks : true,
resize : true,
paste_retain_style_properties : 'all',
setup: function(editor) {
editor.on('change', function() {
tinymce.triggerSave();
});
if (customInit) {
editor.on('init', function(args) {
if (typeof customInit == 'function') {
customInit();
}
});
}
}
});
},
clearMCE : function() {
try {
tinymce.remove();
} catch (e) {
}
},
// datepicker
setDatepicker : function() {
$('.timepicker, .datepicker').on('focus', function() {
$('.timepicker').timepicker('hideWidget');
});
$.datepicker.setDefaults($.extend($.datepicker.regional['ja']));
$('.datepicker').removeClass('hasDatepicker').datepicker({ showAnim:'slideDown', dateFormat:'yy-mm-dd' });
$('.timepicker').timepicker({ defaultTime:false, showMeridian:false, minuteStep:5});
$('.bootstrap-timepicker-widget').css('z-index', 99999);
$('.datepicker,.timepicker').attr('autocomplete', 'off');
},
//チェックボックスを一括操作する
setToggleCheckbox : function(options) {
var options = options || {};
var onSuccess = options.onSuccess ? options.onSuccess : false;
var isForce = options.isForce ? options.isForce : false;
var triggerClass = options.triggerClass ? options.triggerClass : '.x-checks';
$(triggerClass).css('cursor', 'pointer');
$(triggerClass).off().on('click', function(e) {
e.preventDefault();
if ($(this).attr('target_class')) {
$($(this).attr('target_class')).each(function() {
if (!$(this).attr('disabled') || isForce) {
$(this).prop('checked', !$(this).prop('checked'));
}
});
} else {
$(this).closest('table').find('input[type=checkbox]').each(function() {
if (!$(this).attr('disabled') || isForce) {
$(this).prop('checked', !$(this).prop('checked'));
}
});
}
if (onSuccess) {
onSuccess();
}
});
},
//チェックされているIDを配列で取得する
getCheckedIds : function(chkboxName) {
var ret = [];
$('input[name="'+chkboxName+'"]:checked').each(function() {
ret.push($(this).val());
});
return ret;
},
// 英数文字以外を全角数字から半角数字へ
convertNumeric:function(src) {
var src = src.replace(/\D/g,'');
return src.replace(/(\W)/g,
function ($0) {
return String.fromCharCode($0.charCodeAt(0) - 65248);
}
);
},
// コンテンツにソートライブラリのセット
setSort : function(options) {
var options = options || {};
var axis = options.axis ? options.axis : false;
var element = options.element ? options.element : '.x-sort';
var attributes = options.attributes ? options.attributes : 'sortable_ids';
var onSuccess = options.onSuccess ? options.onSuccess : false;
var handle = options.handle ? options.handle : false;
var placeholder = options.placeholder ? options.placeholder : 'ui-state-highlight';
var connectWith = options.connectWith ? options.connectWith : false;
var cancel = options.cancel ? options.cancel : 'input,textarea,button,select,option,audio,video';
var helper = options.helper ? options.helper : function(e, ui) {
ui.children().each(function() {
$(this).width($(this).width());
});
return ui;
};
$(element).each(function() {
$(this).sortable({
helper: helper,
axis: axis,
placeholder: placeholder,
connectWith: connectWith,
handle: handle,
cancel: cancel,
update: function(ev, ui){
if (onSuccess) {
onSuccess($(this).sortable('toArray', { attribute: attributes }));
} else {
var callback = eval($(this).attr('callback'));
if (callback) {
callback($(this).sortable('toArray', { attribute: attributes }));
}
}
}
}).disableSelection();
});
if (handle) {
$(handle).css('cursor', 'move');
} else {
$(element).css('cursor', 'move');
}
},
destroySort : function(options) {
var options = options || {};
var element = options.element ? options.element : 'x-sort';
try {
$(element).sortable('destroy').css('cursor', '');
} catch(e) {}
},
// ドラッグ&ドロップ
setDrag : function(options) {
var options = options || {};
var dragElement = options.dragElement ? options.dragElement : '.x-drag';
var dropElement = options.dropElement ? options.dropElement : '.x-drop';
var selectElement = options.selectElement ? options.selectElement : '.x-select';
var hiddens = options.hiddens ? options.hiddens : 'header,.btn,.panel';
var hoverClass = options.hoverClass ? options.hoverClass : 'drop-hover';
var onDropped = options.onDropped ? options.onDropped : false;
var helper = options.helper ? options.helper : 'clone';
$(dragElement).draggable({
helper: helper,
revert: true,
revertDuration: 0,
cursor: 'move',
opacity: 0.9,
start: function() {
if (hiddens) {
$(hiddens).each(function() {
if (!$(this).find(dropElement).length && !$(this).find(dragElement).length) {
$(this).animate({'opacity': 0.5}, 200);
}
});
}
},
stop: function() {
if (hiddens) {
$(hiddens).animate({'opacity': 1}, 200);
}
}
}).css('cursor', 'move');
$(dropElement).droppable({
hoverClass: hoverClass,
tolerance: 'pointer',
drop: function(event, ui) {
if (onDropped) {
onDropped(event, ui);
}
}
});
},
// ドロップ
setDrop : function(options) {
var options = options || {};
var dropElement = options.dropElement ? options.dropElement : '.x-drop';
var hoverClass = options.hoverClass ? options.hoverClass : 'drop-hover';
var onDropped = options.onDropped ? options.onDropped : false;
var helper = options.helper ? options.helper : 'clone';
$(dropElement).droppable({
hoverClass: hoverClass,
tolerance: 'pointer',
drop: function(event, ui) {
if (onDropped) {
onDropped(event, ui);
}
}
});
},
destroyDrag : function(options) {
var options = options || {};
var dragElement = options.dragElement ? options.dragElement : '.x-drag';
var dropElement = options.dropElement ? options.dropElement : '.x-drop';
try {
$(dragElement).draggable('destroy').css('cursor', '');
$(dropElement).droppable('destroy');
} catch(e) {}
},
// Googleマップを表示
googleMaps : [],
setMap : function(options)
{
var options = options || {};
var address = options.address ? options.address : '';
var map = options.map ? options.map : false;
var isImage = options.image ? options.image : false;
var onEmpty = options.onEmpty ? options.onEmpty : false;
var onError = options.onError ? options.onError : false;
var key = options.key ? options.key : '';
if (!address || !map) {
if (onEmpty) {
onEmpty();
}
return false;
}
map.children().remove();
if (!address.trim()) {
if (onEmpty) {
onEmpty();
}
return;
} else {
var geocoder = new google.maps.Geocoder();
var request = {address: address};
geocoder.geocode(request, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
for (var i in results) {
if (results[i].geometry) {
if (isImage) {
var latlng = results[i].geometry.location.lat() + ',' + results[i].geometry.location.lng();
} else {
var latlng = results[i].geometry.location;
}
if (isImage) {
var options = {
center: latlng,
maptype: google.maps.MapTypeId.ROADMAP,
zoom: 16,
size: '640x360',
format: 'png',
markers: latlng,
key: key
};
map.html($('
').attr('src', 'http://maps.google.com/maps/api/staticmap?' + $.param(options)));
} else {
var options = {
backgroundColor: '#ffffff',
center: latlng,
disableDoubleClickZoom: true,
navigationControl: true,
noClear: false,
scaleControl: true,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 16
};
var googleMap = new google.maps.Map(map[0], options);
var markerOptions = {
position : latlng,
map : googleMap
};
var marker = new google.maps.Marker(markerOptions);
}
map.width('100%').height(360);
}
}
} else {
switch (status) {
case google.maps.GeocoderStatus.ERROR:
case google.maps.GeocoderStatus.INVALID_REQUEST:
case google.maps.GeocoderStatus.OVER_QUERY_LIMIT:
case google.maps.GeocoderStatus.REQUEST_DENIED:
case google.maps.GeocoderStatus.UNKNOWN_ERROR:
case google.maps.GeocoderStatus.ZERO_RESULTS:
default:
// エラー
if (onError) {
onError();
}
break;
}
}
});
}
},
// 試験モード
toggleExam : function(isExam, src) {
if (!isExam || glexa.sessionStorage.getItem('exam_fullscreen')) {
this.exitExam(src);
return true;
} else {
if (isExam) {
this.startExam(src);
return true;
} else {
glexa.sessionStorage.removeItem('exam_fullscreen');
return false;
}
}
},
startExam : function(src) {
console.log('exam start');
glexa.sessionStorage.setItem('exam_fullscreen', true);
$('body').fullscreen();
if (src) {
$('body').html($('').attr('src', src).css('width', '100%').css('height', '100%').css('border', 'solid 20px #ccc'));
}
$(document).bind('fscreenchange', function(e, state, elem) {
if (!$.fullscreen.isFullScreen()) {
window.glexa._exitFullScreen(window.urlbase + 'class');
// window.sessionStorage.removeItem('exam_fullscreen')
// location.href = window.urlbase;
}
});
return true;
},
exitExam : function(src) {
console.log('exam exit');
// window.sessionStorage.removeItem('exam_fullscreen')
window.parent.glexa._exitFullScreen(src);
return true;
},
_exitFullScreen : function(src) {
console.log('exam close');
$(document).unbind('fscreenchange');
$.fullscreen.exit();
glexa.sessionStorage.removeItem('exam_fullscreen');
if (src) {
window.parent.location.href = src;
}
},
// Flash
putSWF : function(options, flashvars) {
var options = options || {};
var flashvars = flashvars;
var src = options.src ? options.src : false;
var params = options.params ? options.params : {
menu: "false",
scale: "exactFit",
allowFullscreen: "true",
allowScriptAccess: "always", // 必ずalways
bgcolor: "#000000",
wmode: "transparent"
}
var element = options.element ? options.element : false;
var attributes = options.attributes ? options.attributes : {};
var width = options.width ? options.width : 'auto';
var height = options.height ? options.height : 'auto';
if (!src || !element) {
return false;
}
swfobject.embedSWF(src, element, width, height, flashversion, 'expressInstall.swf', flashvars, params, attributes);
},
openWindow : function(src, w, h, name) {
if (w == undefined) {
w = 750;
}
if (h==undefined) {
h=500;
}
if (name==undefined) {
name='common window';
}
var win = window.open(src,name,'width='+w+',height='+h+',status=no,toolbar=no,scrollbars=yes,resizable=yes,location=no,menubar=no');
win.focus();
},
// 再生Flash読み込み(mode:プラグイン省略名,filename:音声ファイル名,element:エレメント)
putSoundSwf:function(filename,memberId,element,pitch,noneautoplay,w,h,fileUrl) {
if(w==undefined){
w = 136;
}
if(h==undefined){
h = 24;
}
var html, url;
/*
if (fileUrl != undefined){
url = 'common/bin/glexa_play.swf?filename=' + fileUrl + '%26'+this.getSerial() + (noneautoplay ? '&autoplay=false' : '');
}else{
url = 'common/bin/glexa_play.swf?filename=glexa_play.php%3Ff='+filename+'%26m='+memberId+'%26'+this.getSerial() + (noneautoplay ? '&autoplay=false' : '');
}
html = '';
if (this.get(element)) {
this.get(element).innerHTML = html;
}
*/
var autoplay = 'autoplay';
if (noneautoplay) {
autoplay = '';
}
$('#' + element).html('');
if (pitch) {
this.putPitchLink(filename,memberId,element);
}
},
// 再生Flash読み込み(mode:プラグイン省略名,filename:音声ファイル名,element:エレメント)
putPitchLink:function(filename, memberId, element) {
/*
html = '
';
if (this.get(element)) {
this.get(element).innerHTML += html;
}
*/
},
putSwfPlayer:function(filename, memberId, questionInstanceId, element, isAutoPlay, preWord, pitch) {
if (isAutoPlay == undefined) {
isAutoPlay = true;
}
if (preWord == undefined) {
preWord = '';
}
this.putSoundSwf(filename, memberId, element, undefined, isAutoPlay, 198, 24);
$('#' + element).html(preWord + $('#' + element).html());
if (pitch) {
this.putPitchLink(filename,memberId,element);
}
},
/* FUNCTIONS */
// メール送信者をセットする
// glexa_ajax_mail_member_list
// teacher_ajax_mail_member_list
setMailMember:function(memberId, number, name) {
if (this.members) {
for (var i=0; i ul').tabs();
});
},
//時間割のスクロール
timetableChange:function() {
$(document).ready(function() {
if ($('#mycarousel').size() > 0 && $.fn.jcarousel){
$('#mycarousel').jcarousel();
}
});
},
resizeWindow:function()
{
if (this.examWindow) {
/*
try {
if (this.examWindow.initTesting) {
this.examWindow.initTesting();
}
} catch(e) {}
*/
try {
this.examWindow.moveTo(0, 0);
this.examWindow.resizeTo(window.screen.availWidth, window.screen.availHeight);
} catch(e) {}
setTimeout(this.resizeWindow.bind(this), 500);
}
},
setAudioObject:function( audioSpanTagId, url ) {
// iOS関連のブラウザは、一つのaudioタグオブジェクトに対して、一つの音声ストリームしか再生できない為、
// audioタグオブジェクトを再作成してストリームを読み直し、何度も再生可能にする。
$objAudio =
$("")
.attr("controls", " ")
.attr("preload", 'metadata')
.attr("src", url)
.bind(
"ended",
function() {
recording.setAudioObject(audioSpanTagId, url);
}
);
$("#" + audioSpanTagId + " audio").remove();
$("#" + audioSpanTagId).append($objAudio);
},
enterKeySubmit:function() {
$(document).ready(function() {
$('.x-enter').on('keypress', function(e) {
if (e.which == 13) {
$(this).nextAll('button').click();
return false;
}
});
});
},
replaceOldImages : function() {
$('img').each(function(i, v) {
var src = $(this).attr('src');
if (src.indexOf('images') == 0) {
$(this).attr('src', '/common/obsolute/' + src);
}
});
},
//WebStorageが有効かどうかを判別
storageAvailable : function(type) {
try {
var storage = window[type],
x = '__ZSL32fRHrJ__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
}
catch(e) {
return e instanceof DOMException && (
// everything except Firefox
e.code === 22 ||
// Firefox
e.code === 1014 ||
// test name field too, because code might not be present
// everything except Firefox
e.name === 'QuotaExceededError' ||
// Firefox
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
// acknowledge QuotaExceededError only if there's something already stored
storage.length !== 0;
}
},
localStorage : {
getItem : function(keyname){
if(glexa.storageAvailable('localStorage')){
return localStorage.getItem(keyname);
}else{
return '';
}
},
setItem : function(keyname, keyvalue){
if(glexa.storageAvailable('localStorage')){
localStorage.setItem(keyname,keyvalue);
}
},
removeItem : function(keyname){
if(glexa.storageAvailable('localStorage')){
localStorage.removeItem(keyname);
}
},
key : function(key){
if(glexa.storageAvailable('localStorage')){
return localStorage.key(key);
}else{
return '';
}
},
clear : function(){
if(glexa.storageAvailable('localStorage')){
localStorage.clear();
}
}
},
sessionStorage : {
getItem : function(keyname){
if(glexa.storageAvailable('sessionStorage')){
return sessionStorage.getItem(keyname);
}else{
return '';
}
},
setItem : function(keyname, keyvalue){
if(glexa.storageAvailable('sessionStorage')){
sessionStorage.setItem(keyname,keyvalue);
}
},
removeItem : function(keyname){
if(glexa.storageAvailable('sessionStorage')){
sessionStorage.removeItem(keyname);
}
},
key : function(key){
if(glexa.storageAvailable('sessionStorage')){
return sessionStorage.key(key);
}else{
return '';
}
},
clear : function(){
if(glexa.storageAvailable('sessionStorage')){
sessionStorage.clear();
}
}
},
makeHash : function() {
var l = 8;
var c = "abcdefghijklmnopqrstuvwxyz0123456789";
var cl = c.length;
var r = "";
for (var i=0; iログイン画面より再度ログインしてください。
code : ' + error,
keyboard: false,
btnOkName: 'ログイン画面へ',
onOk: function(){
location.href = topurl;
},
});
glexa.isTimeout = 1;
}
return true;
}
} catch (e) {
}
return false;
// if (!glexa.isTimeout) {
// glexa.openCommonAlertModal({
// body: '長時間操作が行われなかったため、ログアウトされました。
ログイン画面より再度ログインしてください。
code : ' + code,
// keyboard: false,
// btnOkName: 'ログイン画面へ',
// onOk: function(){
// location.href = topurl;
// },
// });
// }
// glexa.isTimeout = 1;
},
};
$.fn.isVisible = function() {
return $.expr.filters.visible(this[0]);
};