1.0.37 • Published 7 years ago

coveomagicbox v1.0.37

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
7 years ago

Magic Box

Build Status

A search box on steroid

Preview

Magic Box allows to create a search box designed to show auto completions based on a grammar.

It works by first declaring a grammar, then specifying a function to provide suggestions.

It will display shadow text as well as allow to navigate using keyboard

Preview

Initialization

See demo.html for examples

// The magic box must be initialized on a div, not directly on an input. This is for styling purpose (shadow text)
var divToInitializeOn = document.getElementById('myMagicBox');

// Use an existing grammar, or build your own.
var grammarToUse = Coveo.MagicBox.Grammars.Basic;

// provide options
var options = {
    suggestionTimeout: 500
}

var magicbox = new Coveo.MagicBox.create(divToInitializeOn, grammarToUse, options);

###Possible options

  • inline: boolean; Specify if the suggestions should push the content of the page downward, or if the suggestions should appear over the content of the page Default to false
  • selectableSuggestionClass: string; Specify the css class that should be generated for suggestion that can be selected. Default is magic-box-suggestion
  • selectedSuggestionClass: string; Specify the css class that should be generated for a suggestion that is currently selected. Default is magic-box-selected
  • suggestionTimeout?: number; Specify the timer before a suggestions is rejected for taking too long. Default is 500 (ms)

##Provide suggestions See demo.html for examples

// You simply need to provide a function on getSuggestions
// This function need to return an array of es6 compliant Promise.
// Resolve those promise with an array of MagicBox.Suggestion
var magicBox = new Coveo.MagicBox.create( [ .... ])

magicBox.getSuggestions = function() {
    var ret = [];
    ret.push(new Promise(function(resolve, reject){
        var text = magicBox.getText();
        $.get('http://someservice.com?q=' + text)
        .done(function(data){
            // Here, be sure to resolve with an array of MagicBox.Suggestion
            resolve([{
                text : data
            },{
                text: 'another suggestion',
                separator: 'Yep this is a static suggestion'
            }])
        })
        .fail(function(){
            reject()
        })
    })
    
    return ret;
}

###MagicBox.Suggestion

  • text: string; OPTIONAL Simple text content for a suggestion, will be displayed as is in the magic box. eg : 'text': 'foobar'
  • html: string; OPTIONAL Any valid HTML content for a suggestion, as a string. eg: 'html': '<div class='some-class'><pre>foobar</pre></div>'
  • dom: HTMLElement; OPTIONAL Any valid HTML content for a suggestion, as an HTMLElement. eg: 'dom': document.createElement('div')
  • separator: string; OPTIONAL A string to display at the end of this suggestion. eg: 'separator': 'This is a separator'
  • onSelect: function; OPTIONAL A function to execute when this suggestion is selected by the end user. eg: 'onSelect': function() { doSomething(); }
  • index: number; OPTIONAL Allows to sort all the suggestions in the order you wish. Higher index means rendered first. eg: 'index': 999

Grammar

new Grammar('Start', {
    Start: ...,
    ...
})

Expression

RegExp Expression

/myRegex/

Options Expression

['Option1', 'Option2', 'Option3']

Ref Expression

Those can be add to the List Expression

Once

[referance]

Optionnal

[referance?]

Zero or many time

[referance*]

One or many time

[referance+]

List Expression

"constant [ref]"

Function Expression

IF YOU ARE NOT SURE IF YOU NEED THIS, YOU DON'T

(input: string, end: boolean, grammar:Grammar)=>Result
1.0.37

7 years ago

1.0.36

8 years ago

1.0.35

8 years ago

1.0.33

8 years ago

1.0.32

8 years ago

1.0.30

8 years ago

1.0.29

8 years ago

1.0.28

8 years ago

1.0.27

8 years ago

1.0.25

8 years ago

1.0.24

8 years ago

1.0.23

8 years ago

1.0.22

8 years ago

1.0.21

9 years ago

1.0.20

9 years ago

1.0.19

9 years ago

1.0.18

9 years ago

1.0.17

9 years ago

1.0.15

9 years ago

1.0.14

9 years ago

1.0.13

9 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.0

10 years ago