Commit 44f22182 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Add requirecss plugin, adjust platform extensions, remove extension.addCss method.

parent 78aa7b40
......@@ -4,6 +4,7 @@
server.socket_host = "0.0.0.0"
server.socket_port = 4282
server.thread_pool = 10
server.max_request_body_size = 262144000
# reloads the program on script changes
engine.autoreload.on = True
define(["vispa/extensions", "./view", "./prefs"], function(extensions, CodeEditorView, Prefs) {
define(["vispa/extensions", "./view", "./prefs", "css!../css/styles"],
function(extensions, CodeEditorView, Prefs) {
var CodeEditorExtension = extensions.Extension._extend({
......@@ -43,9 +44,6 @@ define(["vispa/extensions", "./view", "./prefs"], function(extensions, CodeEdito
for (var i = 0; i < this.fileExtensions.length; i++) {
this.addFileHandler(this.fileExtensions[i], openFunction);
}
// add our css file
this.addCss("styles.css");
}
});
......
//TODO: add some text
//***
define(["vispa/extensions", "vispa/views/center", "jquery"], function(Extensions, CenterView, $) {
define(["vispa/extensions", "vispa/views/center", "jquery", "css!../css/style"],
function(Extensions, CenterView, $, x) {
//TODO: Modify text below
// we define an extension by inheriting/extending the extension base class
// definition in vispa.Extension
......@@ -81,9 +82,6 @@ define(["vispa/extensions", "vispa/views/center", "jquery"], function(Extensions
self.createInstance(workspaceId, DemoView);
}
});
// add our main css file
this.addCss("style.css");
}
});
......
define(["vispa/extensions", "./views", "./shortcuts"], function(extensions, FileViews, Shortcuts) {
define([
"vispa/extensions",
"./views",
"./shortcuts",
"css!../css/base/base",
"css!../css/base/file-icons",
"css!../css/base/pathbar",
"css!../css/base/views/symbol/symbol",
"css!../css/base/views/table/table",
], function(extensions, FileViews, Shortcuts) {
var FileExtension = extensions.Extension._extend({
init: function init() {
init._super.call(this, "file");
......@@ -113,13 +122,6 @@ define(["vispa/extensions", "./views", "./shortcuts"], function(extensions, File
self.createInstance(workspaceId, FileViews.Browser, args);
}
});
// add our css files
this.addCss("base/base.css");
this.addCss("base/file-icons.css");
this.addCss("base/pathbar.css");
this.addCss("base/views/symbol/symbol.css");
this.addCss("base/views/table/table.css");
}
});
......
define(["vispa/extensions", "vispa/views/center", "require"], function(Extensions, CenterView, require) {
define([
"vispa/extensions",
"vispa/views/center",
"require",
"css!../css/styles"
], function(Extensions, CenterView, require) {
var TerminalExtension = Extensions.Extension._extend({
......@@ -28,9 +33,6 @@ define(["vispa/extensions", "vispa/views/center", "require"], function(Extension
});//.addMenuEntry("Show Dummy Dialog", function(workspaceId) {
//self.createInstance(workspaceId, DummyDialogView);
//});
// add our css file
this.addCss("styles.css");
}
});
......
......@@ -812,23 +812,6 @@ define(["jquery", "emitter", "vispa/module", "vispa/ui"], function($, Emitter, M
return this;
},
/**
* Adds a link tag for a css file to the page head.
*
* @param {string} file - The name of a css file relative to the extensions "static/css" folder.
* @returns {this}
*/
addCss: function(file) {
// append a css file ref to the global head tag
// the file will be relative to static/css
$("<link>")
.attr("rel", "stylesheet")
.attr("href", this.static("css", file))
.appendTo("head");
return this;
},
// returns a path relativ to the extension's static root
static: function() {
var args = Array.prototype.slice.call(arguments);
......
/*
* Require-CSS RequireJS css! loader plugin
* 0.1.8
* Guy Bedford 2014
* MIT
*/
/*
*
* Usage:
* require(['css!./mycssFile']);
*
* Tested and working in (up to latest versions as of March 2013):
* Android
* iOS 6
* IE 6 - 10
* Chome 3 - 26
* Firefox 3.5 - 19
* Opera 10 - 12
*
* browserling.com used for virtual testing environment
*
* Credit to B Cavalier & J Hann for the IE 6 - 9 method,
* refined with help from Martin Cermak
*
* Sources that helped along the way:
* - https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent
* - http://www.phpied.com/when-is-a-stylesheet-really-loaded/
* - https://github.com/cujojs/curl/blob/master/src/curl/plugin/css.js
*
*/
define(function() {
//>>excludeStart('excludeRequireCss', pragmas.excludeRequireCss)
if (typeof window == 'undefined')
return { load: function(n, r, load){ load() } };
var head = document.getElementsByTagName('head')[0];
var engine = window.navigator.userAgent.match(/Trident\/([^ ;]*)|AppleWebKit\/([^ ;]*)|Opera\/([^ ;]*)|rv\:([^ ;]*)(.*?)Gecko\/([^ ;]*)|MSIE\s([^ ;]*)|AndroidWebKit\/([^ ;]*)/) || 0;
// use <style> @import load method (IE < 9, Firefox < 18)
var useImportLoad = false;
// set to false for explicit <link> load checking when onload doesn't work perfectly (webkit)
var useOnload = true;
// trident / msie
if (engine[1] || engine[7])
useImportLoad = parseInt(engine[1]) < 6 || parseInt(engine[7]) <= 9;
// webkit
else if (engine[2] || engine[8])
useOnload = false;
// gecko
else if (engine[4])
useImportLoad = parseInt(engine[4]) < 18;
//>>excludeEnd('excludeRequireCss')
//main api object
var cssAPI = {};
//>>excludeStart('excludeRequireCss', pragmas.excludeRequireCss)
cssAPI.pluginBuilder = './css-builder';
// <style> @import load method
var curStyle, curSheet;
var createStyle = function () {
curStyle = document.createElement('style');
head.appendChild(curStyle);
curSheet = curStyle.styleSheet || curStyle.sheet;
}
var ieCnt = 0;
var ieLoads = [];
var ieCurCallback;
var createIeLoad = function(url) {
curSheet.addImport(url);
curStyle.onload = function(){ processIeLoad() };
ieCnt++;
if (ieCnt == 31) {
createStyle();
ieCnt = 0;
}
}
var processIeLoad = function() {
ieCurCallback();
var nextLoad = ieLoads.shift();
if (!nextLoad) {
ieCurCallback = null;
return;
}
ieCurCallback = nextLoad[1];
createIeLoad(nextLoad[0]);
}
var importLoad = function(url, callback) {
if (!curSheet || !curSheet.addImport)
createStyle();
if (curSheet && curSheet.addImport) {
// old IE
if (ieCurCallback) {
ieLoads.push([url, callback]);
}
else {
createIeLoad(url);
ieCurCallback = callback;
}
}
else {
// old Firefox
curStyle.textContent = '@import "' + url + '";';
var loadInterval = setInterval(function() {
try {
curStyle.sheet.cssRules;
clearInterval(loadInterval);
callback();
} catch(e) {}
}, 10);
}
}
// <link> load method
var linkLoad = function(url, callback) {
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
if (useOnload)
link.onload = function() {
link.onload = function() {};
// for style dimensions queries, a short delay can still be necessary
setTimeout(callback, 7);
}
else
var loadInterval = setInterval(function() {
for (var i = 0; i < document.styleSheets.length; i++) {
var sheet = document.styleSheets[i];
if (sheet.href == link.href) {
clearInterval(loadInterval);
return callback();
}
}
}, 10);
link.href = url;
head.appendChild(link);
}
//>>excludeEnd('excludeRequireCss')
cssAPI.normalize = function(name, normalize) {
if (name.substr(name.length - 4, 4) == '.css')
name = name.substr(0, name.length - 4);
return normalize(name);
}
//>>excludeStart('excludeRequireCss', pragmas.excludeRequireCss)
cssAPI.load = function(cssId, req, load, config) {
(useImportLoad ? importLoad : linkLoad)(req.toUrl(cssId + '.css'), load);
}
//>>excludeEnd('excludeRequireCss')
return cssAPI;
});
......@@ -64,6 +64,11 @@
"vendor/bootstrap/plugins/select/bootstrap.select": ["bootstrap"],
"vendor/bootstrap/plugins/slider/bootstrap.slider": ["bootstrap"],
"vendor/bootstrap/plugins/fileinput/bootstrap.fileinput": ["bootstrap"]
},
map: {
"*": {
css: "${base_static}vendor/requirejs/plugins/require-css.js"
}
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment