- Define and group Angular things (dependency injection stuff) in modules.
- Share data and wrap web server interaction in services.
- Extend HTML and do DOM manipulation in directives.
- make Controllers as "thin" as possible.
Using Controllers Correctly
var a = function a(){ | |
this.x = 1; | |
return this; | |
} | |
var l = { | |
x:1 | |
}; | |
a.prototype.inc = function(){ return this.x+1; } | |
l.inc = function(){ return this.x+1; } |
// Send cookies for the socket.io handshake (sails.js) | |
// Based on https://gist.github.com/jfromaniello/4087861 | |
// Socket.io open ticket (started by jfromaniello): | |
// https://github.com/LearnBoost/socket.io-client/pull/512 | |
var io = require('socket.io-client'); | |
var request = require('request'); | |
var xhr = require('socket.io-client/node_modules/xmlhttprequest'); | |
var xhrOriginal = require('xmlhttprequest'); |
chdir('/var/www/website'); | |
$matchingTable = 'sometable'; | |
$regex = 'SELECT(\n|\s|\w|.)*?(?='.$matchingTable.')(\n|\s|\w|.)*?(?=(\'|");)'; // could change to update or delete | |
$filepaths = glob('*.*'); | |
foreach($filepaths as $filepath){ | |
if(!file_exists(realpath($filepath))){ | |
echo $filepath.PHP_EOL; | |
continue; | |
} |
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc | |
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/ | |
// author: Pawel Kozlowski | |
var myApp = angular.module('myApp', []); | |
//service style, probably the simplest one | |
myApp.service('helloWorldFromService', function() { | |
this.sayHello = function() { | |
return "Hello, World!" |
var app; | |
app = (function(){ | |
var myPrivateVariable = "my private content"; | |
var application = { | |
init: function(){ | |
console.log(myPrivateVariable); | |
}, |
// UX indicator Main class | |
var UX = function (wrapperId){ | |
this.wrapperId = wrapperId; | |
this.type = form; | |
this.type.parent = this; | |
this.indicator = '<div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div>'; | |
this.errorWrapper = '<div class="alert alert-error" />'; | |
} | |
UX.prototype.initInidcator = function(id){ |
/** | |
credits to: http://stackoverflow.com/questions/1134976/how-may-i-sort-a-list-alphabetically-using-jquery | |
: http://stackoverflow.com/questions/278089/javascript-to-sort-contents-of-select-element | |
and a little hacks there by 3emad | |
**/ | |
function sortUnorderedOption(select,callback_fun) { | |
selElem = document.getElementById(select); | |
var tmpAry = new Array(); | |
for (var i=0;i<selElem.options.length;i++) { |
/* | |
* showed in chrome network posted the same value and returned the same response | |
* the following code will call action "getBar" twice | |
* $.post("example.com",{action:'getFoo'},function(data){},"json"); | |
* $.post("example.com",{action:'getBar'},function(data){},"json"); | |
* | |
* in google chrome network tab, it will show that getFoo is ignored and getBar was called twice, though | |
* the object response are correct on the javascript end. | |
* | |
* work around to this bug: |
/* | |
* // the following example failed to keep the last index. | |
* | |
* temp = selElem.options[0]; | |
* selElem.options[0] = selElem.options[1]; | |
* selElem.options[1] = temp | |
* return; | |
*/ | |
var dash = selElem.options[0]; | |
var all = selElem.options[1]; |