-
Notifications
You must be signed in to change notification settings - Fork 0
/
embeded-script.js
57 lines (51 loc) · 1.71 KB
/
embeded-script.js
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
setTimeout(function(){
var users = $("[name=notifiedUserIds]").eq(0).find("option"),
handler="<p class='label'><a href='#' style='font-weight:normal' data-js-toggle>AddUser+</a></p>",
html="<ul data-js-toggleTarget style='display:none;max-height:200px;overflow:auto'>";
users.each(function(){
html+="<li class='search-choice' style='width:33%;float:left;'><label><input type='checkbox' data-js-setUser='"+$(this).text()+"'><img src='"+$(this).attr("icon")+"' class='chosen-icon'>"+$(this).text()+"</label></li>";
});
html+="</ul>"
$(document).on("change","[data-js-setUser]",function(){
setSelect($(this).attr("data-js-setUser"),$(this).prop('checked'));
}).on("click","[data-js-toggle]",function(){
$("[data-js-toggleTarget]").slideToggle();
return false;
}).on("change","[name=notifiedUserIds]:eq(0)",function(){
console.log("changeUSer");
setRadio();
});
$("#editArea").before(handler);
$("#notifiedUsersLeft").prepend(html)
var setRadioTimer;
function setRadio(user,state){
if(setRadioTimer)clearTimeout(setRadioTimer);
setRadioTimer = setTimeout(function(){
users.each(function(){
$("[data-js-setUser='"+$(this).text()+"']").prop('checked',$(this).prop('selected'));
});
},1000);
}
function setSelect(user,state){
console.log("setSelect",user,state)
var userList =[];
users.each(function(){
if($(this).text() === user){
$(this).prop('selected',state).change();
}
if($(this).prop('selected')){
userList.push($(this).text());
}
});
localStorage.setItem("userList",JSON.stringify(userList));
}
function init(){
var userList = JSON.parse(localStorage.getItem("userList"));
for(var i=0;i<userList.length;i++){
setSelect(userList[i],true);
}
}
if($("#leftCommentContent").val()==""){
init();
}
},3000);