Permalink
Browse files

add requirejs example

  • Loading branch information...
1 parent 43061d9 commit 9ad43101fcca6efbf79475b058f8cc4a4381fd9c @jpmckinney jpmckinney committed Apr 16, 2013
@@ -0,0 +1,160 @@
+* {
+ padding: 0;
+ margin: 0;
+}
+
+body {
+ background: #fff url(../images/header.gif) repeat-x;
+ color: #333;
+ font-family: Verdana, Arial, Helvetica, sans-serif;
+ font-size: 12px;
+ line-height: 18px;
+}
+img {
+ border: none;
+}
+a {
+ color: #6998f0;
+ text-decoration: none;
+}
+a:hover {
+ color: #000;
+ text-decoration: underline;
+}
+
+#wrap {
+ width: 1000px;
+ margin: 0px auto;
+}
+.clear {
+ clear: both;
+}
+
+/* header */
+
+#header {
+ height: 90px;
+}
+#header h1 {
+ padding: 20px 0 5px 10px;
+ font-size: 20px;
+ letter-spacing: -2px;
+}
+#header h2 {
+ padding-left: 10px;
+ color: #666;
+ font-size: 14px;
+ font-weight: 100;
+}
+
+/* right */
+
+.right {
+ float: right;
+ width: 538px;
+ padding: 10px 20px 10px 40px;
+ border-left: 1px solid #aaa;
+ text-align: justify;
+}
+.right h2 {
+ padding: 15px 0 5px 0;
+ color: #B4241B;
+ font-size: 20px;
+ font-weight: 100;
+ letter-spacing: -2px;
+}
+#result a {
+ margin-right: 5px;
+}
+#navigation {
+ border-bottom: 1px solid #000;
+}
+#pager,
+#pager-header {
+ display: inline;
+}
+#pager li,
+.links li {
+ list-style-type: none;
+ display: inline;
+}
+#selection {
+ padding: 10px 15px 0;
+}
+#selection li {
+ list-style-type: none;
+}
+#docs {
+ padding-top: 1px;
+}
+
+/* left */
+
+.left {
+ float: left;
+ width: 390px;
+ padding: 0 0 10px 10px;
+}
+.left h2 {
+ clear: left;
+ padding-top: 20px;
+ color: #333;
+ font-size: 13px;
+}
+#search input {
+ width: 350px;
+}
+#calendar {
+ width: 160px;
+}
+#search_help {
+ font-size: 80%;
+}
+.tagcloud {
+ padding: 10px 15px 0;
+}
+.tagcloud_item {
+ float: left;
+ display: block;
+ margin-right: 4px;
+ color: #6998f0;
+}
+.tagcloud_item:hover {
+ color: #f00;
+}
+
+/* tagcloud */
+
+a.tagcloud_size_0 {
+font-size: 80%;
+}
+a.tagcloud_size_1 {
+font-size: 90%;
+}
+a.tagcloud_size_2 {
+font-size: 100%;
+}Rst
+a.tagcloud_size_3 {
+font-size: 110%;
+}
+a.tagcloud_size_4 {
+font-size: 120%;
+}
+a.tagcloud_size_5 {
+font-size: 130%;
+}
+a.tagcloud_size_6 {
+font-size: 140%;
+}
+a.tagcloud_size_7 {
+font-size: 150%
+}
+a.tagcloud_size_8 {
+font-size: 160%;
+}
+a.tagcloud_size_9 {
+font-size: 170%;
+}
+a.tagcloud_size_10 {
+font-size: 180%;
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>AJAX Solr</title>
+ <link rel="stylesheet" href="css/reuters.css">
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script>
+ <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/smoothness/jquery-ui.css">
+ <script data-main="js/reuters" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.5/require.min.js"></script>
+</head>
+<body>
+ <div id="wrap">
+ <div id="header">
+ <h1>AJAX Solr Demonstration</h1>
+ <h2>Browse Reuters business news from 1987</h2>
+ </div>
+
+ <div class="right">
+ <div id="result">
+ <div id="navigation">
+ <ul id="pager"></ul>
+ <div id="pager-header"></div>
+ </div>
+ <div id="docs"></div>
+ </div>
+ </div>
+
+ <div class="left">
+ <h2>Current Selection</h2>
+ <ul id="selection"></ul>
+
+ <h2>Search</h2>
+ <span id="search_help">(press ESC to close suggestions)</span>
+ <ul id="search">
+ <input type="text" id="query" name="query" autocomplete="off">
+ </ul>
+
+ <h2>Top Topics</h2>
+ <div class="tagcloud" id="topics"></div>
+
+ <h2>Top Organisations</h2>
+ <div class="tagcloud" id="organisations"></div>
+
+ <h2>Top Exchanges</h2>
+ <div class="tagcloud" id="exchanges"></div>
+
+ <h2>By Country</h2>
+ <div id="countries"></div>
+ <div id="preview"></div>
+
+ <h2>By Date</h2>
+ <div id="calendar"></div>
+
+ <div class="clear"></div>
+ </div>
+ <div class="clear"></div>
+ </div>
+</body>
+</html>
@@ -0,0 +1,102 @@
+var Manager;
+
+require.config({
+ paths: {
+ core: '../../../core',
+ managers: '../../../managers',
+ widgets: '../../../widgets',
+ reuters: '../widgets'
+ },
+ urlArgs: "bust=" + (new Date()).getTime()
+});
+
+(function ($) {
+
+define([
+ 'managers/Manager.jquery',
+ 'core/ParameterStore',
+ 'reuters/ResultWidget',
+ 'reuters/TagcloudWidget',
+ 'reuters/CurrentSearchWidget.9',
+ 'reuters/AutocompleteWidget',
+ 'reuters/CountryCodeWidget',
+ 'reuters/CalendarWidget',
+ 'widgets/jquery/PagerWidget'
+], function () {
+ $(function () {
+ Manager = new AjaxSolr.Manager({
+ solrUrl: 'http://evolvingweb.ca/solr/reuters/'
+ });
+ Manager.addWidget(new AjaxSolr.ResultWidget({
+ id: 'result',
+ target: '#docs'
+ }));
+ Manager.addWidget(new AjaxSolr.PagerWidget({
+ id: 'pager',
+ target: '#pager',
+ prevLabel: '&lt;',
+ nextLabel: '&gt;',
+ innerWindow: 1,
+ renderHeader: function (perPage, offset, total) {
+ $('#pager-header').html($('<span></span>').text('displaying ' + Math.min(total, offset + 1) + ' to ' + Math.min(total, offset + perPage) + ' of ' + total));
+ }
+ }));
+ var fields = [ 'topics', 'organisations', 'exchanges' ];
+ for (var i = 0, l = fields.length; i < l; i++) {
+ Manager.addWidget(new AjaxSolr.TagcloudWidget({
+ id: fields[i],
+ target: '#' + fields[i],
+ field: fields[i]
+ }));
+ }
+ Manager.addWidget(new AjaxSolr.CurrentSearchWidget({
+ id: 'currentsearch',
+ target: '#selection'
+ }));
+ Manager.addWidget(new AjaxSolr.AutocompleteWidget({
+ id: 'text',
+ target: '#search',
+ fields: [ 'topics', 'organisations', 'exchanges' ]
+ }));
+ Manager.addWidget(new AjaxSolr.CountryCodeWidget({
+ id: 'countries',
+ target: '#countries',
+ field: 'countryCodes'
+ }));
+ Manager.addWidget(new AjaxSolr.CalendarWidget({
+ id: 'calendar',
+ target: '#calendar',
+ field: 'date'
+ }));
+ Manager.init();
+ Manager.store.addByValue('q', '*:*');
+ var params = {
+ facet: true,
+ 'facet.field': [ 'topics', 'organisations', 'exchanges', 'countryCodes' ],
+ 'facet.limit': 20,
+ 'facet.mincount': 1,
+ 'f.topics.facet.limit': 50,
+ 'f.countryCodes.facet.limit': -1,
+ 'facet.date': 'date',
+ 'facet.date.start': '1987-02-26T00:00:00.000Z/DAY',
+ 'facet.date.end': '1987-10-20T00:00:00.000Z/DAY+1DAY',
+ 'facet.date.gap': '+1DAY',
+ 'json.nl': 'map'
+ };
+ for (var name in params) {
+ Manager.store.addByValue(name, params[name]);
+ }
+ Manager.doRequest();
+ });
+
+ $.fn.showIf = function (condition) {
+ if (condition) {
+ return this.show();
+ }
+ else {
+ return this.hide();
+ }
+ }
+});
+
+})(jQuery);
@@ -0,0 +1,57 @@
+(function (callback) {
+ if (typeof define === 'function' && define.amd) {
+ define(['core/AbstractTextWidget'], callback);
+ }
+ else {
+ callback();
+ }
+}(function () {
+
+(function ($) {
+
+AjaxSolr.AutocompleteWidget = AjaxSolr.AbstractTextWidget.extend({
+ afterRequest: function () {
+ $(this.target).find('input').unbind().removeData('events').val('');
+
+ var self = this;
+
+ var list = [];
+ for (var i = 0; i < this.fields.length; i++) {
+ var field = this.fields[i];
+ for (var facet in this.manager.response.facet_counts.facet_fields[field]) {
+ list.push({
+ field: field,
+ value: facet,
+ label: facet + ' (' + this.manager.response.facet_counts.facet_fields[field][facet] + ') - ' + field
+ });
+ }
+ }
+
+ this.requestSent = false;
+ $(this.target).find('input').autocomplete('destroy').autocomplete({
+ source: list,
+ select: function(event, ui) {
+ if (ui.item) {
+ self.requestSent = true;
+ if (self.manager.store.addByValue('fq', ui.item.field + ':' + AjaxSolr.Parameter.escapeValue(ui.item.value))) {
+ self.doRequest();
+ }
+ }
+ }
+ });
+
+ // This has lower priority so that requestSent is set.
+ $(this.target).find('input').bind('keydown', function(e) {
+ if (self.requestSent === false && e.which == 13) {
+ var value = $(this).val();
+ if (value && self.set(value)) {
+ self.doRequest();
+ }
+ }
+ });
+ }
+});
+
+})(jQuery);
+
+}));
Oops, something went wrong.

0 comments on commit 9ad4310

Please sign in to comment.