Skip to content

Instantly share code, notes, and snippets.

@morgondag
Last active August 29, 2015 13:57
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 morgondag/9763389 to your computer and use it in GitHub Desktop.
Save morgondag/9763389 to your computer and use it in GitHub Desktop.
A awesome flight.js ui file
/*
1. save this file in ui/data folder with a name
for example if its reader discussion ajax reader_discussion_ajax.js
2. go to reader.js or builder.js
3. require this new file add
var newAwesomeFile = require('ui/reader_discussion_ajax');
4. in the initialize in reader.js attach this file to a DOM node.
if its global add it to document
example:
newAwesomeFile.attachTo('#yourParentSelector');
now this file will be loaded and started everywhere in reader where there is a
dom selector like <div id="yourParentSelector"></div>
*/
define(
[ // here just just include special dependencies like dropdown
'flight/component',
'events',
'utils'
],
// define the scope
function (defineComponent, EVENTS, _) {
'use strict';
// define the name of this function awesomeScript and include the dropdown mixin
return defineComponent(awesomeScript,);
// inside here we write all the magic.
function awesomeScript() {
// define all your global variables here
var someCoolEndpoint = 'data/hubbut/addNewThing'
var thing = 123;
// DOM SELECTORS like <a class="click-btn">
this.defaultAttrs({
$aSelector: '.click-btn',
$anotherSelector: '.button2'
})
// example function
this.awesomeStuff = function(e,t){
e.preventDefault();
// do awesome stuff
}
// example function
this.awesomeInit = function(){
// do awesome stuff on pageload
}
// example function
this.anotherAwesomeFunction = function(e,t){
e.preventDefault();
// do kewl stuff
}
// does something
this.someOtherFunction = function(){
}
//setup stuff when this script is loaded.
this.after('initialize', function() {
// call some logic on load
this.awesomeInit();
//setup click triggers
this.on('click',{
$aSelector: this.awesomeStuff,
$anotherSelector: this.someOtherFunction
})
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment