~johnsca/charms/trusty/cloudfoundry/reconciler-ui

« back to all changes in this revision

Viewing changes to reconciler/ui/static/semantic/uncompressed/modules/search.js

  • Committer: Whit Morriss
  • Date: 2014-10-13 06:50:17 UTC
  • Revision ID: whit.morriss@canonical.com-20141013065017-0feo2ku3yllymkol
reorg reconciler

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * # Semantic - Search
 
3
 * http://github.com/jlukic/semantic-ui/
 
4
 *
 
5
 *
 
6
 * Copyright 2014 Contributors
 
7
 * Released under the MIT license
 
8
 * http://opensource.org/licenses/MIT
 
9
 *
 
10
 */
 
11
 
 
12
;(function ($, window, document, undefined) {
 
13
 
 
14
$.fn.search = function(source, parameters) {
 
15
  var
 
16
    $allModules     = $(this),
 
17
    moduleSelector  = $allModules.selector || '',
 
18
 
 
19
    time            = new Date().getTime(),
 
20
    performance     = [],
 
21
 
 
22
    query           = arguments[0],
 
23
    methodInvoked   = (typeof query == 'string'),
 
24
    queryArguments  = [].slice.call(arguments, 1),
 
25
    returnedValue
 
26
  ;
 
27
  $(this)
 
28
    .each(function() {
 
29
      var
 
30
        settings        = $.extend(true, {}, $.fn.search.settings, parameters),
 
31
 
 
32
        className       = settings.className,
 
33
        selector        = settings.selector,
 
34
        error           = settings.error,
 
35
        namespace       = settings.namespace,
 
36
 
 
37
        eventNamespace  = '.' + namespace,
 
38
        moduleNamespace = namespace + '-module',
 
39
 
 
40
        $module         = $(this),
 
41
        $prompt         = $module.find(selector.prompt),
 
42
        $searchButton   = $module.find(selector.searchButton),
 
43
        $results        = $module.find(selector.results),
 
44
        $result         = $module.find(selector.result),
 
45
        $category       = $module.find(selector.category),
 
46
 
 
47
        element         = this,
 
48
        instance        = $module.data(moduleNamespace),
 
49
 
 
50
        module
 
51
      ;
 
52
      module = {
 
53
 
 
54
        initialize: function() {
 
55
          module.verbose('Initializing module');
 
56
          var
 
57
            prompt = $prompt[0],
 
58
            inputEvent   = (prompt.oninput !== undefined)
 
59
              ? 'input'
 
60
              : (prompt.onpropertychange !== undefined)
 
61
                ? 'propertychange'
 
62
                : 'keyup'
 
63
          ;
 
64
          // attach events
 
65
          $prompt
 
66
            .on('focus' + eventNamespace, module.event.focus)
 
67
            .on('blur' + eventNamespace, module.event.blur)
 
68
            .on('keydown' + eventNamespace, module.handleKeyboard)
 
69
          ;
 
70
          if(settings.automatic) {
 
71
            $prompt
 
72
              .on(inputEvent + eventNamespace, module.search.throttle)
 
73
            ;
 
74
          }
 
75
          $searchButton
 
76
            .on('click' + eventNamespace, module.search.query)
 
77
          ;
 
78
          $results
 
79
            .on('click' + eventNamespace, selector.result, module.results.select)
 
80
          ;
 
81
          module.instantiate();
 
82
        },
 
83
        instantiate: function() {
 
84
          module.verbose('Storing instance of module', module);
 
85
          instance = module;
 
86
          $module
 
87
            .data(moduleNamespace, module)
 
88
          ;
 
89
        },
 
90
        destroy: function() {
 
91
          module.verbose('Destroying instance');
 
92
          $module
 
93
            .removeData(moduleNamespace)
 
94
          ;
 
95
        },
 
96
        event: {
 
97
          focus: function() {
 
98
            $module
 
99
              .addClass(className.focus)
 
100
            ;
 
101
            module.results.show();
 
102
          },
 
103
          blur: function() {
 
104
            module.search.cancel();
 
105
            $module
 
106
              .removeClass(className.focus)
 
107
            ;
 
108
            module.results.hide();
 
109
          }
 
110
        },
 
111
        handleKeyboard: function(event) {
 
112
          var
 
113
            // force latest jq dom
 
114
            $result       = $module.find(selector.result),
 
115
            $category     = $module.find(selector.category),
 
116
            keyCode       = event.which,
 
117
            keys          = {
 
118
              backspace : 8,
 
119
              enter     : 13,
 
120
              escape    : 27,
 
121
              upArrow   : 38,
 
122
              downArrow : 40
 
123
            },
 
124
            activeClass  = className.active,
 
125
            currentIndex = $result.index( $result.filter('.' + activeClass) ),
 
126
            resultSize   = $result.size(),
 
127
            newIndex
 
128
          ;
 
129
          // search shortcuts
 
130
          if(keyCode == keys.escape) {
 
131
            module.verbose('Escape key pressed, blurring search field');
 
132
            $prompt
 
133
              .trigger('blur')
 
134
            ;
 
135
          }
 
136
          // result shortcuts
 
137
          if($results.filter(':visible').size() > 0) {
 
138
            if(keyCode == keys.enter) {
 
139
              module.verbose('Enter key pressed, selecting active result');
 
140
              if( $result.filter('.' + activeClass).size() > 0 ) {
 
141
                $.proxy(module.results.select, $result.filter('.' + activeClass) )();
 
142
                event.preventDefault();
 
143
                return false;
 
144
              }
 
145
            }
 
146
            else if(keyCode == keys.upArrow) {
 
147
              module.verbose('Up key pressed, changing active result');
 
148
              newIndex = (currentIndex - 1 < 0)
 
149
                ? currentIndex
 
150
                : currentIndex - 1
 
151
              ;
 
152
              $category
 
153
                .removeClass(activeClass)
 
154
              ;
 
155
              $result
 
156
                .removeClass(activeClass)
 
157
                .eq(newIndex)
 
158
                  .addClass(activeClass)
 
159
                  .closest($category)
 
160
                    .addClass(activeClass)
 
161
              ;
 
162
              event.preventDefault();
 
163
            }
 
164
            else if(keyCode == keys.downArrow) {
 
165
              module.verbose('Down key pressed, changing active result');
 
166
              newIndex = (currentIndex + 1 >= resultSize)
 
167
                ? currentIndex
 
168
                : currentIndex + 1
 
169
              ;
 
170
              $category
 
171
                .removeClass(activeClass)
 
172
              ;
 
173
              $result
 
174
                .removeClass(activeClass)
 
175
                .eq(newIndex)
 
176
                  .addClass(activeClass)
 
177
                  .closest($category)
 
178
                    .addClass(activeClass)
 
179
              ;
 
180
              event.preventDefault();
 
181
            }
 
182
          }
 
183
          else {
 
184
            // query shortcuts
 
185
            if(keyCode == keys.enter) {
 
186
              module.verbose('Enter key pressed, executing query');
 
187
              module.search.query();
 
188
              $searchButton
 
189
                .addClass(className.down)
 
190
              ;
 
191
              $prompt
 
192
                .one('keyup', function(){
 
193
                  $searchButton
 
194
                    .removeClass(className.down)
 
195
                  ;
 
196
                })
 
197
              ;
 
198
            }
 
199
          }
 
200
        },
 
201
        search: {
 
202
          cancel: function() {
 
203
            var
 
204
              xhr = $module.data('xhr') || false
 
205
            ;
 
206
            if( xhr && xhr.state() != 'resolved') {
 
207
              module.debug('Cancelling last search');
 
208
              xhr.abort();
 
209
            }
 
210
          },
 
211
          throttle: function() {
 
212
            var
 
213
              searchTerm    = $prompt.val(),
 
214
              numCharacters = searchTerm.length
 
215
            ;
 
216
            clearTimeout(module.timer);
 
217
            if(numCharacters >= settings.minCharacters)  {
 
218
              module.timer = setTimeout(module.search.query, settings.searchThrottle);
 
219
            }
 
220
            else {
 
221
              module.results.hide();
 
222
            }
 
223
          },
 
224
          query: function() {
 
225
            var
 
226
              searchTerm = $prompt.val(),
 
227
              cachedHTML = module.search.cache.read(searchTerm)
 
228
            ;
 
229
            if(cachedHTML) {
 
230
              module.debug("Reading result for '" + searchTerm + "' from cache");
 
231
              module.results.add(cachedHTML);
 
232
            }
 
233
            else {
 
234
              module.debug("Querying for '" + searchTerm + "'");
 
235
              if(typeof source == 'object') {
 
236
                module.search.local(searchTerm);
 
237
              }
 
238
              else {
 
239
                module.search.remote(searchTerm);
 
240
              }
 
241
              $.proxy(settings.onSearchQuery, $module)(searchTerm);
 
242
            }
 
243
          },
 
244
          local: function(searchTerm) {
 
245
            var
 
246
              results   = [],
 
247
              fullTextResults = [],
 
248
              searchFields    = $.isArray(settings.searchFields)
 
249
                ? settings.searchFields
 
250
                : [settings.searchFields],
 
251
 
 
252
              searchRegExp   = new RegExp('(?:\s|^)' + searchTerm, 'i'),
 
253
              fullTextRegExp = new RegExp(searchTerm, 'i'),
 
254
              searchHTML
 
255
            ;
 
256
            $module
 
257
              .addClass(className.loading)
 
258
            ;
 
259
            // iterate through search fields in array order
 
260
            $.each(searchFields, function(index, field) {
 
261
              $.each(source, function(label, thing) {
 
262
                if(typeof thing[field] == 'string' && ($.inArray(thing, results) == -1) && ($.inArray(thing, fullTextResults) == -1) ) {
 
263
                  if( searchRegExp.test( thing[field] ) ) {
 
264
                    results.push(thing);
 
265
                  }
 
266
                  else if( fullTextRegExp.test( thing[field] ) ) {
 
267
                    fullTextResults.push(thing);
 
268
                  }
 
269
                }
 
270
              });
 
271
            });
 
272
            searchHTML = module.results.generate({
 
273
              results: $.merge(results, fullTextResults)
 
274
            });
 
275
            $module
 
276
              .removeClass(className.loading)
 
277
            ;
 
278
            module.search.cache.write(searchTerm, searchHTML);
 
279
            module.results.add(searchHTML);
 
280
          },
 
281
          remote: function(searchTerm) {
 
282
            var
 
283
              apiSettings = {
 
284
                stateContext  : $module,
 
285
                url           : source,
 
286
                urlData: { query: searchTerm },
 
287
                success       : function(response) {
 
288
                  searchHTML = module.results.generate(response);
 
289
                  module.search.cache.write(searchTerm, searchHTML);
 
290
                  module.results.add(searchHTML);
 
291
                },
 
292
                failure      : module.error
 
293
              },
 
294
              searchHTML
 
295
            ;
 
296
            module.search.cancel();
 
297
            module.debug('Executing search');
 
298
            $.extend(true, apiSettings, settings.apiSettings);
 
299
            $.api(apiSettings);
 
300
          },
 
301
 
 
302
          cache: {
 
303
            read: function(name) {
 
304
              var
 
305
                cache = $module.data('cache')
 
306
              ;
 
307
              return (settings.cache && (typeof cache == 'object') && (cache[name] !== undefined) )
 
308
                ? cache[name]
 
309
                : false
 
310
              ;
 
311
            },
 
312
            write: function(name, value) {
 
313
              var
 
314
                cache = ($module.data('cache') !== undefined)
 
315
                  ? $module.data('cache')
 
316
                  : {}
 
317
              ;
 
318
              cache[name] = value;
 
319
              $module
 
320
                .data('cache', cache)
 
321
              ;
 
322
            }
 
323
          }
 
324
        },
 
325
 
 
326
        results: {
 
327
          generate: function(response) {
 
328
            module.debug('Generating html from response', response);
 
329
            var
 
330
              template = settings.templates[settings.type],
 
331
              html     = ''
 
332
            ;
 
333
            if(($.isPlainObject(response.results) && !$.isEmptyObject(response.results)) || ($.isArray(response.results) && response.results.length > 0) ) {
 
334
              if(settings.maxResults > 0) {
 
335
                response.results = $.makeArray(response.results).slice(0, settings.maxResults);
 
336
              }
 
337
              if(response.results.length > 0) {
 
338
                if($.isFunction(template)) {
 
339
                  html = template(response);
 
340
                }
 
341
                else {
 
342
                  module.error(error.noTemplate, false);
 
343
                }
 
344
              }
 
345
            }
 
346
            else {
 
347
              html = module.message(error.noResults, 'empty');
 
348
            }
 
349
            $.proxy(settings.onResults, $module)(response);
 
350
            return html;
 
351
          },
 
352
          add: function(html) {
 
353
            if(settings.onResultsAdd == 'default' || $.proxy(settings.onResultsAdd, $results)(html) == 'default') {
 
354
              $results
 
355
                .html(html)
 
356
              ;
 
357
            }
 
358
            module.results.show();
 
359
          },
 
360
          show: function() {
 
361
            if( ($results.filter(':visible').size() === 0) && ($prompt.filter(':focus').size() > 0) && $results.html() !== '') {
 
362
              $results
 
363
                .stop()
 
364
                .fadeIn(200)
 
365
              ;
 
366
              $.proxy(settings.onResultsOpen, $results)();
 
367
            }
 
368
          },
 
369
          hide: function() {
 
370
            if($results.filter(':visible').size() > 0) {
 
371
              $results
 
372
                .stop()
 
373
                .fadeOut(200)
 
374
              ;
 
375
              $.proxy(settings.onResultsClose, $results)();
 
376
            }
 
377
          },
 
378
          select: function(event) {
 
379
            module.debug('Search result selected');
 
380
            var
 
381
              $result = $(this),
 
382
              $title  = $result.find('.title'),
 
383
              title   = $title.html()
 
384
            ;
 
385
            if(settings.onSelect == 'default' || $.proxy(settings.onSelect, this)(event) == 'default') {
 
386
              var
 
387
                $link  = $result.find('a[href]').eq(0),
 
388
                href   = $link.attr('href') || false,
 
389
                target = $link.attr('target') || false
 
390
              ;
 
391
              module.results.hide();
 
392
              $prompt
 
393
                .val(title)
 
394
              ;
 
395
              if(href) {
 
396
                if(target == '_blank' || event.ctrlKey) {
 
397
                  window.open(href);
 
398
                }
 
399
                else {
 
400
                  window.location.href = (href);
 
401
                }
 
402
              }
 
403
            }
 
404
          }
 
405
        },
 
406
 
 
407
        setting: function(name, value) {
 
408
          if( $.isPlainObject(name) ) {
 
409
            $.extend(true, settings, name);
 
410
          }
 
411
          else if(value !== undefined) {
 
412
            settings[name] = value;
 
413
          }
 
414
          else {
 
415
            return settings[name];
 
416
          }
 
417
        },
 
418
        internal: function(name, value) {
 
419
          if( $.isPlainObject(name) ) {
 
420
            $.extend(true, module, name);
 
421
          }
 
422
          else if(value !== undefined) {
 
423
            module[name] = value;
 
424
          }
 
425
          else {
 
426
            return module[name];
 
427
          }
 
428
        },
 
429
        debug: function() {
 
430
          if(settings.debug) {
 
431
            if(settings.performance) {
 
432
              module.performance.log(arguments);
 
433
            }
 
434
            else {
 
435
              module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
 
436
              module.debug.apply(console, arguments);
 
437
            }
 
438
          }
 
439
        },
 
440
        verbose: function() {
 
441
          if(settings.verbose && settings.debug) {
 
442
            if(settings.performance) {
 
443
              module.performance.log(arguments);
 
444
            }
 
445
            else {
 
446
              module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
 
447
              module.verbose.apply(console, arguments);
 
448
            }
 
449
          }
 
450
        },
 
451
        error: function() {
 
452
          module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
 
453
          module.error.apply(console, arguments);
 
454
        },
 
455
        performance: {
 
456
          log: function(message) {
 
457
            var
 
458
              currentTime,
 
459
              executionTime,
 
460
              previousTime
 
461
            ;
 
462
            if(settings.performance) {
 
463
              currentTime   = new Date().getTime();
 
464
              previousTime  = time || currentTime;
 
465
              executionTime = currentTime - previousTime;
 
466
              time          = currentTime;
 
467
              performance.push({
 
468
                'Element'        : element,
 
469
                'Name'           : message[0],
 
470
                'Arguments'      : [].slice.call(message, 1) || '',
 
471
                'Execution Time' : executionTime
 
472
              });
 
473
            }
 
474
            clearTimeout(module.performance.timer);
 
475
            module.performance.timer = setTimeout(module.performance.display, 100);
 
476
          },
 
477
          display: function() {
 
478
            var
 
479
              title = settings.name + ':',
 
480
              totalTime = 0
 
481
            ;
 
482
            time = false;
 
483
            clearTimeout(module.performance.timer);
 
484
            $.each(performance, function(index, data) {
 
485
              totalTime += data['Execution Time'];
 
486
            });
 
487
            title += ' ' + totalTime + 'ms';
 
488
            if(moduleSelector) {
 
489
              title += ' \'' + moduleSelector + '\'';
 
490
            }
 
491
            if($allModules.size() > 1) {
 
492
              title += ' ' + '(' + $allModules.size() + ')';
 
493
            }
 
494
            if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
 
495
              console.groupCollapsed(title);
 
496
              if(console.table) {
 
497
                console.table(performance);
 
498
              }
 
499
              else {
 
500
                $.each(performance, function(index, data) {
 
501
                  console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
 
502
                });
 
503
              }
 
504
              console.groupEnd();
 
505
            }
 
506
            performance = [];
 
507
          }
 
508
        },
 
509
        invoke: function(query, passedArguments, context) {
 
510
          var
 
511
            object = instance,
 
512
            maxDepth,
 
513
            found,
 
514
            response
 
515
          ;
 
516
          passedArguments = passedArguments || queryArguments;
 
517
          context         = element         || context;
 
518
          if(typeof query == 'string' && object !== undefined) {
 
519
            query    = query.split(/[\. ]/);
 
520
            maxDepth = query.length - 1;
 
521
            $.each(query, function(depth, value) {
 
522
              var camelCaseValue = (depth != maxDepth)
 
523
                ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
 
524
                : query
 
525
              ;
 
526
              if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
 
527
                object = object[camelCaseValue];
 
528
              }
 
529
              else if( object[camelCaseValue] !== undefined ) {
 
530
                found = object[camelCaseValue];
 
531
                return false;
 
532
              }
 
533
              else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
 
534
                object = object[value];
 
535
              }
 
536
              else if( object[value] !== undefined ) {
 
537
                found = object[value];
 
538
                return false;
 
539
              }
 
540
              else {
 
541
                return false;
 
542
              }
 
543
            });
 
544
          }
 
545
          if ( $.isFunction( found ) ) {
 
546
            response = found.apply(context, passedArguments);
 
547
          }
 
548
          else if(found !== undefined) {
 
549
            response = found;
 
550
          }
 
551
          if($.isArray(returnedValue)) {
 
552
            returnedValue.push(response);
 
553
          }
 
554
          else if(returnedValue !== undefined) {
 
555
            returnedValue = [returnedValue, response];
 
556
          }
 
557
          else if(response !== undefined) {
 
558
            returnedValue = response;
 
559
          }
 
560
          return found;
 
561
        }
 
562
      };
 
563
      if(methodInvoked) {
 
564
        if(instance === undefined) {
 
565
          module.initialize();
 
566
        }
 
567
        module.invoke(query);
 
568
      }
 
569
      else {
 
570
        if(instance !== undefined) {
 
571
          module.destroy();
 
572
        }
 
573
        module.initialize();
 
574
      }
 
575
 
 
576
    })
 
