Created
May 19, 2016 18:03
-
-
Save carolina-vallejo/a9093b140c218b838a5f252b6f8cbc43 to your computer and use it in GitHub Desktop.
mylibraryjs, started JS library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var configs = { | |
wrap: '#output', | |
data: { | |
labels: ['one', 'two', 'three'], | |
values1: [5, 7, 9], | |
values2: [10, 14, 18] | |
} | |
}; | |
var thelibrary = Mylibrary(configs); | |
thelibrary.fnt(); | |
thelibrary.fnt2(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Javascript library for .... | |
* | |
* @version $Revision: 1 $$Date:: 2016-04-19 #$ | |
* @author Carolina Vallejo <[email protected]> | |
* @copyright Copyright(c) 2016 to the present, Carolina Vallejo | |
*/ | |
(function(global) { | |
'use strict'; | |
/// Set Mylibrary global object /// | |
if (!global.Mylibrary) | |
global.Mylibrary = Mylibrary; | |
function Mylibrary(config) { | |
//default configs.. | |
var cfg = {}; | |
cfg.wrap = 'body'; | |
cfg.message = 'DATA IS: '; | |
cfg.data = { | |
'val': 1, | |
'val': 0 | |
}; | |
//------------------------- | |
// setconfigs | |
var setconfigs = function() { | |
if (!config) { | |
return; | |
} | |
//--rewrite configs | |
for (var op in config) { | |
if (config.hasOwnProperty(op)) { | |
if (cfg.hasOwnProperty(op)) { | |
cfg[op] = config[op]; | |
} | |
} | |
} | |
}; | |
setconfigs(); | |
//------------------------- | |
// dataprocess | |
var dataprocess = (function() { | |
for (var i in cfg.data) { | |
cfg.message += ' ' + cfg.data[i]; | |
} | |
})(); | |
//------------------------- | |
// returned functions | |
return { | |
fnt: function() { | |
$(cfg.wrap).text(cfg.message); | |
}, | |
fnt2: function() { | |
$(cfg.wrap).append('<br> ... and another function!'); | |
} | |
} //---- end return | |
} //---> end Mylibrary() | |
})(typeof global === 'undefined' ? window : global); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>config js library</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script> | |
<script src="main.js"></script> | |
<script src="milibrary.js"></script> | |
</head> | |
<body> | |
<div id="output"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment