Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make addClass, removeClass and toggleClass actually refresh styes

  • Loading branch information...
commit 4f7d88758a8583453b7cd57d9af7fcfc4fe48f7b 1 parent cd8214b
Jacob Waller authored
2  Jakefile.js
View
@@ -104,7 +104,7 @@ task('annotate-source', [], function(params) {
return 'lib/kranium-src/' + p + '.js';
}).join(" ") + ' > docs/annotated-source.html';
- //console.log(cmd);
+ console.log(cmd);
exec(cmd, function(error, stdout, stderr){
sys.puts(stderr); //console.log(error, stdout, stderr);
42 lib/command/watch.js
View
@@ -25,6 +25,10 @@ var client, server;
function watch(opts){
'Start watching'.log();
+
+ Bootstrap.createAppBootstrap(opts);
+
+
// Create server
var interval = setInterval(processChanges, 100),
appsocket = net.createServer(function(stream) {
@@ -255,4 +259,40 @@ function processChanges(){
});
}
});
-}
+}
+
+var Bootstrap = {
+ appKraniumDir: 'Resources/kranium',
+ bootstrapTemplate: function(o){
+ return [
+ '/* BEWARE - generated file ahead */',
+ '(function(global){',
+ ' if(global.BOOTSTRAPPED){ return; }',
+
+ ' global.DEBUG = '+o.debug+';',
+ ' global.USE_BACKBONE = '+o.backbone+';',
+ ' global.TEST = '+o.test+';',
+ ' global.BOOTSTRAPPED = true;',
+
+ 'if(K.is.ios){',
+ ' K.watch("'+o.ip+'", "'+o.port+'");',
+ '}',
+ '})(this);'
+ ].join("\n");
+ },
+
+ createAppBootstrap: function(opts){
+ var me = this,
+ filename = 'Resources/kranium/kranium-generated-bootstrap.js';
+
+ async.series({
+ ip: opts.ip ? function(callback){ callback(null, opts.ip); } : function(callback){ require('../getnetworkip')(function(err, ip){ callback(null, ip||'127.0.0.1'); }); }
+ }, function(err, res){
+ if(path.existsSync(filename)){
+ fs.unlinkSync(filename);
+ }
+ fs.writeFileSync(filename, me.bootstrapTemplate(res.extendIf(opts)));
+ 'Refreshed bootstrap'.log();
+ });
+ }
+};
39 lib/kranium-src/core.js
View
@@ -87,6 +87,15 @@ var reTiObject = /^(\[object Ti|\[Ti\.)/,
*/
function arrayify(o){ return o == null ? [] : (Array.isArray(o) ? o : [o]); }
+ function refreshStyle(el){
+ var _opts = el._opts,
+ styles = K.getStyle(el, _opts && _opts.type, _opts && _opts._type);
+
+ for(var prop in styles){
+ el[prop] = styles[prop];
+ }
+ }
+
/**
* Kranium object constructory-thingy
*
@@ -462,9 +471,12 @@ var reTiObject = /^(\[object Ti|\[Ti\.)/,
* @returns {Boolean}
*/
addClass: function(name){
- return this.each(function(){
- !$(this).hasClass(name) && (this.className += (this.className ? ' ' : '') + name);
- });
+ if(typeof name === 'string'){
+ return this.each(function(){
+ !$(this).hasClass(name) && (this.className += (this.className ? ' ' : '') + name);
+ refreshStyle(this);
+ });
+ }
},
/**
@@ -474,9 +486,12 @@ var reTiObject = /^(\[object Ti|\[Ti\.)/,
* @returns {Boolean}
*/
removeClass: function(name){
- return this.each(function(){
- this.className = this.className.replace(classRE(name), ' ').trim();
- });
+ if(typeof name === 'string'){
+ return this.each(function(){
+ this.className = this.className.replace(classRE(name), ' ').trim();
+ refreshStyle(this);
+ });
+ }
},
/**
@@ -487,10 +502,14 @@ var reTiObject = /^(\[object Ti|\[Ti\.)/,
* @returns {Boolean}
*/
toggleClass: function(name, when){
- return this.each(function(){
- ((when !== undefined && !when) || $(this).hasClass(name)) ?
- $(this).removeClass(name) : $(this).addClass(name);
- });
+ if(typeof name === 'string'){
+ return this.each(function(){
+ ((when !== undefined && !when) || $(this).hasClass(name)) ?
+ $(this).removeClass(name) : $(this).addClass(name);
+
+ refreshStyle(this);
+ });
+ }
},
/**
8 lib/kranium-src/klass.js
View
@@ -11,6 +11,14 @@
if(global.DEBUG || liveKlass || !(klass = K.classes[name])){
if(!liveKlass){ K.loadStyle(name); }
//klass = liveKlass||(exports = {}, Ti.include('kui/' + name + '.js'), exports.Class);
+
+ /*
+ klass = liveKlass || ((exp = require('kui/' + name)) && (typeof exp === 'object' && (typeof exp.Class === 'function' ? exp.Class(K) : exp.Class)) || (typeof exp === 'function' && exp(K)));
+ if(typeof klass.extend !== 'function'){
+ klass = K.classes[klass['extends'] || klass.ext].extend(klass);
+ }
+ */
+
klass = liveKlass || (require('kui/' + name)).Class;
cls = klass.prototype.className;
klass.prototype.className = cls ? cls + ' ' + name : name;
Please sign in to comment.
Something went wrong with that request. Please try again.