瀏覽代碼

module completed

Entony 7 年之前
當前提交
f62a9c472e
共有 6 個文件被更改,包括 123 次插入0 次删除
  1. 3 0
      .bowerrc
  2. 1 0
      .gitignore
  3. 22 0
      bower.json
  4. 0 0
      css/style.css
  5. 37 0
      index.html
  6. 60 0
      js/script.js

+ 3 - 0
.bowerrc

@@ -0,0 +1,3 @@
+{
+	"directory": "lib/"
+}

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+lib/

+ 22 - 0
bower.json

@@ -0,0 +1,22 @@
+{
+  "name": "module3",
+  "authors": [
+    "Entony <leonskottkenedi@gmail.com>"
+  ],
+  "description": "",
+  "main": "",
+  "license": "MIT",
+  "homepage": "",
+  "private": true,
+  "ignore": [
+    "**/.*",
+    "node_modules",
+    "lib/",
+    "test",
+    "tests"
+  ],
+  "dependencies": {
+    "bootstrap": "^3.3.7",
+    "jquery": "^3.2.1"
+  }
+}

+ 0 - 0
css/style.css


+ 37 - 0
index.html

@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="UTF-8">
+	<title>Module 3</title>
+	<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.min.css">
+	<link rel="stylesheet" href="css/style.css">
+</head>
+<body>
+	<div class="container">
+
+		<div class="page-header">
+			<h1>Module 3<small> run code in browser</small></h1>
+		</div>
+
+		<div class="panel panel-primary">
+			<div class="panel-heading">Code spase</div>
+	    	<div class="panel-body">
+				<div class="form-group" id="form">
+		  			<label for="code">Enter your code:</label>
+		  			<textarea class="form-control" rows="5" id="code"></textarea>
+					<pre id="pre-code" hidden></pre>
+				</div>
+				<div id="buttons">
+					<button id="save-code" class="btn btn-info">Save</button>
+					<button id="add-place" class="btn btn-primary pull-right"><span class="glyphicon glyphicon-plus"></span></button>
+				</div>    		
+	    	</div>
+			
+		</div>
+
+	</div>
+
+	<script src="lib/jquery/dist/jquery.min.js"></script>
+	<script src="js/script.js"></script>
+</body> 
+</html>

+ 60 - 0
js/script.js

@@ -0,0 +1,60 @@
+var $saveCode = $('#save-code');
+var $place = $('.container');
+var $pre = $('#pre-code');
+var $buttonPlace = $('#buttons');
+var $addPlace = $('#add-place');
+var $form = $('#form');
+
+	function crateTextArea() {
+		var $panel = $('<div>').addClass('panel panel-primary').appendTo($place);
+		var $panelHead = $('<div>').addClass('panel-heading').text('Code spase').appendTo($panel);
+		var $panelBody = $('<div>').addClass('panel-body').appendTo($panel);
+
+		var $formGroup = $('<div>').addClass('form-group').attr('id', 'form').appendTo($panelBody);
+		var $label = $('<label>').attr('for', 'code').text('Enter your code:').appendTo($formGroup);
+		var $textarea = $('<textarea>').addClass('form-control').attr({'id': 'code','rows': 5}).appendTo($formGroup);
+		var $pre = $('<pre>').attr('id', 'pre-code').appendTo($formGroup).hide();
+
+		var $buttonSave = $('<button>').attr('id', 'save-code').addClass('btn btn-info').text('Save').appendTo($panelBody)
+				.one('click', function(event){
+					$panel.find('.btn-info').remove();
+					var $code = $textarea.val();
+					$textarea.remove();
+					$pre.text($code).fadeIn();
+					$label.text('This code will be executed');
+					$buttonStart = $('<button>')
+									.addClass('btn btn-success')
+									.text('Start')
+									.appendTo($panelBody)
+									.one('click', function(event) {
+										$('<script>')
+											.text($code)
+											.appendTo($place);
+									});
+				});
+		var $buttonDelete = $('<button>').attr('id', 'delete-code').addClass('btn btn-danger pull-right').text('Delete').appendTo($panelBody)
+				.one('click', function(event){
+					$panel.remove(); 
+				});
+	}
+
+$saveCode.on('click', function(event){
+	$buttonPlace.find('.btn-info').remove();
+		var $code = $('#code').val();
+	$pre.text($code).fadeIn();
+	$form.find('.form-control').remove();
+	$('label').text('This code will be executed');
+	$buttonStart = $('<button>')
+			.addClass('btn btn-success')
+			.text('Start')
+			.appendTo($buttonPlace)
+			.one('click', function(event) {
+				$('<script>')
+					.text($code)
+					.appendTo($place);
+			})
+})
+
+$addPlace.on('click', function(event){
+	crateTextArea();
+})