Skip to content

Commit

Permalink
converted plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ittayd committed Mar 16, 2012
1 parent 95fc442 commit 9c56247
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
12 changes: 10 additions & 2 deletions core/js/options.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
define(function(require) {
var $ = require('jquery'),
_ = require('underscore'),
ignoredAttrs = ['src', 'type'],
slydes = slydes || {}


var attrs = {}
_.each(Slydes.script.attributes, function(attr) {
if(!_.contains(ignoredAttrs, attr.name)) {
attrs[attr.name] = attr.value;
}
});
return $.extend({// defaults
plugins: ["core-theme", "prettify"]
}, slydes)
}, slydes, attrs)
})
// jQuery.extend(Slydes, {
// options: (function() {
Expand Down
9 changes: 7 additions & 2 deletions core/js/slydes.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/**
* Main entry point
*/
var SLYDES_JS = SLYDES_JS || "slydes";
var Slydes = {
SLYDES_JS: "slydes",
};


(function() {
var scripts = document.getElementsByTagName('script'),
slydesjs = undefined

for (var i = 0; i < scripts.length; i++) {
if (scripts[i].src.indexOf(SLYDES_JS) != -1) {
if (scripts[i].src.indexOf(Slydes.SLYDES_JS) != -1) {
slydesjs = scripts[i]
}
}
Expand All @@ -18,6 +21,8 @@ var SLYDES_JS = SLYDES_JS || "slydes";
alert(msg)
throw new Error(msg)
}

Slydes.script = slydesjs;

var path = slydesjs.src.split('?')[0], // remove any ?query
baseUrl = path.split('/').slice(0, -3).join('/') + '/', // go up 2 levels
Expand Down
30 changes: 26 additions & 4 deletions core/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
/**
* Misc. utilities. Some of these are required before loading the jquery support
*/
define(function(require) {
return {
array: function array(arg) {
if (arg === undefined) {
return [];
}
if (Array.isArray(arg)) {
return arg;
}
if (typeof(arg) == 'string') {
return arg.split(",");
}
throw "Argument " + arg + " typeof " + typeof(arg) + " cannot be converter to an array";
},

parentDir: function parentDir(path) {
return path.split('/').slice(0, -1).join('/') + '/'
}
}
})
/*
Slydes = jQuery.extend(Slydes, {
parseQuery: function(first, second) {
var query = typeof first === 'string' ? first : window.location.search,
Expand All @@ -24,7 +45,7 @@ Slydes = jQuery.extend(Slydes, {
/**
* Accoring to: http://yearofmoo.com/2011/03/cross-browser-stylesheet-preloading/
*/
loadCss: function(url, options, onload) {
/* loadCss: function(url, options, onload) {
var onload = typeof options == 'function' ? options : onload,
options = typeof options == 'function' ? {} : (options || {}),
options = jQuery.extend({idprefix: 'css-load-track-id', delay: 10, limit: 200}, options),
Expand All @@ -41,7 +62,7 @@ Slydes = jQuery.extend(Slydes, {
/*if (this.isEventSupported(link, 'load')) {
link.onload = success
} else {*/
if (typeof onload == 'function') {
/* if (typeof onload == 'function') {
var counter = 0,
checker = function() {
var stylesheets = document.styleSheets
Expand Down Expand Up @@ -69,7 +90,7 @@ Slydes = jQuery.extend(Slydes, {
checker()
}
/*}*/
},
/* },
notice: function(msg) {
jQuery.gritter.add({title: 'Notice', text: msg})
Expand All @@ -80,7 +101,7 @@ Slydes = jQuery.extend(Slydes, {
*
* doesn't work in some cases (e.g, returns true for 'load' events on <link> elements in FF4)
*/
isEventSupported: (function(){
/* isEventSupported: (function(){
var win = this
var cache = {}
Expand Down Expand Up @@ -130,3 +151,4 @@ jQuery.fn.equals = function(other) {
Slydes.loadScript(Slydes.base + '../lib/jquery-gritter/js/jquery.gritter.js')
Slydes.loadCss(Slydes.base + '../lib/jquery-gritter/css/jquery.gritter.css')
*/
2 changes: 1 addition & 1 deletion examples/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>Slydes</title>
<script src="../core/js/slydes.js?prettify=scala"></script>
<script src="../core/js/slydes.js" prettify="scala"></script>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans:regular,semibold,italic,italicsemibold|Droid+Sans+Mono">
<!-- <link rel="stylesheet" type="text/css" href="style.css"> --> </head>
<body>
Expand Down
9 changes: 6 additions & 3 deletions plugins/prettify/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
define(function(require) {
define(function(require, exports, module) {
var $ = require('jquery'),
_ = require('underscore'),
utils = require('utils'),
options = require('options')

require("./lib/prettify");
require("css!./lib/prettify.css");

if (options.prettify) {
var files = _.map(options.prettify, function(lang) {return "./lib/lang-" + lang + ".js"})
var base = utils.parentDir(module.uri),
files = _.map(utils.array(options.prettify), function(lang) {return base + "lib/lang-" + lang + ".js"})

require(files, function() {
$(document).ready(prettyPring);
$(document).ready(prettyPrint);
})
}

Expand Down

0 comments on commit 9c56247

Please sign in to comment.