2016-07-17 20 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

変更あなたの2つの機能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

でそれは

+0

ありがとう、私はそれをやった作品の場合はページ

<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

解決策は '@'がテキストの最後にある場合にのみ機能します。正しい? – Ankit

関連する問題