2016-07-17 10 views
1

Ich benutze jquery.entionsInput in meinem Projekt. Das Plugin funktioniert gut auf dem Desktop, funktioniert aber nicht auf dem Handy. Das ist mein Code. Der alert() soll testen, ob die Funktion funktioniert oder nicht.jquery.entionsInput funktioniert nicht auf Handy

$('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); 
     } 

     }); 


    } 
    }); 

Dies ist das Plugin link. Das Plugin funktioniert auch nicht auf Mobilgeräten. Vielen Dank im Voraus. Entschuldigung für mein schlechtes Englisch.

Antwort

0

In Ihrer Datei jquery.mentionsInput.js Sie ändern Ihre 2 Funktionen onInputBoxInput() und onInputBoxKeyPress() wie dieses

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 
    } 
} 
} 

und in Ihrer index.html

fügen Sie diesen Code am unteren Rand des die Seite

<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> 

Bitte informieren Sie mich, wenn diese Arbeit ist

+0

danke, aber ich habe es schon und ich bin jetzt beschäftigt für ein anderes Projekt. Wenn ich es in Zukunft benutze, informiere ich Sie –

+0

die Lösung funktioniert nur, wenn das '@' am Ende des Textes ist. richtig? – Ankit