Project

General

Profile

1
var imgUrl = "static-content/images/icons/search_minus.png";
2
var index = 0;
3

    
4
//var cursordId = "input[" + 0 +"]";
5
var cursordId = "";
6

    
7
function hide( id ){
8
    var mySlide = new Fx.Slide( id , {
9
        duration: 'long',
10
        transition: Fx.Transitions.Bounce.easeOut
11
    });
12
    mySlide.hide();
13
}
14

    
15
function slideOut( id ){
16
    var mySlide = new Fx.Slide( id );
17
    mySlide.slideOut();
18
}
19

    
20
function slideIn( id ){
21
    var mySlide = new Fx.Slide( id );
22
    mySlide.slideIn();
23
}
24

    
25
function getTarget( id ) {
26
    var k = 0;
27
    for ( var i = 0; i < id.length; i++ ){
28
        if( id.charAt( i ) == '[' ) {
29
            k = i;
30
            break;
31
        }
32
    }
33
    var newId = id.substring( k+1, id.length - 1  ) ;
34
    return newId;
35
}
36

    
37

    
38
function clicked( e ){
39
    //alert( "other exploder" );
40
    var targetId = getTarget( e.target.id );
41
    var newId = "input[" + targetId +"]";
42
    if ( cursordId == newId  )
43
        return;
44
    slideIn( newId );
45
    var temp = cursordId;
46
    cursordId = newId;
47
//alert( "other exploder exit" );
48
}
49

    
50
function ie_clicked(){
51
    //alert( "internet exploder" );
52
    var id = event.srcElement.id;
53
    var targetId = getTarget( id );
54
    var newId = "input[" + targetId +"]";
55
    if ( cursordId == newId  )
56
        return;
57
    slideIn( newId );
58
    var temp = cursordId;
59
    cursordId = newId;
60
//alert( "internet exploder exit" );
61
//slideOut( temp );
62
}
63

    
64

    
65
function initEvent( id ){
66
    var initVar = document.getElementById( "keyword[" +id +"]" );
67

    
68
    if (  initVar.addEventListener ){
69
        initVar.addEventListener( 'click', clicked , false );;
70
        var fields = document.getElementById( "input[" + id + "]" );
71
        hide( fields );
72
    } else {
73
    	//var inputContent = initVar.cloneNode(false);
74
        initVar.attachEvent( 'onclick', ie_clicked );
75
        var fields = document.getElementById( "input["+ id + "]" );
76
        slideOut( fields );
77
    }
78
}
79

    
80
function closeAdvanceOptions( id ){
81
    //alert( " test " +id );
82
    slideOut( id );
83
    cursordId = "";
84
}
85

    
86

    
87
function addNewInput(){
88
    var initVar = document.getElementById( "keyword[" +0 +"]" );
89
    var fields = document.getElementById( "input[0]" );
90
    var br1 = document.createElement( "br" );
91
    var br2 = document.createElement( "br" );
92
    var inputContent = initVar.cloneNode( false );
93
    var newfields = document.createElement( "div" );
94
    newfields.innerHTML = fields.innerHTML;
95
    var removeButton =  document.createElement( "i" );
96
    removeButton.innerHTML = " <a name = 'removeBtn' id='remove[" + index + "]' href='javascript:removeInput(" + index + ");'><img src='" + imgUrl + "' alt='remove criteria' align='absbottom' border='0' height='15' width='15'></a>";
97
    br1.id = "br1_" + index;
98
    br2.id = "br2_" + index;
99
    inputContent.id = "keyword[" + index +"]";
100
    newfields.id = "input[" + index +"]";
101
    var nlist = newfields.childNodes;
102
    for( i = 0; i < nlist.length; i++ ) {
103
        var link = nlist.item(i);
104
        if( link.id == "fields[0]" ) {
105
            link.selectedIndex = 0;
106
        }
107
    }
108

    
109
    document.body.appendChild( inputContent );
110

    
111
    if (  inputContent.addEventListener ){        
112
        inputContent.addEventListener( 'click', clicked , false );;
113
    } else {
114
        inputContent.attachEvent( 'onclick', ie_clicked );   
115
    }
116

    
117
    link =newfields.getElementsByTagName( "a" );
118
    link[0].href = "javascript:closeAdvanceOptions( 'input[" + index + "]' )";
119
    var addButton = document.getElementById( "callAdd" );
120
    var x = document.getElementById( "stop" );
121
    x.parentNode.insertBefore( inputContent, x );
122
    x.parentNode.insertBefore( removeButton, x );
123
    x.parentNode.insertBefore( addButton, x );
124
    x.parentNode.insertBefore( br1, x );
125
    x.parentNode.insertBefore( newfields, x );
126
    x.parentNode.insertBefore( br2, x );
127
    inputContent.value = "";
128
    hide( newfields );
129
    new Autocompleter.Request.JSON('keyword[' + index + ']', '/uoa-web-generic-latest/Recommender.action', {
130
            'postVar': 'keyword'
131
        });
132
    index++;
133
}
134

    
135
function removeInput( cursor ){
136
    var initVar = document.getElementById("keyword[" + cursor +"]" );
137
    var fields = document.getElementById( "input[" + cursor +"]" );
138
    var br1 =  document.getElementById("br1_" + cursor + "" );
139
    var br2 =  document.getElementById("br2_" + cursor + "" );
140
    var removeButton =  document.getElementById("remove[" + cursor + "]" );
141
    slideOut( initVar.id  );
142
    slideOut( br1.id  );
143
    slideOut( br2.id  );
144
    slideOut( removeButton.id  );
145
    slideOut( fields.id  );
146
    initVar.parentNode.removeChild( initVar );
147
    fields.parentNode.removeChild( fields );
148
    br1.parentNode.removeChild( br1 );
149
    br2.parentNode.removeChild( br2 );
150
    removeButton.parentNode.removeChild( removeButton );
151
    var removeBtns = document.getElementsByName( "removeBtn" );
152
    var nextPos = removeBtns.length;
153
    if(  nextPos == 0 ) {
154
        //alert( "0.1" );
155
        var addButton = document.getElementById( "callAdd" );
156
        //alert( "0.2" );
157
        var x = document.getElementById( "firstBr"  );
158
        //alert( "0.3" );
159
        x.parentNode.insertBefore( addButton, x );
160
    //alert( "0.4" );
161
    }  else {
162
        if(  cursor + 1  == index ) {
163
            index--;
164
        }
165
        var brns = document.getElementsByName( "removeBtn" );
166
        var addButton = document.getElementById( "callAdd" );
167
        var br = brns[ brns.length - 1 ];
168
        br.parentNode.insertBefore( addButton, br );
169
        addButton.parentNode.insertBefore( br, addButton );
170
    }
171
//alert( "6" );
172
}
173

    
174
function moveAddButton(){
175
    //var addButton = document.getElementById( "callAdd" );
176
    //var x = document.getElementById( "stop" );
177
    //x.parentNode.insertBefore( addButton, x );
178
    var removeBtns = document.getElementsByName( "removeBtn" );
179
    var nextPos = removeBtns.length;
180
    if(  nextPos == 0 ) {
181
        var addButton = document.getElementById( "callAdd" );
182
        var x = document.getElementById( "firstBr"  );
183
        x.parentNode.insertBefore( addButton, x );
184
    }  else {
185
        var brns = document.getElementsByName( "removeBtn" );
186
        var addButton = document.getElementById( "callAdd" );
187
        var br = brns[ brns.length - 1 ];
188
        br.parentNode.insertBefore( addButton, br );
189
        addButton.parentNode.insertBefore( br, addButton );
190
    }
191
}
(18-18/20)