<!DOCTYPE html>
<html ng-app="editorApp">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Editor - AngularJS</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #edafb8 0%, #f7d7dc 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
text-align: center;
color: white;
margin-bottom: 30px;
animation: fadeInDown 0.8s ease;
}
.header h1 {
font-size: 2.8rem;
font-weight: 700;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
.header p {
font-size: 1.1rem;
opacity: 0.95;
}
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.editor-container {
background: white;
border-radius: 16px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
overflow: hidden;
animation: fadeInUp 0.6s ease;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.toolbar {
background: #f8f9fa;
padding: 15px 20px;
border-bottom: 2px solid #e0e0e0;
display: flex;
flex-wrap: wrap;
gap: 8px;
align-items: center;
}
.toolbar-group {
display: flex;
gap: 5px;
padding-right: 15px;
border-right: 2px solid #e0e0e0;
}
.toolbar-group:last-child {
border-right: none;
}
.toolbar-btn {
width: 38px;
height: 38px;
border: 2px solid transparent;
background: white;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
font-weight: 600;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
color: #555;
}
.toolbar-btn:hover {
background: #edafb8;
color: white;
border-color: #edafb8;
transform: translateY(-2px);
}
.toolbar-btn.active {
background: #edafb8;
color: white;
border-color: #edafb8;
}
.toolbar-select {
padding: 8px 12px;
border: 2px solid #e0e0e0;
border-radius: 6px;
background: white;
cursor: pointer;
font-size: 14px;
transition: all 0.3s;
min-width: 120px;
}
.toolbar-select:focus {
outline: none;
border-color: #edafb8;
}
.toolbar-input {
width: 50px;
padding: 8px;
border: 2px solid #e0e0e0;
border-radius: 6px;
text-align: center;
font-size: 14px;
transition: all 0.3s;
}
.toolbar-input:focus {
outline: none;
border-color: #edafb8;
}
.color-picker {
width: 38px;
height: 38px;
border: 2px solid #e0e0e0;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s;
}
.color-picker:hover {
border-color: #edafb8;
transform: scale(1.05);
}
.editor-area {
padding: 40px;
min-height: 500px;
font-size: 16px;
line-height: 1.8;
color: #2c3e50;
background: white;
}
.editor-area:focus {
outline: none;
}
.editor-area:empty:before {
content: 'Start typing here...';
color: #aaa;
font-style: italic;
}
.stats-bar {
background: #f8f9fa;
padding: 15px 20px;
border-top: 2px solid #e0e0e0;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 15px;
}
.stat-item {
display: flex;
align-items: center;
gap: 8px;
color: #555;
font-size: 14px;
font-weight: 600;
}
.stat-icon {
color: #edafb8;
font-size: 18px;
}
.action-buttons {
display: flex;
gap: 10px;
}
.action-btn {
padding: 10px 20px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: 600;
transition: all 0.3s;
display: flex;
align-items: center;
gap: 8px;
}
.btn-save {
background: linear-gradient(135deg, #edafb8 0%, #f7d7dc 100%);
color: white;
box-shadow: 0 4px 12px rgba(237, 175, 184, 0.3);
}
.btn-save:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(237, 175, 184, 0.4);
}
.btn-clear {
background: #e0e0e0;
color: #555;
}
.btn-clear:hover {
background: #d0d0d0;
}
.btn-export {
background: #27ae60;
color: white;
}
.btn-export:hover {
background: #229954;
transform: translateY(-2px);
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
align-items: center;
justify-content: center;
z-index: 1000;
animation: fadeIn 0.3s ease;
}
.modal.show {
display: flex;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.modal-content {
background: white;
border-radius: 16px;
padding: 30px;
max-width: 500px;
width: 90%;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
animation: slideUp 0.3s ease;
}
@keyframes slideUp {
from {
transform: translateY(50px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.modal-header {
font-size: 1.5rem;
color: #2c3e50;
margin-bottom: 20px;
font-weight: 700;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
color: #555;
font-weight: 600;
margin-bottom: 8px;
font-size: 14px;
}
.form-group input {
width: 100%;
padding: 12px 15px;
border: 2px solid #e0e0e0;
border-radius: 10px;
font-size: 15px;
transition: all 0.3s;
}
.form-group input:focus {
outline: none;
border-color: #edafb8;
box-shadow: 0 0 0 3px rgba(237, 175, 184, 0.1);
}
.modal-actions {
display: flex;
gap: 10px;
margin-top: 25px;
}
.toast {
position: fixed;
bottom: 30px;
right: 30px;
background: white;
padding: 20px 25px;
border-radius: 12px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
display: none;
align-items: center;
gap: 15px;
z-index: 1001;
animation: slideInRight 0.3s ease;
border-left: 4px solid #edafb8;
}
@keyframes slideInRight {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.toast.show {
display: flex;
}
.toast-icon {
width: 40px;
height: 40px;
background: #edafb8;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 20px;
}
@media (max-width: 768px) {
.header h1 {
font-size: 2rem;
}
.toolbar {
padding: 10px 15px;
}
.toolbar-group {
padding-right: 10px;
}
.toolbar-btn {
width: 35px;
height: 35px;
font-size: 14px;
}
.editor-area {
padding: 20px;
min-height: 400px;
}
.stats-bar {
flex-direction: column;
align-items: flex-start;
}
.action-buttons {
width: 100%;
flex-direction: column;
}
.action-btn {
width: 100%;
justify-content: center;
}
.toast {
bottom: 15px;
right: 15px;
left: 15px;
}
}
</style>
</head>
<body ng-controller="EditorController">
<div class="container">
<div class="header">
<h1>📝 Rich Text Editor</h1>
<p>Create beautiful documents with AngularJS</p>
</div>
<div class="editor-container">
<!-- Toolbar -->
<div class="toolbar">
<!-- Text Formatting -->
<div class="toolbar-group">
<button class="toolbar-btn" ng-click="execCommand('bold')" title="Bold (Ctrl+B)">
<strong>B</strong>
</button>
<button class="toolbar-btn" ng-click="execCommand('italic')" title="Italic (Ctrl+I)">
<em>I</em>
</button>
<button class="toolbar-btn" ng-click="execCommand('underline')" title="Underline (Ctrl+U)">
<u>U</u>
</button>
<button class="toolbar-btn" ng-click="execCommand('strikeThrough')" title="Strikethrough">
<s>S</s>
</button>
</div>
<!-- Font Size -->
<div class="toolbar-group">
<select class="toolbar-select" ng-model="fontSize" ng-change="changeFontSize()">
<option value="1">Small</option>
<option value="3" selected>Normal</option>
<option value="5">Large</option>
<option value="7">Huge</option>
</select>
</div>
<!-- Alignment -->
<div class="toolbar-group">
<button class="toolbar-btn" ng-click="execCommand('justifyLeft')" title="Align Left">
☰
</button>
<button class="toolbar-btn" ng-click="execCommand('justifyCenter')" title="Align Center">
☷
</button>
<button class="toolbar-btn" ng-click="execCommand('justifyRight')" title="Align Right">
☰
</button>
<button class="toolbar-btn" ng-click="execCommand('justifyFull')" title="Justify">
▦
</button>
</div>
<!-- Lists -->
<div class="toolbar-group">
<button class="toolbar-btn" ng-click="execCommand('insertOrderedList')" title="Numbered List">
≡
</button>
<button class="toolbar-btn" ng-click="execCommand('insertUnorderedList')" title="Bullet List">
•
</button>
</div>
<!-- Colors -->
<div class="toolbar-group">
<input type="color" class="color-picker" ng-model="textColor" ng-change="changeTextColor()" title="Text Color">
<input type="color" class="color-picker" ng-model="bgColor" ng-change="changeBgColor()" title="Background Color">
</div>
<!-- Insert -->
<div class="toolbar-group">
<button class="toolbar-btn" ng-click="insertLink()" title="Insert Link">
🔗
</button>
<button class="toolbar-btn" ng-click="insertImage()" title="Insert Image">
🖼️
</button>
<button class="toolbar-btn" ng-click="insertTable()" title="Insert Table">
⊞
</button>
</div>
<!-- Undo/Redo -->
<div class="toolbar-group">
<button class="toolbar-btn" ng-click="execCommand('undo')" title="Undo">
↶
</button>
<button class="toolbar-btn" ng-click="execCommand('redo')" title="Redo">
↷
</button>
</div>
</div>
<!-- Editor Area -->
<div class="editor-area"
contenteditable="true"
id="editor"
ng-model="editorContent"
ng-keyup="updateStats()"
ng-click="updateStats()">
</div>
<!-- Stats Bar -->
<div class="stats-bar">
<div style="display: flex; gap: 20px; flex-wrap: wrap;">
<div class="stat-item">
<span class="stat-icon">📄</span>
<span>Words: {{stats.words}}</span>
</div>
<div class="stat-item">
<span class="stat-icon">🔤</span>
<span>Characters: {{stats.characters}}</span>
</div>
<div class="stat-item">
<span class="stat-icon">📏</span>
<span>Paragraphs: {{stats.paragraphs}}</span>
</div>
</div>
<div class="action-buttons">
<button class="action-btn btn-save" ng-click="saveDocument()">
💾 Save
</button>
<button class="action-btn btn-export" ng-click="exportHTML()">
📥 Export HTML
</button>
<button class="action-btn btn-clear" ng-click="clearEditor()">
🗑️ Clear
</button>
</div>
</div>
</div>
</div>
<!-- Link Modal -->
<div class="modal" id="linkModal" ng-class="{show: showLinkModal}">
<div class="modal-content">
<h3 class="modal-header">Insert Link</h3>
<div class="form-group">
<label>Link Text</label>
<input type="text" ng-model="linkText" placeholder="Enter link text">
</div>
<div class="form-group">
<label>URL</label>
<input type="url" ng-model="linkUrl" placeholder="https://example.com">
</div>
<div class="modal-actions">
<button class="action-btn btn-save" ng-click="confirmLink()" style="flex: 1;">
Insert
</button>
<button class="action-btn btn-clear" ng-click="cancelLink()" style="flex: 1;">
Cancel
</button>
</div>
</div>
</div>
<!-- Image Modal -->
<div class="modal" id="imageModal" ng-class="{show: showImageModal}">
<div class="modal-content">
<h3 class="modal-header">Insert Image</h3>
<div class="form-group">
<label>Image URL</label>
<input type="url" ng-model="imageUrl" placeholder="https://example.com/image.jpg">
</div>
<div class="form-group">
<label>Alt Text</label>
<input type="text" ng-model="imageAlt" placeholder="Image description">
</div>
<div class="modal-actions">
<button class="action-btn btn-save" ng-click="confirmImage()" style="flex: 1;">
Insert
</button>
<button class="action-btn btn-clear" ng-click="cancelImage()" style="flex: 1;">
Cancel
</button>
</div>
</div>
</div>
<!-- Toast Notification -->
<div class="toast" id="toast" ng-class="{show: showToast}">
<div class="toast-icon">✓</div>
<div>
<strong>{{toastMessage}}</strong>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script>
angular.module('editorApp', [])
.controller('EditorController', ['$scope', '$timeout', function($scope, $timeout) {
// Initialize
$scope.editorContent = '';
$scope.fontSize = '3';
$scope.textColor = '#000000';
$scope.bgColor = '#ffffff';
$scope.stats = {
words: 0,
characters: 0,
paragraphs: 0
};
// Modals
$scope.showLinkModal = false;
$scope.showImageModal = false;
$scope.showToast = false;
// Execute formatting command
$scope.execCommand = function(command, value) {
document.execCommand(command, false, value);
document.getElementById('editor').focus();
$scope.updateStats();
};
// Change font size
$scope.changeFontSize = function() {
$scope.execCommand('fontSize', $scope.fontSize);
};
// Change text color
$scope.changeTextColor = function() {
$scope.execCommand('foreColor', $scope.textColor);
};
// Change background color
$scope.changeBgColor = function() {
$scope.execCommand('backColor', $scope.bgColor);
};
// Insert link
$scope.insertLink = function() {
$scope.showLinkModal = true;
$scope.linkText = '';
$scope.linkUrl = '';
};
$scope.confirmLink = function() {
if ($scope.linkUrl) {
var html = '<a href="' + $scope.linkUrl + '" target="_blank">' +
($scope.linkText || $scope.linkUrl) + '</a>';
$scope.execCommand('insertHTML', html);
$scope.cancelLink();
}
};
$scope.cancelLink = function() {
$scope.showLinkModal = false;
};
// Insert image
$scope.insertImage = function() {
$scope.showImageModal = true;
$scope.imageUrl = '';
$scope.imageAlt = '';
};
$scope.confirmImage = function() {
if ($scope.imageUrl) {
var html = '<img src="' + $scope.imageUrl + '" alt="' +
($scope.imageAlt || 'Image') + '" style="max-width: 100%; height: auto;">';
$scope.execCommand('insertHTML', html);
$scope.cancelImage();
}
};
$scope.cancelImage = function() {
$scope.showImageModal = false;
};
// Insert table
$scope.insertTable = function() {
var table = '<table border="1" cellpadding="10" style="border-collapse: collapse; width: 100%;">' +
'<tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr>' +
'<tr><td>Cell 4</td><td>Cell 5</td><td>Cell 6</td></tr>' +
'</table><br>';
$scope.execCommand('insertHTML', table);
};
// Update statistics
$scope.updateStats = function() {
var editor = document.getElementById('editor');
var text = editor.innerText || '';
$scope.stats.characters = text.length;
$scope.stats.words = text.trim() ? text.trim().split(/\s+/).length : 0;
$scope.stats.paragraphs = editor.querySelectorAll('p, div').length ||
(text.trim() ? 1 : 0);
};
// Save document
$scope.saveDocument = function() {
var editor = document.getElementById('editor');
var content = editor.innerHTML;
localStorage.setItem('editorContent', content);
$scope.showToastMessage('Document saved successfully!');
};
// Export HTML
$scope.exportHTML = function() {
var editor = document.getElementById('editor');
var content = editor.innerHTML;
var blob = new Blob([content], { type: 'text/html' });
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = 'document.html';
a.click();
$scope.showToastMessage('HTML exported successfully!');
};
// Clear editor
$scope.clearEditor = function() {
if (confirm('Are you sure you want to clear all content?')) {
document.getElementById('editor').innerHTML = '';
$scope.updateStats();
$scope.showToastMessage('Editor cleared!');
}
};
// Show toast message
$scope.showToastMessage = function(message) {
$scope.toastMessage = message;
$scope.showToast = true;
$timeout(function() {
$scope.showToast = false;
}, 3000);
};
// Load saved content
var savedContent = localStorage.getItem('editorContent');
if (savedContent) {
document.getElementById('editor').innerHTML = savedContent;
$scope.updateStats();
}
// Keyboard shortcuts
document.addEventListener('keydown', function(e) {
if (e.ctrlKey || e.metaKey) {
switch(e.key.toLowerCase()) {
case 'b':
e.preventDefault();
$scope.execCommand('bold');
break;
case 'i':
e.preventDefault();
$scope.execCommand('italic');
break;
case 'u':
e.preventDefault();
$scope.execCommand('underline');
break;
case 's':
e.preventDefault();
$scope.saveDocument();
$scope.$apply();
break;
}
}
});
}]);
</script>
</body>
</html>
No comments yet. Be the first!