-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
162 lines (150 loc) · 5.69 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<head>
<style>
#status {
padding:4px;
width:300px;
height:100px;
clear:both;
border:1px solid #00BFFF;
}
.tag{
background-color:#00BFFF;
background: #dce6f8; /* Old browsers */
background: -moz-linear-gradient(top, #dce6f8 0%, #bdcff1 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#dce6f8), color-stop(100%,#bdcff1)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #dce6f8 0%,#bdcff1 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #dce6f8 0%,#bdcff1 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #dce6f8 0%,#bdcff1 100%); /* IE10+ */
background: linear-gradient(to bottom, #dce6f8 0%,#bdcff1 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#dce6f8', endColorstr='#bdcff1',GradientType=0 ); /* IE6-9 */
padding:1px 5px;
border-radius:2px;
margin-top:2px;
color: black;
text-decoration: none;
}
.suggest_name{
width:300px;
height:30px;
}
#suggest{
border:1px solid black;
width:300px;
top:115px;
position:absolute;
z-index:100;
}
#post_status{
position:relative;
}
</style>
<script src="jquery-1.10.2.min.js" type="text/javascript" /></script>
<title>
Facebook Mentions
</title>
</head>
<body>
<div id="content">
<div name="status" id="status"></div>
<button id="post_status">Post</button>
</div>
<script>
// Config
var status = "#status"; //Div tag that you are targeting
var tag_class = "tag"; //CSS Class for the tagged elemnts inside div
var profile_link = "http://127.0.0.1/user/"; // The ID from the database will be appended to this URL for tagged users
var ping_url = "mention_post.php"; //URL from where the db results are returned .
var suggest = "#suggest";
//plugin Start
function placeCaretAtEnd(el) {
el.focus();
if (typeof window.getSelection != "undefined"
&& typeof document.createRange != "undefined") {
var range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (typeof document.body.createTextRange != "undefined") {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(false);
textRange.select();
}
}
$(status).prop('contentEditable',true);
$(".name").css("width",$(status).width());
var prev_matches;
var current_match;
$(document).on("mouseover",".suggest_name",function(){
$(".suggest_name").css("background-color","#FFF");
$(this).css("background-color","#00BFFF");
});
$(document).on( "click","#suggest > div", function() {
var text = $(status).html();
var tagged = "<a href='"+profile_link+$(this).attr('data')+"' class='"+tag_class+"'>"+$(this).html()+"</a> ";
var rep = text.replace(current_match,tagged);
$(status).html(rep);
placeCaretAtEnd($("#status").get(0));
$(suggest).remove();
console.log($(status).html());
});
$(status).keydown(function(e){
if(e.keyCode == 32 || e.keyCode == 27){ //space
$(suggest).remove();
}
if($(suggest).is(":visible"))
{
if(e.keyCode == 38) //up arrow
{
e.preventDefault();
$(".suggest_name").each(function(){
if($(this).css("background-color")!="rgb(255,255,255)")
{
$(this).css("background-color","rgb(255, 255, 255)");
$(this).prev().css("background-color","rgb(0, 191, 255)");
}
});
}
if(e.keyCode == 40) //down arrow
{
}
}
});
$( status ).keyup(function(e) {
var text = $(this).html();
var matches = text.match(/@[a-zA-Z1-9]*/g);
for(var match in matches) {
if(prev_matches != null){
if($.inArray(matches[match],prev_matches) == -1){
current_match = matches[match];
console.log(matches[match]);
$(suggest).remove();
$(status).after('<div id="suggest"></div>');
$.ajax({
url: ping_url,
type: 'POST',
cache: false,
data : {name:matches[match]},
timeout: 30000,
error: function(){
return true;
},
success: function(data){
console.log(data);
var arr = $.parseJSON(data);
$.each(arr, function (index, value) {
$(suggest).append("<div class='suggest_name' data='"+index+"' >"+value+"</div>");
});
$('.suggest_name').first().css("background-color","#00BFFF");
}
});
}
}
}
prev_matches = matches;
//console.log(text);
});
</script>
</body>