Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
microplugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Custom Issue Tracker
Custom Issue Tracker
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
angularjs
microplugin
Commits
200595c9
Commit
200595c9
authored
Aug 03, 2018
by
bingchuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[dev] 0.0.x
parents
Pipeline
#68
failed with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
158 additions
and
0 deletions
+158
-0
bower.json
bower.json
+22
-0
microplugin.js
src/microplugin.js
+136
-0
No files found.
bower.json
0 → 100644
View file @
200595c9
{
"name"
:
"microplugin"
,
"keywords"
:
[
"extensibility"
,
"plugins"
,
"architecture"
,
"require"
,
"dependencies"
],
"description"
:
"A lightweight plugin / dependency system for javascript libraries."
,
"version"
:
"0.0.3"
,
"license"
:
"Apache License, Version 2.0"
,
"readmeFilename"
:
"README.md"
,
"repository"
:
{
"type"
:
"git"
,
"url"
:
"git://github.com/brianreavis/microplugin.js.git"
},
"main"
:
[
"src/microplugin.js"
],
"ignore"
:
[
"Makefile"
,
"test"
,
".travis.yml"
,
".npmignore.yml"
],
"dependencies"
:
{}
}
src/microplugin.js
0 → 100644
View file @
200595c9
/**
* microplugin.js
* Copyright (c) 2013 Brian Reavis & contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
* @author Brian Reavis <brian@thirdroute.com>
*/
(
function
(
root
,
factory
)
{
if
(
typeof
define
===
'function'
&&
define
.
amd
)
{
define
(
factory
);
}
else
if
(
typeof
exports
===
'object'
)
{
module
.
exports
=
factory
();
}
else
{
root
.
MicroPlugin
=
factory
();
}
}(
this
,
function
()
{
var
MicroPlugin
=
{};
MicroPlugin
.
mixin
=
function
(
Interface
)
{
Interface
.
plugins
=
{};
/**
* Initializes the listed plugins (with options).
* Acceptable formats:
*
* List (without options):
* ['a', 'b', 'c']
*
* List (with options):
* [{'name': 'a', options: {}}, {'name': 'b', options: {}}]
*
* Hash (with options):
* {'a': { ... }, 'b': { ... }, 'c': { ... }}
*
* @param {mixed} plugins
*/
Interface
.
prototype
.
initializePlugins
=
function
(
plugins
)
{
var
i
,
n
,
key
;
var
self
=
this
;
var
queue
=
[];
self
.
plugins
=
{
names
:
[],
settings
:
{},
requested
:
{},
loaded
:
{}
};
if
(
utils
.
isArray
(
plugins
))
{
for
(
i
=
0
,
n
=
plugins
.
length
;
i
<
n
;
i
++
)
{
if
(
typeof
plugins
[
i
]
===
'string'
)
{
queue
.
push
(
plugins
[
i
]);
}
else
{
self
.
plugins
.
settings
[
plugins
[
i
].
name
]
=
plugins
[
i
].
options
;
queue
.
push
(
plugins
[
i
].
name
);
}
}
}
else
if
(
plugins
)
{
for
(
key
in
plugins
)
{
if
(
plugins
.
hasOwnProperty
(
key
))
{
self
.
plugins
.
settings
[
key
]
=
plugins
[
key
];
queue
.
push
(
key
);
}
}
}
while
(
queue
.
length
)
{
self
.
require
(
queue
.
shift
());
}
};
Interface
.
prototype
.
loadPlugin
=
function
(
name
)
{
var
self
=
this
;
var
plugins
=
self
.
plugins
;
var
plugin
=
Interface
.
plugins
[
name
];
if
(
!
Interface
.
plugins
.
hasOwnProperty
(
name
))
{
throw
new
Error
(
'Unable to find "'
+
name
+
'" plugin'
);
}
plugins
.
requested
[
name
]
=
true
;
plugins
.
loaded
[
name
]
=
plugin
.
fn
.
apply
(
self
,
[
self
.
plugins
.
settings
[
name
]
||
{}]);
plugins
.
names
.
push
(
name
);
};
/**
* Initializes a plugin.
*
* @param {string} name
*/
Interface
.
prototype
.
require
=
function
(
name
)
{
var
self
=
this
;
var
plugins
=
self
.
plugins
;
if
(
!
self
.
plugins
.
loaded
.
hasOwnProperty
(
name
))
{
if
(
plugins
.
requested
[
name
])
{
throw
new
Error
(
'Plugin has circular dependency ("'
+
name
+
'")'
);
}
self
.
loadPlugin
(
name
);
}
return
plugins
.
loaded
[
name
];
};
/**
* Registers a plugin.
*
* @param {string} name
* @param {function} fn
*/
Interface
.
define
=
function
(
name
,
fn
)
{
Interface
.
plugins
[
name
]
=
{
'name'
:
name
,
'fn'
:
fn
};
};
};
var
utils
=
{
isArray
:
Array
.
isArray
||
function
(
vArg
)
{
return
Object
.
prototype
.
toString
.
call
(
vArg
)
===
'[object Array]'
;
}
};
return
MicroPlugin
;
}));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment