Widget:KeywordSearch: Difference between revisions

Jump to navigation Jump to search
Matt Pijoan (talk | contribs)
No edit summary
Matt Pijoan (talk | contribs)
No edit summary
 
(78 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>
<includeonly>
<style type="text/css">
.WBRButton{
font-family:Arial;
float:left;
background-color:#3366CC;
height:40px;
font-weight:bold;
width:150px;
display: table-cell;
cursor: pointer;
color:#FFFFFF;
text-align: center;
vertical-align: middle;
margin-right:10px;
}
</style>
<script type="text/javascript">
<script type="text/javascript">
$(document).ready(function(){CoK();});


$(document).ready(function () {
function CoK() {
        var stuffs ="<div id='formSpace'></div><div class='WBRButton' id='orOp'><br />OR</div><div class='WBRButton' id='andOp'><br />AND</div><div class='WBRButton' id='showQueries'><br />SHOW</div>";
        $("#examSpace").append(stuffs);
var orBox = "<div class='query'> <input type='text' class='queryString' /> </div><br />";
var orBox = "<div class='query'> <input type='text' class='queryString' /> </div><br />";
var andBox = " <input type='text' class='queryString' /> ";
var andBox = " <input type='text' class='queryString' /> ";
$("#formSpace").html(orBox);
$("#formSpace").html(orBox);
$(".queryString").focus(function () {
$(".queryString").focusin(function () {
$(".focused").removeClass("focused");
$(".focused").removeClass("focused");
$(this).parent().addClass("focused");
$(this).parent().addClass("focused");
Line 13: Line 33:
$(this).remove();
$(this).remove();
}
}
                        clearEmptyDivs();
});
});
});
});
 
function clearEmptyDivs(){
$.each($(":br"), function(){
console.log($(this).parent());
}
$.each($(".query"), function(){
if($(this).children().length === 0){
$(this).remove();
}
});
}
$("#orOp").click(function () {
$("#orOp").click(function () {
$("#formSpace").append(orBox);
$("#formSpace").append(orBox);
Line 25: Line 55:
$(this).remove();
$(this).remove();
}
}
clearEmptyDivs();
});
});
});
});
Line 39: Line 70:
$(this).remove();
$(this).remove();
}
}
clearEmptyDivs();
});
});
});
});
Line 45: Line 77:
$("#showQueries").click({}, showQueries);
$("#showQueries").click({}, showQueries);
function showQueries(event) {
function showQueries(event) {
event.data.testVar = [];
                 event.data.queries = [];
                 event.data.queries = [];
                 event.data.returned = [];
                 event.data.questionListAll = [];
                event.data.keyword = {};
                 event.data.keyword.iterator = 0;
                 event.data.keyword.iterator = 0;
event.data.testVar = $(".query").map(function () {
$.each($(".query"),function (index, value) {
return getStrings($(this).children());
                                event.data.queries[index] = "";
$.each($(this).children(), function(ind, val){
                                    event.data.queries[index] += "[[WBRKeyword::" + $(this).val() + "]]";
                                });
});
});
for (var i = 0; i < event.data.testVar.length; i++) {
                                 runQueries(event.data);
event.data.testVar2 = $.makeArray(event.data.testVar[i]);
                        event.data.queries[i] = "";
for (var j = 0; j < event.data.testVar[i].length; j++) {
event.data.queries[i] += "[[WBRKeyword::" + $(event.data.testVar2[j]).val() + "]]";
}
}
                                 console.log(event.data.queries);
}
}
function getStrings(obj) {
function runQueries(obj) {
var outArr = [];
var api = new mw.Api();
outArr[outArr.length] = $.each(obj, function (ind, tal) {
api.get({
var string = $(this).val();
action : 'ask',
return string;
query : obj.queries[obj.keyword.iterator],
});
format : 'json'
return outArr;
})
}
.always(function (data) {
        function runQueries(event){
        $.each(data.query.results, function(index, value){
        if(event.data.queries[event.data.keyword.iterator] <= event.data.queries.length){
              obj.questionListAll.push(value.fulltext);
        var api = new mw.Api();
        });
api.get({
if ((obj.keyword.iterator+1) < obj.queries.length) {
action : 'ask',
        obj.keyword.iterator++;
query : event.data.queries[event.data.queries[event.data.keyword.iterator],
         runQueries(obj);       
format : 'json'
} else {
})
        removeDuplicates(obj);
.done(function (data) {
console.log('API result:', data);
});
         else {
 
         }
         }
});
}
function removeDuplicates(obj){
        for(var i=0;i<obj.questionListAll.length;i++){
              $.each(obj.questionListAll, function(index, value){
                  if(obj.questionListAll[i] === value && i != index){
                    console.log(value);
                    console.log(obj.questionListAll[i]);
                    obj.questionListAll.splice(index, 1);
                    return false;
                  }
              });
         }
         }
});
console.log(obj.questionListAll);
}
}


</script>
</script>
<form>
<div id="examSpace"></div>
<div id="formSpace"></div>
 
<input type='button' id='orOp' value='OR' />
<input type='button' id='andOp' value='AND' />
<input type='button' id='showQueries' value='SHOW' />
</form>
</includeonly>
</includeonly>

Latest revision as of 15:59, 23 October 2013