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
 
(129 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 orBox = "<div class='query'> <input type='text' class='queryString' /> </div><br />";
        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>";
var andBox = " <input type='text' class='queryString' /> ";
        $("#examSpace").append(stuffs);
$("#formSpace").html(orBox);
var orBox = "<div class='query'> <input type='text' class='queryString' /> </div><br />";
$(".queryString").focus(function(){$(".focused").removeClass( "focused" );$( this ).parent().addClass( "focused" ); $(".queryString").focusout(function(){if($(this).val().length <= 1){$(this).remove();}});});
var andBox = " <input type='text' class='queryString' /> ";
$("#formSpace").html(orBox);
$(".queryString").focusin(function () {
$(".focused").removeClass("focused");
$(this).parent().addClass("focused");
$(".queryString").focusout(function () {
if ($(this).val().length <= 1) {
$(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 () {
$("#formSpace").append(orBox);
$(".queryString").focus(function () {
$(".focused").removeClass("focused");
$(this).parent().addClass("focused");
$(".queryString").focusout(function () {
if ($(this).val().length <= 1) {
$(this).remove();
}
clearEmptyDivs();
});
});
});


$("#andOp").click(function () {
var andBox = "<input type='text' class='queryString' />";
$(".focused").append(andBox);
$(".queryString").focus(function () {
$(".focused").removeClass("focused");
$(this).parent().addClass("focused");
$(".queryString").focusout(function () {
if ($(this).val().length <= 1) {
$(this).remove();
}
clearEmptyDivs();
});
});
});


$("#orOp").click(function(){
$("#showQueries").click({}, showQueries);
$("#formSpace").append(orBox);
function showQueries(event) {
$(".queryString").focus(function(){$(".focused").removeClass( "focused" );$( this ).parent().addClass( "focused" ); $(".queryString").focusout(function(){if($(this).val().length <= 1){$(this).remove();}});});
                event.data.queries = [];
});
                event.data.questionListAll = [];
                event.data.keyword = {};
                event.data.keyword.iterator = 0;
$.each($(".query"),function (index, value) {
                                event.data.queries[index] = "";
$.each($(this).children(), function(ind, val){
                                    event.data.queries[index] += "[[WBRKeyword::" + $(this).val() + "]]";
                                });
});
                                runQueries(event.data);
}
function runQueries(obj) {
var api = new mw.Api();
api.get({
action : 'ask',
query : obj.queries[obj.keyword.iterator],
format : 'json'
})
.always(function (data) {
        $.each(data.query.results, function(index, value){
              obj.questionListAll.push(value.fulltext);
        });
if ((obj.keyword.iterator+1) < obj.queries.length) {
        obj.keyword.iterator++;
        runQueries(obj);       
} else {
        removeDuplicates(obj);
        }
});
}
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);
}
}


$("#andOp").click(function(){
</script>
var andBox = "<input type='text' class='queryString' />";
<div id="examSpace"></div>
$(".focused").append(andBox);
$(".queryString").focus(function(){$(".focused").removeClass( "focused" );$( this ).parent().addClass( "focused" ); $(".queryString").focusout(function(){if($(this).val().length <= 1){$(this).remove();}});});
});


$("#showQueries").click(function(){
  var testArr = new Array();
  var testVar = $.each($(".query"), function(index, value){
        testArr[index] = "";
        testArr[index] += $.each($(this).children(), function(ind, val){
              alert($(this).val());
              return $(this).val();
        });
  });
    console.log(testVar);
        return testArr;
});
});
</script>
<form>
<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