Skip to content

Instantly share code, notes, and snippets.

@ttilley
Forked from jashkenas/search.coffee
Created April 3, 2010 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttilley/354876 to your computer and use it in GitHub Desktop.
Save ttilley/354876 to your computer and use it in GitHub Desktop.
dojo.provide 'cdoc.mixins.search'
dojo.require "dijit.form.ValidationTextBox"
dojo.require "dijit.layout.BorderContainer"
dojo.require "dijit.layout.ContentPane"
dojo.require "dojo.data.ItemFileReadStore"
dojo.require "cdoc.string.quicksilver"
dojo.declare "cdoc.mixins.search", [dijit.layout.BorderContainer], {
title: "Mixins"
design: 'headline'
gutters: true
store: null
abbreviation: ''
matches: []
mixinImages: {
'Compass Core': "/docs/images/compass_icon.png"
'Blueprint': "/docs/images/blueprint_icon.png"
}
constructor: (options) ->
dojo.mixin this, options
_escapeHTML: (str) ->
div: document.createElement 'div'
text: document.createTextNode str
div.appendChild text
div.innerHTML
_nukeList: ->
this.matches: []
dojo.empty this.resultList
_score: (item) ->
name: this.store.getValue item, 'name'
score: cdoc.string.quicksilver name.toLowerCase(), this.abbreviation.toLowerCase()
if score > 0
pathname: this.store.getValue item, 'pathname'
signature: this._escapeHTML this.store.getValue item, 'signature'
framework: this._escapeHTML this.store.getValue item, 'framework'
stylesheet: this._escapeHTML this.store.getValue item, 'stylesheet'
line_item: dojo.create 'li', {
'data-framework': framework
'data-name': name
'data-signature': signature
'data-score': score
'data-stylesheet': stylesheet
}
link: dojo.create 'a', {href: pathname}, line_item
src: this.mixinImages[framework] or this._blankGif
dojo.create 'img', {src: src.toString(), alt: ''}, link
dojo.create 'span', {innerHTML: signature}, link
this.matches.push line_item
}
(function(){
dojo.provide('cdoc.mixins.search');
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("cdoc.string.quicksilver");
dojo.declare("cdoc.mixins.search", [dijit.layout.BorderContainer], {
title: "Mixins",
design: 'headline',
gutters: true,
store: null,
abbreviation: '',
matches: [],
mixinImages: {
'Compass Core': "/docs/images/compass_icon.png",
'Blueprint': "/docs/images/blueprint_icon.png"
},
constructor: function constructor(options) {
return dojo.mixin(this, options);
},
_escapeHTML: function _escapeHTML(str) {
var div, text;
div = document.createElement('div');
text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
},
_nukeList: function _nukeList() {
this.matches = [];
return dojo.empty(this.resultList);
},
_score: function _score(item) {
var framework, line_item, link, name, pathname, score, signature, src, stylesheet;
name = this.store.getValue(item, 'name');
score = cdoc.string.quicksilver(name.toLowerCase(), this.abbreviation.toLowerCase());
if (score > 0) {
pathname = this.store.getValue(item, 'pathname');
signature = this._escapeHTML(this.store.getValue(item, 'signature'));
framework = this._escapeHTML(this.store.getValue(item, 'framework'));
stylesheet = this._escapeHTML(this.store.getValue(item, 'stylesheet'));
line_item = dojo.create('li', {
'data-framework': framework,
'data-name': name,
'data-signature': signature,
'data-score': score,
'data-stylesheet': stylesheet
});
link = dojo.create('a', {
href: pathname
}, line_item);
src = this.mixinImages[framework] || this._blankGif;
dojo.create('img', {
src: src.toString(),
alt: ''
}, link);
dojo.create('span', {
innerHTML: signature
}, link);
return this.matches.push(line_item);
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment