2016-07-17 5 views
1

내 프로젝트에서 jquery.mentionsInput을 사용하고 있습니다. 플러그인이 데스크톱에서는 정상적으로 작동하지만 모바일에서는 작동하지 않습니다. 이것은 내 코드입니다. 경고()는 기능이 작동하는지 검사하는 것입니다. jquery.mentionsInput이 모바일에서 작동하지 않습니다.

$('textarea.mention').mentionsInput({ 

    onDataRequest:function (mode, query, callback) { 
     alert("To test on mobile"); 
     searchVal = query; 

     $.ajax({ 
     type: "GET", 
     dataType: "json", 
     url: rootPath()+"user/tagFriends/"+searchVal, 

     success: function(data){ 
      data = _.filter(data, function(item) { return item.name.toLowerCase().indexOf(query.toLowerCase()) > - 1 }); 
      callback.call(this, data); 
     } 

     }); 


    } 
    }); 

플러그인 link입니다. 플러그인은 모바일에서도 작동하지 않습니다. 미리 감사드립니다. 내 하찮은 영어 실력에 죄송하다는 말씀을 드리고 싶습니다. 파일의 jquery.mentionsInput.js에서

답변

0

수정하여이 개 기능 onInputBoxInput()와 onInputBoxKeyPress()의 하단에 코드를 추가이

function onInputBoxInput(e) { 
var ua = navigator.userAgent.toLowerCase(); 
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile"); 
if(isAndroid) {//certain versions of android mobile browser don't trigger   the keypress event. 
if(e.keyCode !== KEY.BACKSPACE) { 
var typedValue = String.fromCharCode(e.which || e.keyCode); //Takes the string that represent this CharCode 
inputBuffer.push(typedValue); //Push the value pressed into inputBuffer 
} 
    } 
updateValues(); 
updateMentionsCollection(); 

var triggerCharIndex = _.lastIndexOf(inputBuffer, settings.triggerChar); //Returns the last match of the triggerChar in the inputBuffer 
if (triggerCharIndex > -1) { //If the triggerChar is present in the inputBuffer array 
    currentDataQuery = inputBuffer.slice(triggerCharIndex + 1).join(''); //Gets the currentDataQuery 
    currentDataQuery = utils.rtrim(currentDataQuery); //Deletes the whitespaces 
    _.defer(_.bind(doSearch, this, currentDataQuery)); //Invoking the function doSearch (Bind the function to this) 
} 
} 

//Takes the keypress event 
function onInputBoxKeyPress(e) { 
var ua = navigator.userAgent.toLowerCase(); 
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile"); 
if(!isAndroid) { 
    if(e.keyCode !== KEY.BACKSPACE) { //If the key pressed is not the backspace 
     var typedValue = String.fromCharCode(e.which || e.keyCode); //Takes the string that represent this CharCode 
     inputBuffer.push(typedValue); //Push the value pressed into inputBuffer 
    } 
} 
} 

같은 당신의 index.html을

에서 그 일을의 경우 페이지가

<script> 


var sendBoxElem = $('textarea.mention'); 
sendBoxElem.bind("input", function(e) { 
var ua = navigator.userAgent.toLowerCase(); 
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile"); 
if(isAndroid) { 
var char = this.value.charCodeAt(this.value.length - 1); 
//$scope.data = char; 
if(e.keyCode === undefined){ 
e.keyCode = char; 
} 
return true; 
} 
}); 

</script> 

저를 알려 주시기 바랍니다

+0

당신을 감사합니다,하지만 난 그것을했다 이미 다른 프로젝트를 위해 바쁘다. 나중에 사용한다면 –

+0

해결책은'@'가 텍스트의 끝에있을 때만 작동합니다. 옳은? – Ankit

관련 문제