577
  ;
 
578
 
 
579
  return (returnedValue !== undefined)
 
580
    ? returnedValue
 
581
    : this
 
582
  ;
 
583
};
 
584
 
 
585
$.fn.search.settings = {
 
586
 
 
587
  name           : 'Search Module',
 
588
  namespace      : 'search',
 
589
 
 
590
  debug          : false,
 
591
  verbose        : true,
 
592
  performance    : true,
 
593
 
 
594
  // onSelect default action is defined in module
 
595
  onSelect       : 'default',
 
596
  onResultsAdd   : 'default',
 
597
 
 
598
  onSearchQuery  : function(){},
 
599
  onResults      : function(response){},
 
600
 
 
601
  onResultsOpen  : function(){},
 
602
  onResultsClose : function(){},
 
603
 
 
604
  automatic      : 'true',
 
605
  type           : 'simple',
 
606
  minCharacters  : 3,
 
607
  searchThrottle : 300,
 
608
  maxResults     : 7,
 
609
  cache          : true,
 
610
 
 
611
  searchFields    : [
 
612
    'title',
 
613
    'description'
 
614
  ],
 
615
 
 
616
  // api config
 
617
  apiSettings: {
 
618
 
 
619
  },
 
620
 
 
621
  className: {
 
622
    active  : 'active',
 
623
    down    : 'down',
 
624
    focus   : 'focus',
 
625
    empty   : 'empty',
 
626
    loading : 'loading'
 
627
  },
 
628
 
 
629
  error : {
 
630
    noResults   : 'Your search returned no results',
 
631
    logging     : 'Error in debug logging, exiting.',
 
632
    noTemplate  : 'A valid template name was not specified.',
 
633
    serverError : 'There was an issue with querying the server.',
 
634
    method      : 'The method you called is not defined.'
 
635
  },
 
636
 
 
637
  selector : {
 
638
    prompt       : '.prompt',
 
639
    searchButton : '.search.button',
 
640
    results      : '.results',
 
641
    category     : '.category',
 
642
    result       : '.result'
 
643
  },
 
644
 
 
645
  templates: {
 
646
    message: function(message, type) {
 
647
      var
 
648
        html = ''
 
649
      ;
 
650
      if(message !== undefined && type !== undefined) {
 
651
        html +=  ''
 
652
          + '<div class="message ' + type +'">'
 
653
        ;
 
654
        // message type
 
655
        if(type == 'empty') {
 
656
          html += ''
 
657
            + '<div class="header">No Results</div class="header">'
 
658
            + '<div class="description">' + message + '</div class="description">'
 
659
          ;
 
660
        }
 
661
        else {
 
662
          html += ' <div class="description">' + message + '</div>';
 
663
        }
 
664
        html += '</div>';
 
665
      }
 
666
      return html;
 
667
    },
 
668
    categories: function(response) {
 
669
      var
 
670
        html = ''
 
671
      ;
 
672
      if(response.results !== undefined) {
 
673
        // each category
 
674
        $.each(response.results, function(index, category) {
 
675
          if(category.results !== undefined && category.results.length > 0) {
 
676
            html  += ''
 
677
              + '<div class="category">'
 
678
              + '<div class="name">' + category.name + '</div>'
 
679
            ;
 
680
            // each item inside category
 
681
            $.each(category.results, function(index, result) {
 
682
              html  += '<div class="result">';
 
683
              html  += '<a href="' + result.url + '"></a>';
 
684
              if(result.image !== undefined) {
 
685
                html+= ''
 
686
                  + '<div class="image">'
 
687
                  + ' <img src="' + result.image + '">'
 
688
                  + '</div>'
 
689
                ;
 
690
              }
 
691
              html += '<div class="info">';
 
692
              if(result.price !== undefined) {
 
693
                html+= '<div class="price">' + result.price + '</div>';
 
694
              }
 
695
              if(result.title !== undefined) {
 
696
                html+= '<div class="title">' + result.title + '</div>';
 
697
              }
 
698
              if(result.description !== undefined) {
 
699
                html+= '<div class="description">' + result.description + '</div>';
 
700
              }
 
701
              html  += ''
 
702
                + '</div>'
 
703
                + '</div>'
 
704
              ;
 
705
            });
 
706
            html  += ''
 
707
              + '</div>'
 
708
            ;
 
709
          }
 
710
        });
 
711
        if(response.resultPage) {
 
712
          html += ''
 
713
          + '<a href="' + response.resultPage.url + '" class="all">'
 
714
          +   response.resultPage.text
 
715
          + '</a>';
 
716
        }
 
717
        return html;
 
718
      }
 
719
      return false;
 
720
    },
 
721
    simple: function(response) {
 
722
      var
 
723
        html = ''
 
724
      ;
 
725
      if(response.results !== undefined) {
 
726
 
 
727
        // each result
 
728
        $.each(response.results, function(index, result) {
 
729
          html  += '<a class="result" href="' + result.url + '">';
 
730
          if(result.image !== undefined) {
 
731
            html+= ''
 
732
              + '<div class="image">'
 
733
              + ' <img src="' + result.image + '">'
 
734
              + '</div>'
 
735
            ;
 
736
          }
 
737
          html += '<div class="info">';
 
738
          if(result.price !== undefined) {
 
739
            html+= '<div class="price">' + result.price + '</div>';
 
740
          }
 
741
          if(result.title !== undefined) {
 
742
            html+= '<div class="title">' + result.title + '</div>';
 
743
          }
 
744
          if(result.description !== undefined) {
 
745
            html+= '<div class="description">' + result.description + '</div>';
 
746
          }
 
747
          html  += ''
 
748
            + '</div>'
 
749
            + '</a>'
 
750
          ;
 
751
        });
 
752
 
 
753
        if(response.resultPage) {
 
754
          html += ''
 
755
          + '<a href="' + response.resultPage.url + '" class="all">'
 
756
          +   response.resultPage.text
 
757
          + '</a>';
 
758
        }
 
759
        return html;
 
760
      }
 
761
      return false;
 
762
    }
 
763
  }
 
764
};
 
765
 
 
766
})( jQuery, window , document );
 
 
b'\\ No newline at end of file'