Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Merge branch yobi-702 of laziel/yobi
Browse files Browse the repository at this point in the history
from pull request 584
  • Loading branch information
laziel committed Feb 13, 2014
2 parents 9972fc6 + 4ec6246 commit c10eb09
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
42 changes: 41 additions & 1 deletion public/javascripts/common/yobi.Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,45 @@ $yobi = yobi.Common = (function(){
return htVar.welHSC.text(sHTML).html();
}

/**
* Get whether the file is image with MIME type, and filename extension.
* returns boolean or null if unavailable to determine result
*
* @param {Variant} vFile File object or HTMLElement
* @returns {Boolean|Null}
*/
function isImageFile(vFile){
// if vFile is File Object
if(typeof window.File !== "undefined" && vFile instanceof window.File){
return (vFile.type.indexOf("image/") !== 0);
}

// if vFile is HTMLElement
var welFile = $(vFile);
var oFileList = welFile.prop("files");

if(oFileList && oFileList.length){
var bResult = true;

for(var i = 0, nLength = oFileList.length; i < nLength; i++){
bResult = bResult && isImageFile(oFileList[i]);
}

return bResult;
}

// if cannot find MIME type from File object
// get whether filename ends with extension looks like image file
// like as .gif, .bmp, .jpg, .jpeg, .png.
if(typeof welFile.val() === "string"){
htVar.rxImgExts = htVar.rxImgExts || /\.(gif|bmp|jpg|jpeg|png)$/i;
return htVar.rxImgExts.test(welFile.val());
}

// Unavailable to detect mimeType
return null;
}

/* public Interface */
return {
"setScriptPath" : setScriptPath,
Expand All @@ -330,7 +369,8 @@ $yobi = yobi.Common = (function(){
"notify" : notify,
"nl2br" : nl2br,
"tmpl" : processTpl,
"htmlspecialchars": htmlspecialchars
"htmlspecialchars": htmlspecialchars,
"isImageFile": isImageFile
};
})();

4 changes: 1 addition & 3 deletions public/javascripts/service/yobi.project.Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* 정규식 변수는 한번만 선언하는게 성능 향상에 도움이 됩니다
*/
function _initVar(htOptions){
htVar.rxLogoExt = /\.(gif|bmp|jpg|jpeg|png)$/i;
htVar.rxPrjName = /^[0-9A-Za-z-_\.]+$/;
htVar.aReservedWords = [".", "..", ".git"];
}
Expand Down Expand Up @@ -80,8 +79,7 @@
function _onChangeLogoPath(){
var welTarget = $(this);

// 확장자 규칙 검사
if(!htVar.rxLogoExt.test(welTarget.val())){
if($yobi.isImageFile(welTarget) === false){
$yobi.showAlert(Messages("project.logo.alert"));
welTarget.val('');
return;
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/service/yobi.user.Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
* @return {Boolean}
*/
function _onAvatarBeforeUpload(htData){
if(htData.oFile && htData.oFile.type.indexOf("image/") !== 0){
if($yobi.isImageFile(htData.oFile) === false){
_onAvatarUploadError(Messages("user.avatar.onlyImage"));
return false;
}
Expand Down

0 comments on commit c10eb09

Please sign in to comment.