mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
Merge pull request #557 from redhog/master
Templating system built on top of EJS and plugin installer
This commit is contained in:
commit
9ecd864ac6
46 changed files with 1526 additions and 1774 deletions
|
@ -233,14 +233,16 @@ require.setGlobalKeyPath("require");\n\
|
|||
|
||||
iframeHTML.push(doctype);
|
||||
iframeHTML.push("<html><head>");
|
||||
iframeHTML.push('<script type="text/javascript" src="../static/js/jquery.js"></script>');
|
||||
|
||||
hooks.callAll("aceInitInnerdocbodyHead", {
|
||||
iframeHTML: iframeHTML
|
||||
});
|
||||
|
||||
// For compatability's sake transform in and out.
|
||||
for (var i = 0, ii = iframeHTML.length; i < ii; i++) {
|
||||
iframeHTML[i] = JSON.stringify(iframeHTML[i]);
|
||||
}
|
||||
hooks.callAll("aceInitInnerdocbodyHead", {
|
||||
iframeHTML: iframeHTML
|
||||
});
|
||||
for (var i = 0, ii = iframeHTML.length; i < ii; i++) {
|
||||
iframeHTML[i] = JSON.parse(iframeHTML[i]);
|
||||
}
|
||||
|
@ -262,6 +264,11 @@ require.setGlobalKeyPath("require");\n\
|
|||
// Inject my plugins into my child.
|
||||
iframeHTML.push('\
|
||||
<script type="text/javascript">\
|
||||
parent_req = require("./pluginfw/parent_require.js");\
|
||||
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/hooks");\
|
||||
parent_req.getRequirementFromParent(require, "ep_etherpad-lite/static/js/pluginfw/plugins");\
|
||||
parent_req.getRequirementFromParent(require, "./pluginfw/hooks");\
|
||||
parent_req.getRequirementFromParent(require, "./pluginfw/plugins");\
|
||||
require.define("/plugins", null);\n\
|
||||
require.define("/plugins.js", function (require, exports, module) {\
|
||||
module.exports = require("ep_etherpad-lite/static/js/plugins");\
|
||||
|
|
|
@ -844,7 +844,7 @@ function Ace2Inner(){
|
|||
var cmdArgs = Array.prototype.slice.call(arguments, 1);
|
||||
if (CMDS[cmd])
|
||||
{
|
||||
inCallStack(cmd, function()
|
||||
inCallStackIfNecessary(cmd, function()
|
||||
{
|
||||
fastIncorp(9);
|
||||
CMDS[cmd].apply(CMDS, cmdArgs);
|
||||
|
@ -854,7 +854,7 @@ function Ace2Inner(){
|
|||
|
||||
function replaceRange(start, end, text)
|
||||
{
|
||||
inCallStack('replaceRange', function()
|
||||
inCallStackIfNecessary('replaceRange', function()
|
||||
{
|
||||
fastIncorp(9);
|
||||
performDocumentReplaceRange(start, end, text);
|
||||
|
@ -1155,7 +1155,7 @@ function Ace2Inner(){
|
|||
return;
|
||||
}
|
||||
|
||||
inCallStack("idleWorkTimer", function()
|
||||
inCallStackIfNecessary("idleWorkTimer", function()
|
||||
{
|
||||
|
||||
var isTimeUp = newTimeLimit(250);
|
||||
|
@ -2043,6 +2043,7 @@ function Ace2Inner(){
|
|||
return [lineNum, col];
|
||||
}
|
||||
}
|
||||
editorInfo.ace_getLineAndCharForPoint = getLineAndCharForPoint;
|
||||
|
||||
function createDomLineEntry(lineString)
|
||||
{
|
||||
|
@ -2328,6 +2329,7 @@ function Ace2Inner(){
|
|||
var cs = builder.toString();
|
||||
performDocumentApplyChangeset(cs);
|
||||
}
|
||||
editorInfo.ace_performDocumentApplyAttributesToRange = performDocumentApplyAttributesToRange;
|
||||
|
||||
function buildKeepToStartOfRange(builder, start)
|
||||
{
|
||||
|
@ -2853,6 +2855,7 @@ function Ace2Inner(){
|
|||
currentCallStack.selectionAffected = true;
|
||||
}
|
||||
}
|
||||
editorInfo.ace_performSelectionChange = performSelectionChange;
|
||||
|
||||
// Change the abstract representation of the document to have a different selection.
|
||||
// Should not rely on the line representation. Should not affect the DOM.
|
||||
|
@ -3280,7 +3283,7 @@ function Ace2Inner(){
|
|||
|
||||
function handleClick(evt)
|
||||
{
|
||||
inCallStack("handleClick", function()
|
||||
inCallStackIfNecessary("handleClick", function()
|
||||
{
|
||||
idleWorkTimer.atMost(200);
|
||||
});
|
||||
|
@ -3602,7 +3605,7 @@ function Ace2Inner(){
|
|||
|
||||
var stopped = false;
|
||||
|
||||
inCallStack("handleKeyEvent", function()
|
||||
inCallStackIfNecessary("handleKeyEvent", function()
|
||||
{
|
||||
|
||||
if (type == "keypress" || (isTypeForSpecialKey && keyCode == 13 /*return*/ ))
|
||||
|
@ -4689,7 +4692,7 @@ function Ace2Inner(){
|
|||
}
|
||||
|
||||
// click below the body
|
||||
inCallStack("handleOuterClick", function()
|
||||
inCallStackIfNecessary("handleOuterClick", function()
|
||||
{
|
||||
// put caret at bottom of doc
|
||||
fastIncorp(11);
|
||||
|
@ -4726,6 +4729,54 @@ function Ace2Inner(){
|
|||
else $(elem).removeClass(elem, className);
|
||||
}
|
||||
|
||||
function setup()
|
||||
{
|
||||
doc = document; // defined as a var in scope outside
|
||||
inCallStackIfNecessary("setup", function()
|
||||
{
|
||||
var body = doc.getElementById("innerdocbody");
|
||||
root = body; // defined as a var in scope outside
|
||||
if (browser.mozilla) addClass(root, "mozilla");
|
||||
if (browser.safari) addClass(root, "safari");
|
||||
if (browser.msie) addClass(root, "msie");
|
||||
if (browser.msie)
|
||||
{
|
||||
// cache CSS background images
|
||||
try
|
||||
{
|
||||
doc.execCommand("BackgroundImageCache", false, true);
|
||||
}
|
||||
catch (e)
|
||||
{ /* throws an error in some IE 6 but not others! */
|
||||
}
|
||||
}
|
||||
setClassPresence(root, "authorColors", true);
|
||||
setClassPresence(root, "doesWrap", doesWrap);
|
||||
|
||||
initDynamicCSS();
|
||||
|
||||
enforceEditability();
|
||||
|
||||
// set up dom and rep
|
||||
while (root.firstChild) root.removeChild(root.firstChild);
|
||||
var oneEntry = createDomLineEntry("");
|
||||
doRepLineSplice(0, rep.lines.length(), [oneEntry]);
|
||||
insertDomLines(null, [oneEntry.domInfo], null);
|
||||
rep.alines = Changeset.splitAttributionLines(
|
||||
Changeset.makeAttribution("\n"), "\n");
|
||||
|
||||
bindTheEventHandlers();
|
||||
|
||||
});
|
||||
|
||||
scheduler.setTimeout(function()
|
||||
{
|
||||
parent.readyFunc(); // defined in code that sets up the inner iframe
|
||||
}, 0);
|
||||
|
||||
isSetUp = true;
|
||||
}
|
||||
|
||||
function focus()
|
||||
{
|
||||
window.focus();
|
||||
|
|
|
@ -465,7 +465,7 @@ if (!JSON)
|
|||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
throw new SyntaxError('JSON.parse');
|
||||
throw new SyntaxError('JSON.parse: ' + text);
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
|
|
@ -31,7 +31,6 @@ require('./farbtastic');
|
|||
require('./excanvas');
|
||||
JSON = require('./json2');
|
||||
require('./undo-xpopup');
|
||||
require('./prefixfree');
|
||||
|
||||
var chat = require('./chat').chat;
|
||||
var getCollabClient = require('./collab_client').getCollabClient;
|
||||
|
@ -42,7 +41,7 @@ var padeditbar = require('./pad_editbar').padeditbar;
|
|||
var padeditor = require('./pad_editor').padeditor;
|
||||
var padimpexp = require('./pad_impexp').padimpexp;
|
||||
var padmodals = require('./pad_modals').padmodals;
|
||||
var padsavedrevs = require('./pad_savedrevs').padsavedrevs;
|
||||
var padsavedrevs = require('./pad_savedrevs');
|
||||
var paduserlist = require('./pad_userlist').paduserlist;
|
||||
var padutils = require('./pad_utils').padutils;
|
||||
|
||||
|
@ -50,6 +49,50 @@ var createCookie = require('./pad_utils').createCookie;
|
|||
var readCookie = require('./pad_utils').readCookie;
|
||||
var randomString = require('./pad_utils').randomString;
|
||||
|
||||
var hooks = require('./pluginfw/hooks');
|
||||
|
||||
function createCookie(name, value, days, path)
|
||||
{
|
||||
if (days)
|
||||
{
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
var expires = "; expires=" + date.toGMTString();
|
||||
}
|
||||
else var expires = "";
|
||||
|
||||
if(!path)
|
||||
path = "/";
|
||||
|
||||
document.cookie = name + "=" + value + expires + "; path=" + path;
|
||||
}
|
||||
|
||||
function readCookie(name)
|
||||
{
|
||||
var nameEQ = name + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++)
|
||||
{
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function randomString()
|
||||
{
|
||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
var string_length = 20;
|
||||
var randomstring = '';
|
||||
for (var i = 0; i < string_length; i++)
|
||||
{
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum, rnum + 1);
|
||||
}
|
||||
return "t." + randomstring;
|
||||
}
|
||||
|
||||
function getParams()
|
||||
{
|
||||
var params = getUrlVars()
|
||||
|
@ -457,7 +500,7 @@ var pad = {
|
|||
guestPolicy: pad.padOptions.guestPolicy
|
||||
}, this);
|
||||
padimpexp.init(this);
|
||||
padsavedrevs.init(clientVars.initialRevisionList, this);
|
||||
padsavedrevs.init(this);
|
||||
|
||||
padeditor.init(postAceInit, pad.padOptions.view || {}, this);
|
||||
|
||||
|
@ -491,6 +534,7 @@ var pad = {
|
|||
if(padcookie.getPref("showAuthorshipColors") == false){
|
||||
pad.changeViewOption('showAuthorColors', false);
|
||||
}
|
||||
hooks.aCallAll("postAceInit");
|
||||
}
|
||||
},
|
||||
dispose: function()
|
||||
|
|
|
@ -449,7 +449,7 @@ var paddocbar = (function()
|
|||
handleResizePage: function()
|
||||
{
|
||||
// Side-step circular reference. This should be injected.
|
||||
var padsavedrevs = require('./pad_savedrevs').padsavedrevs;
|
||||
var padsavedrevs = require('./pad_savedrevs');
|
||||
padsavedrevs.handleResizePage();
|
||||
},
|
||||
hideLaterIfNoOtherInteraction: function()
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
var padutils = require('./pad_utils').padutils;
|
||||
var padeditor = require('./pad_editor').padeditor;
|
||||
var padsavedrevs = require('./pad_savedrevs').padsavedrevs;
|
||||
var padsavedrevs = require('./pad_savedrevs');
|
||||
|
||||
function indexOf(array, value) {
|
||||
for (var i = 0, ii = array.length; i < ii; i++) {
|
||||
|
@ -131,7 +131,7 @@ var padeditbar = (function()
|
|||
{
|
||||
self.toogleDropDown("importexport");
|
||||
}
|
||||
else if (cmd == 'save')
|
||||
else if (cmd == 'savedRevision')
|
||||
{
|
||||
padsavedrevs.saveNow();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
/**
|
||||
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
||||
* This helps other people to understand this code better and helps them to improve it.
|
||||
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copyright 2009 Google Inc.
|
||||
* Copyright 2012 Peter 'Pita' Martischka
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,507 +14,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var padutils = require('./pad_utils').padutils;
|
||||
var paddocbar = require('./pad_docbar').paddocbar;
|
||||
var pad;
|
||||
|
||||
var padsavedrevs = (function()
|
||||
{
|
||||
exports.saveNow = function(){
|
||||
pad.collabClient.sendMessage({"type": "SAVE_REVISION"});
|
||||
alert("This revision is now marked as a saved revision");
|
||||
}
|
||||
|
||||
function reversedCopy(L)
|
||||
{
|
||||
var L2 = L.slice();
|
||||
L2.reverse();
|
||||
return L2;
|
||||
}
|
||||
|
||||
function makeRevisionBox(revisionInfo, rnum)
|
||||
{
|
||||
var box = $('<div class="srouterbox">' + '<div class="srinnerbox">' + '<a href="javascript:void(0)" class="srname"><!-- --></a>' + '<div class="sractions"><a class="srview" href="javascript:void(0)" target="_blank">view</a> | <a class="srrestore" href="javascript:void(0)">restore</a></div>' + '<div class="srtime"><!-- --></div>' + '<div class="srauthor"><!-- --></div>' + '<img class="srtwirly" src="static/img/misc/status-ball.gif">' + '</div></div>');
|
||||
setBoxLabel(box, revisionInfo.label);
|
||||
setBoxTimestamp(box, revisionInfo.timestamp);
|
||||
box.find(".srauthor").html("by " + padutils.escapeHtml(revisionInfo.savedBy));
|
||||
var viewLink = '/ep/pad/view/' + pad.getPadId() + '/' + revisionInfo.id;
|
||||
box.find(".srview").attr('href', viewLink);
|
||||
var restoreLink = 'javascript:void(require('+JSON.stringify(module.id)+').padsavedrevs.restoreRevision(' + JSON.stringify(rnum) + ');';
|
||||
box.find(".srrestore").attr('href', restoreLink);
|
||||
box.find(".srname").click(function(evt)
|
||||
{
|
||||
editRevisionLabel(rnum, box);
|
||||
});
|
||||
return box;
|
||||
}
|
||||
|
||||
function setBoxLabel(box, label)
|
||||
{
|
||||
box.find(".srname").html(padutils.escapeHtml(label)).attr('title', label);
|
||||
}
|
||||
|
||||
function setBoxTimestamp(box, timestamp)
|
||||
{
|
||||
box.find(".srtime").html(padutils.escapeHtml(
|
||||
padutils.timediff(new Date(timestamp))));
|
||||
}
|
||||
|
||||
function getNthBox(n)
|
||||
{
|
||||
return $("#savedrevisions .srouterbox").eq(n);
|
||||
}
|
||||
|
||||
function editRevisionLabel(rnum, box)
|
||||
{
|
||||
var input = $('<input type="text" class="srnameedit"/>');
|
||||
box.find(".srnameedit").remove(); // just in case
|
||||
var label = box.find(".srname");
|
||||
input.width(label.width());
|
||||
input.height(label.height());
|
||||
input.css('top', label.position().top);
|
||||
input.css('left', label.position().left);
|
||||
label.after(input);
|
||||
label.css('opacity', 0);
|
||||
|
||||
function endEdit()
|
||||
{
|
||||
input.remove();
|
||||
label.css('opacity', 1);
|
||||
}
|
||||
var rev = currentRevisionList[rnum];
|
||||
var oldLabel = rev.label;
|
||||
input.blur(function()
|
||||
{
|
||||
var newLabel = input.val();
|
||||
if (newLabel && newLabel != oldLabel)
|
||||
{
|
||||
relabelRevision(rnum, newLabel);
|
||||
}
|
||||
endEdit();
|
||||
});
|
||||
input.val(rev.label).focus().select();
|
||||
padutils.bindEnterAndEscape(input, function onEnter()
|
||||
{
|
||||
input.blur();
|
||||
}, function onEscape()
|
||||
{
|
||||
input.val('').blur();
|
||||
});
|
||||
}
|
||||
|
||||
function relabelRevision(rnum, newLabel)
|
||||
{
|
||||
var rev = currentRevisionList[rnum];
|
||||
$.ajax(
|
||||
{
|
||||
type: 'post',
|
||||
url: '/ep/pad/saverevisionlabel',
|
||||
data: {
|
||||
userId: pad.getUserId(),
|
||||
padId: pad.getPadId(),
|
||||
revId: rev.id,
|
||||
newLabel: newLabel
|
||||
},
|
||||
success: success,
|
||||
error: error
|
||||
});
|
||||
|
||||
function success(text)
|
||||
{
|
||||
var newRevisionList = JSON.parse(text);
|
||||
self.newRevisionList(newRevisionList);
|
||||
pad.sendClientMessage(
|
||||
{
|
||||
type: 'revisionLabel',
|
||||
revisionList: reversedCopy(currentRevisionList),
|
||||
savedBy: pad.getUserName(),
|
||||
newLabel: newLabel
|
||||
});
|
||||
}
|
||||
|
||||
function error(e)
|
||||
{
|
||||
alert("Oops! There was an error saving that revision label. Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
var currentRevisionList = [];
|
||||
|
||||
function setRevisionList(newRevisionList, noAnimation)
|
||||
{
|
||||
// deals with changed labels and new added revisions
|
||||
for (var i = 0; i < currentRevisionList.length; i++)
|
||||
{
|
||||
var a = currentRevisionList[i];
|
||||
var b = newRevisionList[i];
|
||||
if (b.label != a.label)
|
||||
{
|
||||
setBoxLabel(getNthBox(i), b.label);
|
||||
}
|
||||
}
|
||||
for (var j = currentRevisionList.length; j < newRevisionList.length; j++)
|
||||
{
|
||||
var newBox = makeRevisionBox(newRevisionList[j], j);
|
||||
$("#savedrevs-scrollinner").append(newBox);
|
||||
newBox.css('left', j * REVISION_BOX_WIDTH);
|
||||
}
|
||||
var newOnes = (newRevisionList.length > currentRevisionList.length);
|
||||
currentRevisionList = newRevisionList;
|
||||
if (newOnes)
|
||||
{
|
||||
setDesiredScroll(getMaxScroll());
|
||||
if (noAnimation)
|
||||
{
|
||||
setScroll(desiredScroll);
|
||||
}
|
||||
|
||||
if (!noAnimation)
|
||||
{
|
||||
var nameOfLast = currentRevisionList[currentRevisionList.length - 1].label;
|
||||
displaySavedTip(nameOfLast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function refreshRevisionList()
|
||||
{
|
||||
for (var i = 0; i < currentRevisionList.length; i++)
|
||||
{
|
||||
var r = currentRevisionList[i];
|
||||
var box = getNthBox(i);
|
||||
setBoxTimestamp(box, r.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
var savedTipAnimator = padutils.makeShowHideAnimator(function(state)
|
||||
{
|
||||
if (state == -1)
|
||||
{
|
||||
$("#revision-notifier").css('opacity', 0).css('display', 'block');
|
||||
}
|
||||
else if (state == 0)
|
||||
{
|
||||
$("#revision-notifier").css('opacity', 1);
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
$("#revision-notifier").css('opacity', 0).css('display', 'none');
|
||||
}
|
||||
else if (state < 0)
|
||||
{
|
||||
$("#revision-notifier").css('opacity', 1);
|
||||
}
|
||||
else if (state > 0)
|
||||
{
|
||||
$("#revision-notifier").css('opacity', 1 - state);
|
||||
}
|
||||
}, false, 25, 300);
|
||||
|
||||
function displaySavedTip(text)
|
||||
{
|
||||
$("#revision-notifier .name").html(padutils.escapeHtml(text));
|
||||
savedTipAnimator.show();
|
||||
padutils.cancelActions("hide-revision-notifier");
|
||||
var hideLater = padutils.getCancellableAction("hide-revision-notifier", function()
|
||||
{
|
||||
savedTipAnimator.hide();
|
||||
});
|
||||
window.setTimeout(hideLater, 3000);
|
||||
}
|
||||
|
||||
var REVISION_BOX_WIDTH = 120;
|
||||
var curScroll = 0; // distance between left of revisions and right of view
|
||||
var desiredScroll = 0;
|
||||
|
||||
function getScrollWidth()
|
||||
{
|
||||
return REVISION_BOX_WIDTH * currentRevisionList.length;
|
||||
}
|
||||
|
||||
function getViewportWidth()
|
||||
{
|
||||
return $("#savedrevs-scrollouter").width();
|
||||
}
|
||||
|
||||
function getMinScroll()
|
||||
{
|
||||
return Math.min(getViewportWidth(), getScrollWidth());
|
||||
}
|
||||
|
||||
function getMaxScroll()
|
||||
{
|
||||
return getScrollWidth();
|
||||
}
|
||||
|
||||
function setScroll(newScroll)
|
||||
{
|
||||
curScroll = newScroll;
|
||||
$("#savedrevs-scrollinner").css('right', newScroll);
|
||||
updateScrollArrows();
|
||||
}
|
||||
|
||||
function setDesiredScroll(newDesiredScroll, dontUpdate)
|
||||
{
|
||||
desiredScroll = Math.min(getMaxScroll(), Math.max(getMinScroll(), newDesiredScroll));
|
||||
if (!dontUpdate)
|
||||
{
|
||||
updateScroll();
|
||||
}
|
||||
}
|
||||
|
||||
function updateScroll()
|
||||
{
|
||||
updateScrollArrows();
|
||||
scrollAnimator.scheduleAnimation();
|
||||
}
|
||||
|
||||
function updateScrollArrows()
|
||||
{
|
||||
$("#savedrevs-scrollleft").toggleClass("disabledscrollleft", desiredScroll <= getMinScroll());
|
||||
$("#savedrevs-scrollright").toggleClass("disabledscrollright", desiredScroll >= getMaxScroll());
|
||||
}
|
||||
var scrollAnimator = padutils.makeAnimationScheduler(function()
|
||||
{
|
||||
setDesiredScroll(desiredScroll, true); // re-clamp
|
||||
if (Math.abs(desiredScroll - curScroll) < 1)
|
||||
{
|
||||
setScroll(desiredScroll);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
setScroll(curScroll + (desiredScroll - curScroll) * 0.5);
|
||||
return true;
|
||||
}
|
||||
}, 50, 2);
|
||||
|
||||
var isSaving = false;
|
||||
|
||||
function setIsSaving(v)
|
||||
{
|
||||
isSaving = v;
|
||||
rerenderButton();
|
||||
}
|
||||
|
||||
function haveReachedRevLimit()
|
||||
{
|
||||
var mv = pad.getPrivilege('maxRevisions');
|
||||
return (!(mv < 0 || mv > currentRevisionList.length));
|
||||
}
|
||||
|
||||
function rerenderButton()
|
||||
{
|
||||
if (isSaving || (!pad.isFullyConnected()) || haveReachedRevLimit())
|
||||
{
|
||||
$("#savedrevs-savenow").css('opacity', 0.75);
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#savedrevs-savenow").css('opacity', 1);
|
||||
}
|
||||
}
|
||||
|
||||
var scrollRepeatTimer = null;
|
||||
var scrollStartTime = 0;
|
||||
|
||||
function setScrollRepeatTimer(dir)
|
||||
{
|
||||
clearScrollRepeatTimer();
|
||||
scrollStartTime = +new Date;
|
||||
scrollRepeatTimer = window.setTimeout(function f()
|
||||
{
|
||||
if (!scrollRepeatTimer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.scroll(dir);
|
||||
var scrollTime = (+new Date) - scrollStartTime;
|
||||
var delay = (scrollTime > 2000 ? 50 : 300);
|
||||
scrollRepeatTimer = window.setTimeout(f, delay);
|
||||
}, 300);
|
||||
$(document).bind('mouseup', clearScrollRepeatTimer);
|
||||
}
|
||||
|
||||
function clearScrollRepeatTimer()
|
||||
{
|
||||
if (scrollRepeatTimer)
|
||||
{
|
||||
window.clearTimeout(scrollRepeatTimer);
|
||||
scrollRepeatTimer = null;
|
||||
}
|
||||
$(document).unbind('mouseup', clearScrollRepeatTimer);
|
||||
}
|
||||
|
||||
var pad = undefined;
|
||||
var self = {
|
||||
init: function(initialRevisions, _pad)
|
||||
{
|
||||
pad = _pad;
|
||||
self.newRevisionList(initialRevisions, true);
|
||||
|
||||
$("#savedrevs-savenow").click(function()
|
||||
{
|
||||
self.saveNow();
|
||||
});
|
||||
$("#savedrevs-scrollleft").mousedown(function()
|
||||
{
|
||||
self.scroll('left');
|
||||
setScrollRepeatTimer('left');
|
||||
});
|
||||
$("#savedrevs-scrollright").mousedown(function()
|
||||
{
|
||||
self.scroll('right');
|
||||
setScrollRepeatTimer('right');
|
||||
});
|
||||
$("#savedrevs-close").click(function()
|
||||
{
|
||||
paddocbar.setShownPanel(null);
|
||||
});
|
||||
|
||||
// update "saved n minutes ago" times
|
||||
window.setInterval(function()
|
||||
{
|
||||
refreshRevisionList();
|
||||
}, 60 * 1000);
|
||||
},
|
||||
restoreRevision: function(rnum)
|
||||
{
|
||||
var rev = currentRevisionList[rnum];
|
||||
var warning = ("Restoring this revision will overwrite the current" + " text of the pad. " + "Are you sure you want to continue?");
|
||||
var hidePanel = paddocbar.hideLaterIfNoOtherInteraction();
|
||||
var box = getNthBox(rnum);
|
||||
if (confirm(warning))
|
||||
{
|
||||
box.find(".srtwirly").show();
|
||||
$.ajax(
|
||||
{
|
||||
type: 'get',
|
||||
url: '/ep/pad/getrevisionatext',
|
||||
data: {
|
||||
padId: pad.getPadId(),
|
||||
revId: rev.id
|
||||
},
|
||||
success: success,
|
||||
error: error
|
||||
});
|
||||
}
|
||||
|
||||
function success(resultJson)
|
||||
{
|
||||
untwirl();
|
||||
var result = JSON.parse(resultJson);
|
||||
padeditor.restoreRevisionText(result);
|
||||
window.setTimeout(function()
|
||||
{
|
||||
hidePanel();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function error(e)
|
||||
{
|
||||
untwirl();
|
||||
alert("Oops! There was an error retreiving the text (revNum= " + rev.revNum + "; padId=" + pad.getPadId());
|
||||
}
|
||||
|
||||
function untwirl()
|
||||
{
|
||||
box.find(".srtwirly").hide();
|
||||
}
|
||||
},
|
||||
showReachedLimit: function()
|
||||
{
|
||||
alert("Sorry, you do not have privileges to save more than " + pad.getPrivilege('maxRevisions') + " revisions.");
|
||||
},
|
||||
newRevisionList: function(lst, noAnimation)
|
||||
{
|
||||
// server gives us list with newest first;
|
||||
// we want chronological order
|
||||
var L = reversedCopy(lst);
|
||||
setRevisionList(L, noAnimation);
|
||||
rerenderButton();
|
||||
},
|
||||
saveNow: function()
|
||||
{
|
||||
if (isSaving)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!pad.isFullyConnected())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (haveReachedRevLimit())
|
||||
{
|
||||
self.showReachedLimit();
|
||||
return;
|
||||
}
|
||||
setIsSaving(true);
|
||||
var savedBy = pad.getUserName() || "unnamed";
|
||||
pad.callWhenNotCommitting(submitSave);
|
||||
|
||||
function submitSave()
|
||||
{
|
||||
$.ajax(
|
||||
{
|
||||
type: 'post',
|
||||
url: '/ep/pad/saverevision',
|
||||
data: {
|
||||
padId: pad.getPadId(),
|
||||
savedBy: savedBy,
|
||||
savedById: pad.getUserId(),
|
||||
revNum: pad.getCollabRevisionNumber()
|
||||
},
|
||||
success: success,
|
||||
error: error
|
||||
});
|
||||
}
|
||||
|
||||
function success(text)
|
||||
{
|
||||
setIsSaving(false);
|
||||
var newRevisionList = JSON.parse(text);
|
||||
self.newRevisionList(newRevisionList);
|
||||
pad.sendClientMessage(
|
||||
{
|
||||
type: 'newRevisionList',
|
||||
revisionList: newRevisionList,
|
||||
savedBy: savedBy
|
||||
});
|
||||
}
|
||||
|
||||
function error(e)
|
||||
{
|
||||
setIsSaving(false);
|
||||
alert("Oops! The server failed to save the revision. Please try again later.");
|
||||
}
|
||||
},
|
||||
handleResizePage: function()
|
||||
{
|
||||
updateScrollArrows();
|
||||
},
|
||||
handleIsFullyConnected: function(isConnected)
|
||||
{
|
||||
rerenderButton();
|
||||
},
|
||||
scroll: function(dir)
|
||||
{
|
||||
var minScroll = getMinScroll();
|
||||
var maxScroll = getMaxScroll();
|
||||
if (dir == 'left')
|
||||
{
|
||||
if (desiredScroll > minScroll)
|
||||
{
|
||||
var n = Math.floor((desiredScroll - 1 - minScroll) / REVISION_BOX_WIDTH);
|
||||
setDesiredScroll(Math.max(0, n) * REVISION_BOX_WIDTH + minScroll);
|
||||
}
|
||||
}
|
||||
else if (dir == 'right')
|
||||
{
|
||||
if (desiredScroll < maxScroll)
|
||||
{
|
||||
var n = Math.floor((maxScroll - desiredScroll - 1) / REVISION_BOX_WIDTH);
|
||||
setDesiredScroll(maxScroll - Math.max(0, n) * REVISION_BOX_WIDTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return self;
|
||||
}());
|
||||
|
||||
exports.padsavedrevs = padsavedrevs;
|
||||
exports.init = function(_pad){
|
||||
pad = _pad;
|
||||
}
|
||||
|
|
|
@ -10,12 +10,18 @@ if (plugins.isClient) {
|
|||
_ = require("underscore");
|
||||
}
|
||||
|
||||
exports.bubbleExceptions = true
|
||||
|
||||
var hookCallWrapper = function (hook, hook_name, args, cb) {
|
||||
if (cb === undefined) cb = function (x) { return x; };
|
||||
try {
|
||||
if (exports.bubbleExceptions) {
|
||||
return hook.hook_fn(hook_name, args, cb);
|
||||
} catch (ex) {
|
||||
console.error([hook_name, hook.part.full_name, ex.stack || ex]);
|
||||
} else {
|
||||
try {
|
||||
return hook.hook_fn(hook_name, args, cb);
|
||||
} catch (ex) {
|
||||
console.error([hook_name, hook.part.full_name, ex.stack || ex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +42,7 @@ exports.flatten = function (lst) {
|
|||
}
|
||||
|
||||
exports.callAll = function (hook_name, args) {
|
||||
if (!args) args = {};
|
||||
if (plugins.hooks[hook_name] === undefined) return [];
|
||||
return exports.flatten(_.map(plugins.hooks[hook_name], function (hook) {
|
||||
return hookCallWrapper(hook, hook_name, args);
|
||||
|
@ -43,26 +50,31 @@ exports.callAll = function (hook_name, args) {
|
|||
}
|
||||
|
||||
exports.aCallAll = function (hook_name, args, cb) {
|
||||
if (plugins.hooks[hook_name] === undefined) cb([]);
|
||||
if (!args) args = {};
|
||||
if (!cb) cb = function () {};
|
||||
if (plugins.hooks[hook_name] === undefined) return cb(null, []);
|
||||
async.map(
|
||||
plugins.hooks[hook_name],
|
||||
function (hook, cb) {
|
||||
hookCallWrapper(hook, hook_name, args, function (res) { cb(null, res); });
|
||||
},
|
||||
function (err, res) {
|
||||
cb(exports.flatten(res));
|
||||
cb(null, exports.flatten(res));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
exports.callFirst = function (hook_name, args) {
|
||||
if (!args) args = {};
|
||||
if (plugins.hooks[hook_name][0] === undefined) return [];
|
||||
return exports.flatten(hookCallWrapper(plugins.hooks[hook_name][0], hook_name, args));
|
||||
}
|
||||
|
||||
exports.aCallFirst = function (hook_name, args, cb) {
|
||||
if (plugins.hooks[hook_name][0] === undefined) cb([]);
|
||||
hookCallWrapper(plugins.hooks[hook_name][0], hook_name, args, function (res) { cb(exports.flatten(res)); });
|
||||
if (!args) args = {};
|
||||
if (!cb) cb = function () {};
|
||||
if (plugins.hooks[hook_name][0] === undefined) return cb(null, []);
|
||||
hookCallWrapper(plugins.hooks[hook_name][0], hook_name, args, function (res) { cb(null, exports.flatten(res)); });
|
||||
}
|
||||
|
||||
exports.callAllStr = function(hook_name, args, sep, pre, post) {
|
||||
|
|
76
src/static/js/pluginfw/installer.js
Normal file
76
src/static/js/pluginfw/installer.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");
|
||||
var npm = require("npm");
|
||||
var registry = require("npm/lib/utils/npm-registry-client/index.js");
|
||||
|
||||
var withNpm = function (npmfn, cb) {
|
||||
npm.load({}, function (er) {
|
||||
if (er) return cb({progress:1, error:er});
|
||||
npm.on("log", function (message) {
|
||||
cb({progress: 0.5, message:message.msg + ": " + message.pref});
|
||||
});
|
||||
npmfn(function (er, data) {
|
||||
if (er) return cb({progress:1, error:er.code + ": " + er.path});
|
||||
if (!data) data = {};
|
||||
data.progress = 1;
|
||||
data.message = "Done.";
|
||||
cb(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// All these functions call their callback multiple times with
|
||||
// {progress:[0,1], message:STRING, error:object}. They will call it
|
||||
// with progress = 1 at least once, and at all times will either
|
||||
// message or error be present, not both. It can be called multiple
|
||||
// times for all values of propgress except for 1.
|
||||
|
||||
exports.uninstall = function(plugin_name, cb) {
|
||||
withNpm(
|
||||
function (cb) {
|
||||
npm.commands.uninstall([plugin_name], function (er) {
|
||||
if (er) return cb(er);
|
||||
hooks.aCallAll("pluginUninstall", {plugin_name: plugin_name}, function (er, data) {
|
||||
if (er) return cb(er);
|
||||
plugins.update(cb);
|
||||
});
|
||||
});
|
||||
},
|
||||
cb
|
||||
);
|
||||
};
|
||||
|
||||
exports.install = function(plugin_name, cb) {
|
||||
withNpm(
|
||||
function (cb) {
|
||||
npm.commands.install([plugin_name], function (er) {
|
||||
if (er) return cb(er);
|
||||
hooks.aCallAll("pluginInstall", {plugin_name: plugin_name}, function (er, data) {
|
||||
if (er) return cb(er);
|
||||
plugins.update(cb);
|
||||
});
|
||||
});
|
||||
},
|
||||
cb
|
||||
);
|
||||
};
|
||||
|
||||
exports.search = function(pattern, cb) {
|
||||
withNpm(
|
||||
function (cb) {
|
||||
registry.get(
|
||||
"/-/all", null, 600, false, true,
|
||||
function (er, data) {
|
||||
if (er) return cb(er);
|
||||
var res = {};
|
||||
for (key in data) {
|
||||
if (key.indexOf(plugins.prefix) == 0 && key.indexOf(pattern) != -1)
|
||||
res[key] = data[key];
|
||||
}
|
||||
cb(null, {results:res});
|
||||
}
|
||||
);
|
||||
},
|
||||
cb
|
||||
);
|
||||
};
|
37
src/static/js/pluginfw/parent_require.js
Normal file
37
src/static/js/pluginfw/parent_require.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* This module allows passing require modules instances to
|
||||
* embedded iframes in a page.
|
||||
* For example, if a page has the "plugins" module initialized,
|
||||
* it is important to use exactly the same "plugins" instance
|
||||
* inside iframes as well. Otherwise, plugins cannot save any
|
||||
* state.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Instructs the require object that when a reqModuleName module
|
||||
* needs to be loaded, that it iterates through the parents of the
|
||||
* current window until it finds one who can execute "require"
|
||||
* statements and asks it to perform require on reqModuleName.
|
||||
*
|
||||
* @params requireDefObj Require object which supports define
|
||||
* statements. This object is accessible after loading require-kernel.
|
||||
* @params reqModuleName Module name e.g. (ep_etherpad-lite/static/js/plugins)
|
||||
*/
|
||||
exports.getRequirementFromParent = function(requireDefObj, reqModuleName) {
|
||||
requireDefObj.define(reqModuleName, function(require, exports, module) {
|
||||
var t = parent;
|
||||
var max = 0; // make sure I don't go up more than 10 times
|
||||
while (typeof(t) != "undefined") {
|
||||
max++;
|
||||
if (max==10)
|
||||
break;
|
||||
if (typeof(t.require) != "undefined") {
|
||||
module.exports = t.require(reqModuleName);
|
||||
return;
|
||||
}
|
||||
t = t.parent;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ var _;
|
|||
|
||||
if (!exports.isClient) {
|
||||
var npm = require("npm/lib/npm.js");
|
||||
var readInstalled = require("npm/lib/utils/read-installed.js");
|
||||
var readInstalled = require("./read-installed.js");
|
||||
var relativize = require("npm/lib/utils/relativize.js");
|
||||
var readJson = require("npm/lib/utils/read-json.js");
|
||||
var path = require("path");
|
||||
|
@ -12,12 +12,12 @@ if (!exports.isClient) {
|
|||
var fs = require("fs");
|
||||
var tsort = require("./tsort");
|
||||
var util = require("util");
|
||||
var extend = require("node.extend");
|
||||
_ = require("underscore");
|
||||
}else{
|
||||
var $, jQuery
|
||||
$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
|
||||
_ = require("ep_etherpad-lite/static/js/underscore");
|
||||
|
||||
}
|
||||
|
||||
exports.prefix = 'ep_';
|
||||
|
@ -123,14 +123,19 @@ exports.getPackages = function (cb) {
|
|||
function flatten(deps) {
|
||||
_.chain(deps).keys().each(function (name) {
|
||||
if (name.indexOf(exports.prefix) == 0) {
|
||||
packages[name] = deps[name];
|
||||
packages[name] = extend({}, deps[name]);
|
||||
// Delete anything that creates loops so that the plugin
|
||||
// list can be sent as JSON to the web client
|
||||
delete packages[name].dependencies;
|
||||
delete packages[name].parent;
|
||||
}
|
||||
if (deps[name].dependencies !== undefined)
|
||||
flatten(deps[name].dependencies);
|
||||
delete deps[name].dependencies;
|
||||
});
|
||||
}
|
||||
flatten([data]);
|
||||
var tmp = {};
|
||||
tmp[data.name] = data;
|
||||
flatten(tmp);
|
||||
cb(null, packages);
|
||||
});
|
||||
}
|
||||
|
|
324
src/static/js/pluginfw/read-installed.js
Normal file
324
src/static/js/pluginfw/read-installed.js
Normal file
|
@ -0,0 +1,324 @@
|
|||
// A copy of npm/lib/utils/read-installed.js
|
||||
// that is hacked to not cache everything :)
|
||||
|
||||
// Walk through the file-system "database" of installed
|
||||
// packages, and create a data object related to the
|
||||
// installed versions of each package.
|
||||
|
||||
/*
|
||||
This will traverse through all node_modules folders,
|
||||
resolving the dependencies object to the object corresponding to
|
||||
the package that meets that dep, or just the version/range if
|
||||
unmet.
|
||||
|
||||
Assuming that you had this folder structure:
|
||||
|
||||
/path/to
|
||||
+-- package.json { name = "root" }
|
||||
`-- node_modules
|
||||
+-- foo {bar, baz, asdf}
|
||||
| +-- node_modules
|
||||
| +-- bar { baz }
|
||||
| `-- baz
|
||||
`-- asdf
|
||||
|
||||
where "foo" depends on bar, baz, and asdf, bar depends on baz,
|
||||
and bar and baz are bundled with foo, whereas "asdf" is at
|
||||
the higher level (sibling to foo), you'd get this object structure:
|
||||
|
||||
{ <package.json data>
|
||||
, path: "/path/to"
|
||||
, parent: null
|
||||
, dependencies:
|
||||
{ foo :
|
||||
{ version: "1.2.3"
|
||||
, path: "/path/to/node_modules/foo"
|
||||
, parent: <Circular: root>
|
||||
, dependencies:
|
||||
{ bar:
|
||||
{ parent: <Circular: foo>
|
||||
, path: "/path/to/node_modules/foo/node_modules/bar"
|
||||
, version: "2.3.4"
|
||||
, dependencies: { baz: <Circular: foo.dependencies.baz> }
|
||||
}
|
||||
, baz: { ... }
|
||||
, asdf: <Circular: asdf>
|
||||
}
|
||||
}
|
||||
, asdf: { ... }
|
||||
}
|
||||
}
|
||||
|
||||
Unmet deps are left as strings.
|
||||
Extraneous deps are marked with extraneous:true
|
||||
deps that don't meet a requirement are marked with invalid:true
|
||||
|
||||
to READ(packagefolder, parentobj, name, reqver)
|
||||
obj = read package.json
|
||||
installed = ./node_modules/*
|
||||
if parentobj is null, and no package.json
|
||||
obj = {dependencies:{<installed>:"*"}}
|
||||
deps = Object.keys(obj.dependencies)
|
||||
obj.path = packagefolder
|
||||
obj.parent = parentobj
|
||||
if name, && obj.name !== name, obj.invalid = true
|
||||
if reqver, && obj.version !satisfies reqver, obj.invalid = true
|
||||
if !reqver && parentobj, obj.extraneous = true
|
||||
for each folder in installed
|
||||
obj.dependencies[folder] = READ(packagefolder+node_modules+folder,
|
||||
obj, folder, obj.dependencies[folder])
|
||||
# walk tree to find unmet deps
|
||||
for each dep in obj.dependencies not in installed
|
||||
r = obj.parent
|
||||
while r
|
||||
if r.dependencies[dep]
|
||||
if r.dependencies[dep].verion !satisfies obj.dependencies[dep]
|
||||
WARN
|
||||
r.dependencies[dep].invalid = true
|
||||
obj.dependencies[dep] = r.dependencies[dep]
|
||||
r = null
|
||||
else r = r.parent
|
||||
return obj
|
||||
|
||||
|
||||
TODO:
|
||||
1. Find unmet deps in parent directories, searching as node does up
|
||||
as far as the left-most node_modules folder.
|
||||
2. Ignore anything in node_modules that isn't a package folder.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
var npm = require("npm/lib/npm.js")
|
||||
, fs = require("graceful-fs")
|
||||
, path = require("path")
|
||||
, asyncMap = require("slide").asyncMap
|
||||
, semver = require("semver")
|
||||
, readJson = require("npm/lib/utils/read-json.js")
|
||||
, log = require("npm/lib/utils/log.js")
|
||||
|
||||
module.exports = readInstalled
|
||||
|
||||
function readInstalled (folder, cb) {
|
||||
/* This is where we clear the cache, these three lines are all the
|
||||
* new code there is */
|
||||
rpSeen = {};
|
||||
riSeen = [];
|
||||
var fuSeen = [];
|
||||
|
||||
var d = npm.config.get("depth")
|
||||
readInstalled_(folder, null, null, null, 0, d, function (er, obj) {
|
||||
if (er) return cb(er)
|
||||
// now obj has all the installed things, where they're installed
|
||||
// figure out the inheritance links, now that the object is built.
|
||||
resolveInheritance(obj)
|
||||
cb(null, obj)
|
||||
})
|
||||
}
|
||||
|
||||
var rpSeen = {}
|
||||
function readInstalled_ (folder, parent, name, reqver, depth, maxDepth, cb) {
|
||||
//console.error(folder, name)
|
||||
|
||||
var installed
|
||||
, obj
|
||||
, real
|
||||
, link
|
||||
|
||||
fs.readdir(path.resolve(folder, "node_modules"), function (er, i) {
|
||||
// error indicates that nothing is installed here
|
||||
if (er) i = []
|
||||
installed = i.filter(function (f) { return f.charAt(0) !== "." })
|
||||
next()
|
||||
})
|
||||
|
||||
readJson(path.resolve(folder, "package.json"), function (er, data) {
|
||||
obj = copy(data)
|
||||
|
||||
if (!parent) {
|
||||
obj = obj || true
|
||||
er = null
|
||||
}
|
||||
return next(er)
|
||||
})
|
||||
|
||||
fs.lstat(folder, function (er, st) {
|
||||
if (er) {
|
||||
if (!parent) real = true
|
||||
return next(er)
|
||||
}
|
||||
fs.realpath(folder, function (er, rp) {
|
||||
//console.error("realpath(%j) = %j", folder, rp)
|
||||
real = rp
|
||||
if (st.isSymbolicLink()) link = rp
|
||||
next(er)
|
||||
})
|
||||
})
|
||||
|
||||
var errState = null
|
||||
, called = false
|
||||
function next (er) {
|
||||
if (errState) return
|
||||
if (er) {
|
||||
errState = er
|
||||
return cb(null, [])
|
||||
}
|
||||
//console.error('next', installed, obj && typeof obj, name, real)
|
||||
if (!installed || !obj || !real || called) return
|
||||
called = true
|
||||
if (rpSeen[real]) return cb(null, rpSeen[real])
|
||||
if (obj === true) {
|
||||
obj = {dependencies:{}, path:folder}
|
||||
installed.forEach(function (i) { obj.dependencies[i] = "*" })
|
||||
}
|
||||
if (name && obj.name !== name) obj.invalid = true
|
||||
obj.realName = name || obj.name
|
||||
obj.dependencies = obj.dependencies || {}
|
||||
|
||||
// "foo":"http://blah" is always presumed valid
|
||||
if (reqver
|
||||
&& semver.validRange(reqver)
|
||||
&& !semver.satisfies(obj.version, reqver)) {
|
||||
obj.invalid = true
|
||||
}
|
||||
|
||||
if (parent
|
||||
&& !(name in parent.dependencies)
|
||||
&& !(name in (parent.devDependencies || {}))) {
|
||||
obj.extraneous = true
|
||||
}
|
||||
obj.path = obj.path || folder
|
||||
obj.realPath = real
|
||||
obj.link = link
|
||||
if (parent && !obj.link) obj.parent = parent
|
||||
rpSeen[real] = obj
|
||||
obj.depth = depth
|
||||
if (depth >= maxDepth) return cb(null, obj)
|
||||
asyncMap(installed, function (pkg, cb) {
|
||||
var rv = obj.dependencies[pkg]
|
||||
if (!rv && obj.devDependencies) rv = obj.devDependencies[pkg]
|
||||
readInstalled_( path.resolve(folder, "node_modules/"+pkg)
|
||||
, obj, pkg, obj.dependencies[pkg], depth + 1, maxDepth
|
||||
, cb )
|
||||
}, function (er, installedData) {
|
||||
if (er) return cb(er)
|
||||
installedData.forEach(function (dep) {
|
||||
obj.dependencies[dep.realName] = dep
|
||||
})
|
||||
|
||||
// any strings here are unmet things. however, if it's
|
||||
// optional, then that's fine, so just delete it.
|
||||
if (obj.optionalDependencies) {
|
||||
Object.keys(obj.optionalDependencies).forEach(function (dep) {
|
||||
if (typeof obj.dependencies[dep] === "string") {
|
||||
delete obj.dependencies[dep]
|
||||
}
|
||||
})
|
||||
}
|
||||
return cb(null, obj)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// starting from a root object, call findUnmet on each layer of children
|
||||
var riSeen = []
|
||||
function resolveInheritance (obj) {
|
||||
if (typeof obj !== "object") return
|
||||
if (riSeen.indexOf(obj) !== -1) return
|
||||
riSeen.push(obj)
|
||||
if (typeof obj.dependencies !== "object") {
|
||||
obj.dependencies = {}
|
||||
}
|
||||
Object.keys(obj.dependencies).forEach(function (dep) {
|
||||
findUnmet(obj.dependencies[dep])
|
||||
})
|
||||
Object.keys(obj.dependencies).forEach(function (dep) {
|
||||
resolveInheritance(obj.dependencies[dep])
|
||||
})
|
||||
}
|
||||
|
||||
// find unmet deps by walking up the tree object.
|
||||
// No I/O
|
||||
var fuSeen = []
|
||||
function findUnmet (obj) {
|
||||
if (fuSeen.indexOf(obj) !== -1) return
|
||||
fuSeen.push(obj)
|
||||
//console.error("find unmet", obj.name, obj.parent && obj.parent.name)
|
||||
var deps = obj.dependencies = obj.dependencies || {}
|
||||
//console.error(deps)
|
||||
Object.keys(deps)
|
||||
.filter(function (d) { return typeof deps[d] === "string" })
|
||||
.forEach(function (d) {
|
||||
//console.error("find unmet", obj.name, d, deps[d])
|
||||
var r = obj.parent
|
||||
, found = null
|
||||
while (r && !found && typeof deps[d] === "string") {
|
||||
// if r is a valid choice, then use that.
|
||||
found = r.dependencies[d]
|
||||
if (!found && r.realName === d) found = r
|
||||
|
||||
if (!found) {
|
||||
r = r.link ? null : r.parent
|
||||
continue
|
||||
}
|
||||
if ( typeof deps[d] === "string"
|
||||
&& !semver.satisfies(found.version, deps[d])) {
|
||||
// the bad thing will happen
|
||||
log.warn(obj.path + " requires "+d+"@'"+deps[d]
|
||||
+"' but will load\n"
|
||||
+found.path+",\nwhich is version "+found.version
|
||||
,"unmet dependency")
|
||||
found.invalid = true
|
||||
}
|
||||
deps[d] = found
|
||||
}
|
||||
|
||||
})
|
||||
log.verbose([obj._id], "returning")
|
||||
return obj
|
||||
}
|
||||
|
||||
function copy (obj) {
|
||||
if (!obj || typeof obj !== 'object') return obj
|
||||
if (Array.isArray(obj)) return obj.map(copy)
|
||||
|
||||
var o = {}
|
||||
for (var i in obj) o[i] = copy(obj[i])
|
||||
return o
|
||||
}
|
||||
|
||||
if (module === require.main) {
|
||||
var util = require("util")
|
||||
console.error("testing")
|
||||
|
||||
var called = 0
|
||||
readInstalled(process.cwd(), function (er, map) {
|
||||
console.error(called ++)
|
||||
if (er) return console.error(er.stack || er.message)
|
||||
cleanup(map)
|
||||
console.error(util.inspect(map, true, 10, true))
|
||||
})
|
||||
|
||||
var seen = []
|
||||
function cleanup (map) {
|
||||
if (seen.indexOf(map) !== -1) return
|
||||
seen.push(map)
|
||||
for (var i in map) switch (i) {
|
||||
case "_id":
|
||||
case "path":
|
||||
case "extraneous": case "invalid":
|
||||
case "dependencies": case "name":
|
||||
continue
|
||||
default: delete map[i]
|
||||
}
|
||||
var dep = map.dependencies
|
||||
// delete map.dependencies
|
||||
if (dep) {
|
||||
// map.dependencies = dep
|
||||
for (var i in dep) if (typeof dep[i] === "object") {
|
||||
cleanup(dep[i])
|
||||
}
|
||||
}
|
||||
return map
|
||||
}
|
||||
}
|
|
@ -1,419 +0,0 @@
|
|||
/**
|
||||
* StyleFix 1.0.2
|
||||
* @author Lea Verou
|
||||
* MIT license
|
||||
*/
|
||||
|
||||
(function(){
|
||||
|
||||
if(!window.addEventListener) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = window.StyleFix = {
|
||||
link: function(link) {
|
||||
try {
|
||||
// Ignore stylesheets with data-noprefix attribute as well as alternate stylesheets
|
||||
if(link.rel !== 'stylesheet' || link.hasAttribute('data-noprefix')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = link.href || link.getAttribute('data-href'),
|
||||
base = url.replace(/[^\/]+$/, ''),
|
||||
parent = link.parentNode,
|
||||
xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', url);
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState === 4) {
|
||||
var css = xhr.responseText;
|
||||
|
||||
if(css && link.parentNode) {
|
||||
css = self.fix(css, true, link);
|
||||
|
||||
// Convert relative URLs to absolute, if needed
|
||||
if(base) {
|
||||
css = css.replace(/url\(('?|"?)(.+?)\1\)/gi, function($0, quote, url) {
|
||||
if(!/^([a-z]{3,10}:|\/|#)/i.test(url)) { // If url not absolute & not a hash
|
||||
// May contain sequences like /../ and /./ but those DO work
|
||||
return 'url("' + base + url + '")';
|
||||
}
|
||||
|
||||
return $0;
|
||||
});
|
||||
|
||||
// behavior URLs shoudn’t be converted (Issue #19)
|
||||
css = css.replace(RegExp('\\b(behavior:\\s*?url\\(\'?"?)' + base, 'gi'), '$1');
|
||||
}
|
||||
|
||||
var style = document.createElement('style');
|
||||
style.textContent = css;
|
||||
style.media = link.media;
|
||||
style.disabled = link.disabled;
|
||||
style.setAttribute('data-href', link.getAttribute('href'));
|
||||
|
||||
parent.insertBefore(style, link);
|
||||
parent.removeChild(link);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(null);
|
||||
|
||||
link.setAttribute('data-inprogress', '');
|
||||
},
|
||||
|
||||
styleElement: function(style) {
|
||||
var disabled = style.disabled;
|
||||
|
||||
style.textContent = self.fix(style.textContent, true, style);
|
||||
|
||||
style.disabled = disabled;
|
||||
},
|
||||
|
||||
styleAttribute: function(element) {
|
||||
var css = element.getAttribute('style');
|
||||
|
||||
css = self.fix(css, false, element);
|
||||
|
||||
element.setAttribute('style', css);
|
||||
},
|
||||
|
||||
process: function() {
|
||||
// Linked stylesheets
|
||||
$('link[rel="stylesheet"]:not([data-inprogress])').forEach(StyleFix.link);
|
||||
|
||||
// Inline stylesheets
|
||||
$('style').forEach(StyleFix.styleElement);
|
||||
|
||||
// Inline styles
|
||||
$('[style]').forEach(StyleFix.styleAttribute);
|
||||
},
|
||||
|
||||
register: function(fixer, index) {
|
||||
(self.fixers = self.fixers || [])
|
||||
.splice(index === undefined? self.fixers.length : index, 0, fixer);
|
||||
},
|
||||
|
||||
fix: function(css, raw) {
|
||||
for(var i=0; i<self.fixers.length; i++) {
|
||||
css = self.fixers[i](css, raw) || css;
|
||||
}
|
||||
|
||||
return css;
|
||||
},
|
||||
|
||||
camelCase: function(str) {
|
||||
return str.replace(/-([a-z])/g, function($0, $1) { return $1.toUpperCase(); }).replace('-','');
|
||||
},
|
||||
|
||||
deCamelCase: function(str) {
|
||||
return str.replace(/[A-Z]/g, function($0) { return '-' + $0.toLowerCase() });
|
||||
}
|
||||
};
|
||||
|
||||
/**************************************
|
||||
* Process styles
|
||||
**************************************/
|
||||
(function(){
|
||||
setTimeout(function(){
|
||||
$('link[rel="stylesheet"]').forEach(StyleFix.link);
|
||||
}, 10);
|
||||
|
||||
document.addEventListener('DOMContentLoaded', StyleFix.process, false);
|
||||
})();
|
||||
|
||||
function $(expr, con) {
|
||||
return [].slice.call((con || document).querySelectorAll(expr));
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
/**
|
||||
* PrefixFree 1.0.4
|
||||
* @author Lea Verou
|
||||
* MIT license
|
||||
*/
|
||||
(function(root, undefined){
|
||||
|
||||
if(!window.StyleFix || !window.getComputedStyle) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = window.PrefixFree = {
|
||||
prefixCSS: function(css, raw) {
|
||||
var prefix = self.prefix;
|
||||
|
||||
function fix(what, before, after, replacement) {
|
||||
what = self[what];
|
||||
|
||||
if(what.length) {
|
||||
var regex = RegExp(before + '(' + what.join('|') + ')' + after, 'gi');
|
||||
|
||||
css = css.replace(regex, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
fix('functions', '(\\s|:|,)', '\\s*\\(', '$1' + prefix + '$2(');
|
||||
fix('keywords', '(\\s|:)', '(\\s|;|\\}|$)', '$1' + prefix + '$2$3');
|
||||
fix('properties', '(^|\\{|\\s|;)', '\\s*:', '$1' + prefix + '$2:');
|
||||
|
||||
// Prefix properties *inside* values (issue #8)
|
||||
if (self.properties.length) {
|
||||
var regex = RegExp('\\b(' + self.properties.join('|') + ')(?!:)', 'gi');
|
||||
|
||||
fix('valueProperties', '\\b', ':(.+?);', function($0) {
|
||||
return $0.replace(regex, prefix + "$1")
|
||||
});
|
||||
}
|
||||
|
||||
if(raw) {
|
||||
fix('selectors', '', '\\b', self.prefixSelector);
|
||||
fix('atrules', '@', '\\b', '@' + prefix + '$1');
|
||||
}
|
||||
|
||||
// Fix double prefixing
|
||||
css = css.replace(RegExp('-' + prefix, 'g'), '-');
|
||||
|
||||
return css;
|
||||
},
|
||||
|
||||
// Warning: prefixXXX functions prefix no matter what, even if the XXX is supported prefix-less
|
||||
prefixSelector: function(selector) {
|
||||
return selector.replace(/^:{1,2}/, function($0) { return $0 + self.prefix })
|
||||
},
|
||||
|
||||
prefixProperty: function(property, camelCase) {
|
||||
var prefixed = self.prefix + property;
|
||||
|
||||
return camelCase? StyleFix.camelCase(prefixed) : prefixed;
|
||||
}
|
||||
};
|
||||
|
||||
/**************************************
|
||||
* Properties
|
||||
**************************************/
|
||||
(function() {
|
||||
var prefixes = {},
|
||||
properties = [],
|
||||
shorthands = {},
|
||||
style = getComputedStyle(document.documentElement, null),
|
||||
dummy = document.createElement('div').style;
|
||||
|
||||
// Why are we doing this instead of iterating over properties in a .style object? Cause Webkit won't iterate over those.
|
||||
var iterate = function(property) {
|
||||
if(property.charAt(0) === '-') {
|
||||
properties.push(property);
|
||||
|
||||
var parts = property.split('-'),
|
||||
prefix = parts[1];
|
||||
|
||||
// Count prefix uses
|
||||
prefixes[prefix] = ++prefixes[prefix] || 1;
|
||||
|
||||
// This helps determining shorthands
|
||||
while(parts.length > 3) {
|
||||
parts.pop();
|
||||
|
||||
var shorthand = parts.join('-');
|
||||
|
||||
if(supported(shorthand) && properties.indexOf(shorthand) === -1) {
|
||||
properties.push(shorthand);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
supported = function(property) {
|
||||
return StyleFix.camelCase(property) in dummy;
|
||||
}
|
||||
|
||||
// Some browsers have numerical indices for the properties, some don't
|
||||
if(style.length > 0) {
|
||||
for(var i=0; i<style.length; i++) {
|
||||
iterate(style[i])
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(var property in style) {
|
||||
iterate(StyleFix.deCamelCase(property));
|
||||
}
|
||||
}
|
||||
|
||||
// Find most frequently used prefix
|
||||
var highest = {uses:0};
|
||||
for(var prefix in prefixes) {
|
||||
var uses = prefixes[prefix];
|
||||
|
||||
if(highest.uses < uses) {
|
||||
highest = {prefix: prefix, uses: uses};
|
||||
}
|
||||
}
|
||||
|
||||
self.prefix = '-' + highest.prefix + '-';
|
||||
self.Prefix = StyleFix.camelCase(self.prefix);
|
||||
|
||||
self.properties = [];
|
||||
|
||||
// Get properties ONLY supported with a prefix
|
||||
for(var i=0; i<properties.length; i++) {
|
||||
var property = properties[i];
|
||||
|
||||
if(property.indexOf(self.prefix) === 0) { // we might have multiple prefixes, like Opera
|
||||
var unprefixed = property.slice(self.prefix.length);
|
||||
|
||||
if(!supported(unprefixed)) {
|
||||
self.properties.push(unprefixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IE fix
|
||||
if(self.Prefix == 'Ms'
|
||||
&& !('transform' in dummy)
|
||||
&& !('MsTransform' in dummy)
|
||||
&& ('msTransform' in dummy)) {
|
||||
self.properties.push('transform', 'transform-origin');
|
||||
}
|
||||
|
||||
self.properties.sort();
|
||||
})();
|
||||
|
||||
/**************************************
|
||||
* Values
|
||||
**************************************/
|
||||
(function() {
|
||||
// Values that might need prefixing
|
||||
var functions = {
|
||||
'linear-gradient': {
|
||||
property: 'backgroundImage',
|
||||
params: 'red, teal'
|
||||
},
|
||||
'calc': {
|
||||
property: 'width',
|
||||
params: '1px + 5%'
|
||||
},
|
||||
'element': {
|
||||
property: 'backgroundImage',
|
||||
params: '#foo'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
functions['repeating-linear-gradient'] =
|
||||
functions['repeating-radial-gradient'] =
|
||||
functions['radial-gradient'] =
|
||||
functions['linear-gradient'];
|
||||
|
||||
var keywords = {
|
||||
'initial': 'color',
|
||||
'zoom-in': 'cursor',
|
||||
'zoom-out': 'cursor',
|
||||
'box': 'display',
|
||||
'flexbox': 'display',
|
||||
'inline-flexbox': 'display'
|
||||
};
|
||||
|
||||
self.functions = [];
|
||||
self.keywords = [];
|
||||
|
||||
var style = document.createElement('div').style;
|
||||
|
||||
function supported(value, property) {
|
||||
style[property] = '';
|
||||
style[property] = value;
|
||||
|
||||
return !!style[property];
|
||||
}
|
||||
|
||||
for (var func in functions) {
|
||||
var test = functions[func],
|
||||
property = test.property,
|
||||
value = func + '(' + test.params + ')';
|
||||
|
||||
if (!supported(value, property)
|
||||
&& supported(self.prefix + value, property)) {
|
||||
// It's supported, but with a prefix
|
||||
self.functions.push(func);
|
||||
}
|
||||
}
|
||||
|
||||
for (var keyword in keywords) {
|
||||
var property = keywords[keyword];
|
||||
|
||||
if (!supported(keyword, property)
|
||||
&& supported(self.prefix + keyword, property)) {
|
||||
// It's supported, but with a prefix
|
||||
self.keywords.push(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
/**************************************
|
||||
* Selectors and @-rules
|
||||
**************************************/
|
||||
(function() {
|
||||
|
||||
var
|
||||
selectors = {
|
||||
':read-only': null,
|
||||
':read-write': null,
|
||||
':any-link': null,
|
||||
'::selection': null
|
||||
},
|
||||
|
||||
atrules = {
|
||||
'keyframes': 'name',
|
||||
'viewport': null,
|
||||
'document': 'regexp(".")'
|
||||
};
|
||||
|
||||
self.selectors = [];
|
||||
self.atrules = [];
|
||||
|
||||
var style = root.appendChild(document.createElement('style'));
|
||||
|
||||
function supported(selector) {
|
||||
style.textContent = selector + '{}'; // Safari 4 has issues with style.innerHTML
|
||||
|
||||
return !!style.sheet.cssRules.length;
|
||||
}
|
||||
|
||||
for(var selector in selectors) {
|
||||
var test = selector + (selectors[selector]? '(' + selectors[selector] + ')' : '');
|
||||
|
||||
if(!supported(test) && supported(self.prefixSelector(test))) {
|
||||
self.selectors.push(selector);
|
||||
}
|
||||
}
|
||||
|
||||
for(var atrule in atrules) {
|
||||
var test = atrule + ' ' + (atrules[atrule] || '');
|
||||
|
||||
if(!supported('@' + test) && supported('@' + self.prefix + test)) {
|
||||
self.atrules.push(atrule);
|
||||
}
|
||||
}
|
||||
|
||||
root.removeChild(style);
|
||||
|
||||
})();
|
||||
|
||||
// Properties that accept properties as their value
|
||||
self.valueProperties = [
|
||||
'transition',
|
||||
'transition-property'
|
||||
]
|
||||
|
||||
// Add class for current prefix
|
||||
root.className += ' ' + self.prefix;
|
||||
|
||||
StyleFix.register(self.prefixCSS);
|
||||
|
||||
|
||||
})(document.documentElement);
|
Loading…
Add table
Add a link
Reference in a new issue