-
Notifications
You must be signed in to change notification settings - Fork 1
/
contentEditable.html
201 lines (161 loc) · 5.85 KB
/
contentEditable.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>content editable</title>
<style>
body
{
font-size: 80%;
}
#ed
{
white-space: pre;
height: 600px;
overflow: auto;
border: solid 1px #aaa;
outline: none;
}
span
{
color: rgba(255, 0, 0, 0.5);
}
</style>
</head>
<body>
<div id='ed' contentEditable='true' onchange='alert("s")'>
// List launched applications
var apps = [[NSWorkspace sharedWorkspace] launchedApplications]
for (var i=0; i<apps.length; i++)
// option-right from next EOL
log(apps[i].NSApplicationName)
// Instead of using alloc/init and releasing ...
var url = [[NSURL alloc] initFileURLWithPath:"/tmp" isDirectory:true]
[url release]
// Replace 'init' in the method name with 'instance' to get an object managed by JavascriptCore
var url = [NSURL instanceFileURLWithPath:"/tmp" isDirectory:true]
// Mark object as collectable
url = null
// Mix and match ObjJ and Javascript syntax
var a = [NSArray arrayWithObjects:'hello', [7, 8, 9], 'world']
log('a[1][2]=' + [[a objectAtIndex:1] objectAtIndex:2])
log('a[1][1]=' + [a[1] objectAtIndex:1])
log('a[1][0]=' + a[1][0])
// Syntactic sugar for selector notation
var o = [SomeObject instance]
[o performSelector:@selector(doStuff:) withObject:anObject afterDelay:500]
//
// Define a Cocoa class in Javascript
// It can then be used from Javascript or Cocoa (use it as a delegate class, create a new NSView, ...)
//
class MyObject < NSObject
{
// Find objects containing at least one capital letter
- (NSArray*)findObjectsInArray:(NSArray*)array
{
return array.filter(function (elt) { return elt.match(/[A-Z]/) })
}
// Use radix = 16 to parse hex
// Use radix = 36 to parse a Reddit story number
- (NSNumber*)parseNumberInString:(NSString*)str withRadix:(int)radix
{
return parseInt(str, radix)
}
// NSApplication delegate method
- (void)applicationWillBecomeActive:(NSNotification *)notification
{
log('Hello ! ' + notification.name)
}
}
// Instance our new class
var obj = [MyObject instance]
log([obj parseNumberInString:'9q5vm' withRadix:'36'])
// Register it as application delegate
[NSApplication sharedApplication].delegate = obj
//
// Swizzle a method from an existing class
//
class NSButton
{
swizzle - (void)drawRect:(NSRect)rect
{
// Call original method
this.Original(arguments)
log('drawRect: called on button ' + this)
}
}
<span>The <b>result <i>rapidly</i> bec</b>omes an unmaintainable mess
</span><span>The <b>result <i>rapidly</i> bec</b>omes an unmaintainable <span contentEditable='false'>NO</span>mess
</span><span>The <b>result <i>rapidly</i> bec</b>omes an unmaintainable mess
</span>
function a(b, c)
{
if (b) <span contentEditable='true'>l</span>
<span contentEditable='true'>l</span> c()
}
<span>I am working on <span>a systems <span>integration</span> project</span> that has gotten itself into what I call a SpaghettiArchitecture? - a bunch of (generally small) programs that connect one database to another, or one app to another, and so on. This has been a result of DoTheSimplestThingThatCouldPossiblyWork. "Well, we need to get this data over there." "Oh, just write a little batch transfer program." The result rapidly becomes an unmaintainable mess - everything depends on everything else, the business logic is scattered, and there's not even a single codebase to RefactorMercilessly.</span>
So perhaps we can say that DoTheSimplestThingThatCouldPossiblyWork is a reasonable approach within a single program or codebase (provided, of course, that we RefactorMercilessly and UnitTest to keep it from becoming FlimsyAndBarelyFunctional). But on an architectural level, it is absolutely necessary to do a BigDesignUpFront (or at least a SmallDesignUpFront?) - put the right architectural components in place, plan for future expansion, decide how we're going to let our different apps and programs be loosely coupled, and so on. -- RobertEikel
This doesn't sound like DoTheSimplestThingThatCouldPossiblyWork at all to me. It sounds a lot more like DoTheQuickestThingThatMightWorkForAWhile. Programs were simply plugged in without any particular thought to the overall picture. I've never read or heard of anything in XP that says this is a good idea.
</div>
<script>
function f()
{
var n = document.getElementsByTagName('DIV')[0]
n.focus()
var s = getSelection()
s.collapseToStart()
}
setTimeout(f, 10)
function dumpHash(o)
{
var str = ''
for (var i in o) str += i + '=' + (o[i]) + '\n'
return str
}
function O()
{
this.a = 'foo'
}
O.prototype = { get test(){ return this.a },
set test(v) { this.a = v } }
var o = new O
o.test = 'foo2'
// alert(o.test)
// alert(dumpHash(O.prototype))
// var a = { get test(){ return "foo"; }}
// alert(a.test)
function getTickCount()
{
return (new Date).getTime()
}
function modifySelection()
{
function f()
{
document.getElementById('log').innerHTML = getTickCount()
try
{
var sel = getSelection()
sel.setBaseAndExtent(sel.baseNode, sel.baseOffset+1, sel.extentNode, sel.extentOffset)
}
catch(e)
{
}
}
var d = 1000
document.getElementById('log').innerHTML = 'Starting in ' + d + 'ms'
setInterval(f, d)
}
</script>
<script>
// Test comma expressions
var c = 1, d = 2, array = [2, 3]
var a = (alert('hello'), d), b = alert('world'), d, test = [alert('blah'), array[2]]
alert('passed a=' + (a==d) + ' b=' + (b==undefined) + ' test=' + (test[0]==array[2]))
</script>
<div id='log'>log</div>
<button onclick='modifySelection()'>Start modifying selection by timeout</button>
<pre>
Custom selexion : update after each move
</body>
</html>