mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-10 07:44:43 +00:00
doc(sample): Add javascript sandbox integration (jsFiddle)
Change doc_widget.js to: - render "edit in jsfiddle" button next to all examples - make opt out certain examples by adding jsfiddle="false" attribute to doc:source element
This commit is contained in:
parent
de34ca0b64
commit
431b748cac
6 changed files with 78 additions and 6 deletions
|
|
@ -19,6 +19,37 @@ ul.doc-example > li.doc-example-heading {
|
||||||
margin-bottom: -10px;
|
margin-bottom: -10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.nojsfiddle {
|
||||||
|
float: right;
|
||||||
|
font-size: 14px;
|
||||||
|
margin-right:10px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
form.jsfiddle {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
z-index: 1;
|
||||||
|
height: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
form.jsfiddle button {
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 4px 10px;
|
||||||
|
margin: 10px;
|
||||||
|
background-color: #FFF;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #7989D6;
|
||||||
|
border-color: #7989D6;
|
||||||
|
-moz-border-radius: 8px;
|
||||||
|
-webkit-border-radius:8px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
form.jsfiddle textarea, form.jsfiddle input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
li.doc-example-live {
|
li.doc-example-live {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
//jqlite instead. jqlite's find() method currently supports onlt getElementsByTagName!
|
//jqlite instead. jqlite's find() method currently supports onlt getElementsByTagName!
|
||||||
var example = element.find('pre').eq(0), //doc-source
|
var example = element.find('pre').eq(0), //doc-source
|
||||||
exampleSrc = example.text(),
|
exampleSrc = example.text(),
|
||||||
|
jsfiddle = element.find('doc:source').attr('jsfiddle') || true,
|
||||||
scenario = element.find('pre').eq(1); //doc-scenario
|
scenario = element.find('pre').eq(1); //doc-scenario
|
||||||
|
|
||||||
var code = indent(exampleSrc);
|
var code = indent(exampleSrc);
|
||||||
|
|
@ -35,7 +36,8 @@
|
||||||
'<ul class="doc-example">' +
|
'<ul class="doc-example">' +
|
||||||
'<li class="doc-example-heading"><h3>Source</h3></li>' +
|
'<li class="doc-example-heading"><h3>Source</h3></li>' +
|
||||||
'<li class="doc-example-source" ng:non-bindable>' +
|
'<li class="doc-example-source" ng:non-bindable>' +
|
||||||
'<pre class="brush: js; html-script: true; highlight: [' +
|
jsFiddleButton(jsfiddle) + // may or may not have value
|
||||||
|
'<pre class="brush: js; html-script: true; highlight: [' +
|
||||||
code.hilite + ']; toolbar: false;"></pre></li>' +
|
code.hilite + ']; toolbar: false;"></pre></li>' +
|
||||||
'<li class="doc-example-heading"><h3>Live Preview</h3></li>' +
|
'<li class="doc-example-heading"><h3>Live Preview</h3></li>' +
|
||||||
'<li class="doc-example-live">' + exampleSrc +'</li>';
|
'<li class="doc-example-live">' + exampleSrc +'</li>';
|
||||||
|
|
@ -59,6 +61,45 @@
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert(e);
|
alert(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function jsFiddleButton(jsfiddle) {
|
||||||
|
if (jsfiddle !== 'false') {
|
||||||
|
if(jsfiddle == true) {
|
||||||
|
//dynamically generate a fiddle
|
||||||
|
var fiddleUrl = 'http://jsfiddle.net/api/post/library/pure/',
|
||||||
|
fiddleSrc = exampleSrc,
|
||||||
|
stripIndent = fiddleSrc.match(/^(\s*)/)[1].length;
|
||||||
|
|
||||||
|
//escape closing textarea
|
||||||
|
fiddleSrc = fiddleSrc.replace(/<\/textarea>/gi,'</textarea>')
|
||||||
|
//strip extra indentation
|
||||||
|
fiddleSrc = fiddleSrc.replace(new RegExp('^\\s{' + stripIndent + '}', 'gm'), '');
|
||||||
|
|
||||||
|
return '<form class="jsfiddle" method="post" action="' + fiddleUrl + '" target="_blank">' +
|
||||||
|
'<textarea name="css">' +
|
||||||
|
'body { font-family: Arial,Helvetica,sans-serif; }\n' +
|
||||||
|
'body, td, th { font-size: 14px; margin: 0; }\n' +
|
||||||
|
'table { border-collapse: separate; border-spacing: 2px; display: table; margin-bottom: 0; margin-top: 0; -moz-box-sizing: border-box; text-indent: 0; }\n' +
|
||||||
|
'a:link, a:visited, a:hover { color: #5D6DB6; text-decoration: none; }\n' +
|
||||||
|
'</textarea>' +
|
||||||
|
'<input type="text" name="title" value="AngularJS Live Example">' +
|
||||||
|
'<textarea name="html">' +
|
||||||
|
'<script src="' + angularJsUrl + '" ng:autobind></script>\n\n' +
|
||||||
|
'<!-- AngularJS Example Code: -->\n\n' +
|
||||||
|
fiddleSrc +
|
||||||
|
'</textarea>' +
|
||||||
|
'<button>edit at jsFiddle</button>' +
|
||||||
|
'</form>';
|
||||||
|
} else {
|
||||||
|
//use existing fiddle
|
||||||
|
fiddleUrl = "http://jsfiddle.net" + jsfiddle;
|
||||||
|
return '<form class="jsfiddle" method="get" action="' + fiddleUrl + '" target="_blank">' +
|
||||||
|
'<button>edit at jsFiddle</button>' +
|
||||||
|
'</form>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function indent(text) {
|
function indent(text) {
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@
|
||||||
|
|
||||||
Let's look at what a buzz client created with the `$resource` service looks like:
|
Let's look at what a buzz client created with the `$resource` service looks like:
|
||||||
<doc:example>
|
<doc:example>
|
||||||
<doc:source>
|
<doc:source jsfiddle="false">
|
||||||
<script>
|
<script>
|
||||||
function BuzzController($resource) {
|
function BuzzController($resource) {
|
||||||
this.Activity = $resource(
|
this.Activity = $resource(
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
Try changing the URL in the input box to see changes.
|
Try changing the URL in the input box to see changes.
|
||||||
|
|
||||||
<doc:example>
|
<doc:example>
|
||||||
<doc:source>
|
<doc:source jsfiddle="false">
|
||||||
<script>
|
<script>
|
||||||
function MainCntl($route, $location) {
|
function MainCntl($route, $location) {
|
||||||
this.$route = $route;
|
this.$route = $route;
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
<doc:example>
|
<doc:example>
|
||||||
<doc:source>
|
<doc:source jsfiddle="false">
|
||||||
<script>
|
<script>
|
||||||
function FetchCntl($xhr) {
|
function FetchCntl($xhr) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
|
||||||
|
|
@ -949,7 +949,7 @@ angularWidget('select', function(element){
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
<doc:example>
|
<doc:example>
|
||||||
<doc:source>
|
<doc:source jsfiddle="false">
|
||||||
<select name="url">
|
<select name="url">
|
||||||
<option value="examples/ng-include/template1.html">template1.html</option>
|
<option value="examples/ng-include/template1.html">template1.html</option>
|
||||||
<option value="examples/ng-include/template2.html">template2.html</option>
|
<option value="examples/ng-include/template2.html">template2.html</option>
|
||||||
|
|
@ -1375,7 +1375,7 @@ angularWidget("@ng:non-bindable", noop);
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
<doc:example>
|
<doc:example>
|
||||||
<doc:source>
|
<doc:source jsfiddle="false">
|
||||||
<script>
|
<script>
|
||||||
function MyCtrl($route) {
|
function MyCtrl($route) {
|
||||||
$route.when('/overview',
|
$route.when('/overview',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue