Skip to content

Commit

Permalink
Utils moved to Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
bcinarli committed Nov 27, 2015
1 parent de0209b commit 27d539a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 59 deletions.
1 change: 1 addition & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link rel="stylesheet" href="../dist/uxrocket.modal.css" />

<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<script src="../bower_components/uxrocket.factory/dist/uxrocket.factory.js"></script>
<script src="../lib/uxrocket.modal.js"></script>

<script>
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ gulp.task('watch', ['csslint', 'sass', 'lint', 'scripts', 'mocha'], function() {
gulp.watch(['package.json', 'bower.json'], ['sass', 'scripts']);
});

gulp.task('default', ['watch']);
gulp.task('default', ['watch', 'connect']);
79 changes: 21 additions & 58 deletions lib/uxrocket.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
instance = 1,

overlay = '<div id="uxr-modal-overlay"></div>',
content = '<div id="{{id}}" class="uxr-modal-container uxr-modal-loading">' +
' <div class="uxr-modal-drag uxr-modal-hide"></div>' +
' <div class="uxr-modal-content">' +
' <div class="uxr-modal-loaded-content"></div>' +
content = '<div id="{{id}}" class="{{container}} {{loading}}">' +
' <div class="{{drag}} {{hide}}"></div>' +
' <div class="{{content}}">' +
' <div class="{{loadedContent}}"></div>' +
' </div>' +
' <a href="#" class="uxr-modal-close uxr-modal-hide"></a>' +
' <a href="#" class="{{close}} {{hide}}"></a>' +
'</div>',
openedInstances = {},

Expand Down Expand Up @@ -89,7 +89,9 @@
close: 'close',
hide: 'hide'
}
};
},

utils = new uxrPluginUtils({ns: ns});

var Modal = function(el, options, selector) {
this._name = rocketName;
Expand Down Expand Up @@ -200,7 +202,17 @@
Modal.prototype.prepare = function() {
var css = {},
$overlay = $('#uxr-modal-overlay'),
_content = content.replace('{{id}}', 'uxr-modal-instance-' + this._instance),
data = {
id: 'uxr-modal-instance-' + this._instance,
container: utils.getClassname('container'),
loading: utils.getClassname('loading'),
drag: utils.getClassname('drag'),
hide: utils.getClassname('hide'),
content: utils.getClassname('content'),
loadedContent: utils.getClassname('loadedContent'),
close: utils.getClassname('close')
},
_content = utils.render(content, data),
_appendTo = 'body';

this.emitEvent('start');
Expand Down Expand Up @@ -336,7 +348,7 @@

modal.close(this);

if(this._direct){
if(this._direct) {
this.removeContent();
}

Expand Down Expand Up @@ -546,55 +558,6 @@
}
};

var utils = {
callback: function(fn) {
// if callback string is function call it directly
if(typeof fn === 'function') {
fn.apply(this);
}

// if callback defined via data-attribute, call it via new Function
else {
if(fn !== false) {
var func = new Function('return ' + fn);
func();
}
}
},

escapeSelector: function(selector) {
var is_ID = selector.charAt(0) === '#',
re = /([ !"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g;

return is_ID ? '#' + selector.substring(1).replace(re, '\\$1') : selector;
},

getStringVariable: function(str) {
var val;
// check if it is chained
if(str.indexOf('.') > -1) {
var chain = str.split('.'),
chainVal = window[chain[0]];

for(var i = 1; i < chain.length; i++) {
chainVal = chainVal[chain[i]];
}

val = chainVal;
}

else {
val = window[str];
}

return val;
},

getClassname: function(which) {
return ns.prefix + ns.name + '-' + ns.classes[which];
}
};

ux = $.fn.modal = $.fn.uxrmodal = $.uxrmodal = function(options) {
var selector = this.selector;

Expand Down Expand Up @@ -643,7 +606,7 @@
return openedInstances;
};

ux.version = '1.3.3';
ux.version = '1.4.0';

ux.settings = defaults;
}));
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script src="../node_modules/chai/chai.js"></script>

<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<script src="../bower_components/uxrocket.factory/dist/uxrocket.factory.js"></script>
<script src="../dist/uxrocket.modal.js" data-cover></script>
<script>
mocha.setup('bdd');
Expand Down

0 comments on commit 27d539a

Please sign in to comment.