2012-04-04 14:59:58 +00:00
|
|
|
'use strict'
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.ExamplePage <f> Example Page
|
|
|
|
([options[, self]]) -> <o:Ox.SplitPanel> Example Page
|
2012-05-21 10:38:18 +00:00
|
|
|
options <o> Options
|
|
|
|
self <o> Shared private variable
|
|
|
|
@*/
|
|
|
|
|
2012-04-04 14:59:58 +00:00
|
|
|
Ox.ExamplePage = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
|
|
|
html: '',
|
|
|
|
js: '',
|
2012-06-12 12:31:45 +00:00
|
|
|
references: [],
|
2012-04-06 12:10:21 +00:00
|
|
|
replaceCode: [],
|
|
|
|
replaceComment: [],
|
2012-04-04 14:59:58 +00:00
|
|
|
selected: 'source',
|
|
|
|
title: ''
|
|
|
|
})
|
|
|
|
.options(options || {});
|
|
|
|
|
|
|
|
self.$toolbar = Ox.Bar({size: 24});
|
|
|
|
|
|
|
|
self.$title = Ox.Label({
|
2012-04-05 15:32:19 +00:00
|
|
|
style: 'square',
|
2012-04-15 18:15:14 +00:00
|
|
|
title: self.options.title
|
2012-04-04 14:59:58 +00:00
|
|
|
})
|
|
|
|
.css({float: 'left', margin: '4px'})
|
|
|
|
.appendTo(self.$toolbar)
|
|
|
|
|
2012-04-15 12:18:45 +00:00
|
|
|
self.$openButton = Ox.Button({
|
|
|
|
disabled: self.options.selected == 'source',
|
|
|
|
title: 'open',
|
2012-04-15 19:13:18 +00:00
|
|
|
tooltip: 'Open in New Tab',
|
2012-04-15 12:18:45 +00:00
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'right', margin: '4px 4px 4px 2px'})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
window.open(self.options.html);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$toolbar);
|
|
|
|
|
2012-04-04 14:59:58 +00:00
|
|
|
self.$reloadButton = Ox.Button({
|
|
|
|
disabled: self.options.selected == 'source',
|
|
|
|
title: 'redo',
|
|
|
|
tooltip: 'Reload',
|
|
|
|
type: 'image'
|
|
|
|
})
|
2012-04-04 16:26:17 +00:00
|
|
|
.css({float: 'right', margin: '4px 2px 4px 2px'})
|
2012-04-04 14:59:58 +00:00
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
self.$frame.attr({src: self.options.html});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$toolbar);
|
|
|
|
|
2012-04-15 19:13:18 +00:00
|
|
|
self.$switchButton = Ox.Button({
|
|
|
|
disabled: self.options.selected == 'source',
|
|
|
|
title: 'switch',
|
|
|
|
tooltip: 'Switch Theme',
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'right', margin: '4px 2px 4px 2px'})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
self.$frame[0].contentWindow.postMessage(
|
|
|
|
'Ox && Ox.Theme && Ox.Theme('
|
|
|
|
+ 'Ox.Theme() == "classic" ? "modern" : "classic"'
|
|
|
|
+ ')',
|
|
|
|
'*'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$toolbar);
|
|
|
|
|
2012-04-04 14:59:58 +00:00
|
|
|
self.$tabs = Ox.ButtonGroup({
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
id: 'source',
|
2012-04-04 16:26:17 +00:00
|
|
|
title: 'View Source',
|
|
|
|
width: 80
|
2012-04-04 14:59:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'live',
|
2012-04-04 16:26:17 +00:00
|
|
|
title: 'View Live',
|
|
|
|
width: 80
|
2012-04-04 14:59:58 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
selectable: true,
|
|
|
|
value: self.options.selected
|
|
|
|
})
|
2012-04-05 15:32:19 +00:00
|
|
|
.css({float: 'right', margin: '4px 2px 4px 2px'})
|
2012-04-04 14:59:58 +00:00
|
|
|
.bindEvent({
|
|
|
|
change: function(data) {
|
2012-04-15 19:13:18 +00:00
|
|
|
var disabled = data.value == 'source';
|
2012-04-04 14:59:58 +00:00
|
|
|
self.options.selected = data.value;
|
2012-04-15 19:13:18 +00:00
|
|
|
self.hasUI && self.$switchButton.options({disabled: disabled});
|
|
|
|
self.$reloadButton.options({disabled: disabled});
|
|
|
|
self.$openButton.options({disabled: disabled});
|
2012-04-04 14:59:58 +00:00
|
|
|
self.$content.animate({
|
|
|
|
marginLeft: data.value == 'source'
|
|
|
|
? 0 : -self.options.width + 'px'
|
|
|
|
}, 250, function() {
|
|
|
|
if (data.value == 'live' && !self.$frame.attr('src')) {
|
|
|
|
self.$frame.attr({src: self.options.html});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$toolbar);
|
|
|
|
|
2012-06-12 14:26:55 +00:00
|
|
|
/*
|
2012-06-12 12:31:45 +00:00
|
|
|
self.$referencesMenu = Ox.MenuButton({
|
|
|
|
items: self.options.references.map(function(reference) {
|
|
|
|
return {id: reference, title: reference};
|
2012-04-04 16:26:17 +00:00
|
|
|
}),
|
2012-04-05 15:32:19 +00:00
|
|
|
//title: 'Documentation',
|
|
|
|
//width: 128
|
2012-04-04 16:26:17 +00:00
|
|
|
title: 'select',
|
2012-04-05 15:32:19 +00:00
|
|
|
tooltip: 'References',
|
2012-04-04 16:26:17 +00:00
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'right', margin: '4px 2px 4px 2px'})
|
|
|
|
.bindEvent({
|
|
|
|
click: function(data) {
|
2012-06-12 14:26:55 +00:00
|
|
|
that.triggerEvent('doc', {id: data.id});
|
2012-04-04 16:26:17 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$toolbar);
|
2012-06-12 14:26:55 +00:00
|
|
|
*/
|
2012-04-04 16:26:17 +00:00
|
|
|
|
2012-04-04 14:59:58 +00:00
|
|
|
self.$viewer = Ox.SourceViewer({
|
|
|
|
file: self.options.js,
|
2012-04-06 12:10:21 +00:00
|
|
|
replaceCode: self.options.replaceCode,
|
|
|
|
replaceComment: self.options.replaceComment
|
2012-04-04 14:59:58 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
width: self.options.width + 'px',
|
|
|
|
height: self.options.height - 24 + 'px'
|
|
|
|
});
|
|
|
|
self.$frame = Ox.Element('<iframe>')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: self.options.width + 'px',
|
|
|
|
top: 0,
|
|
|
|
border: 0
|
|
|
|
})
|
|
|
|
.attr({
|
|
|
|
width: self.options.width,
|
|
|
|
height: self.options.height
|
|
|
|
});
|
|
|
|
self.$content = Ox.Element()
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
width: self.options.width * 2 + 'px'
|
|
|
|
})
|
|
|
|
.append(self.$viewer)
|
|
|
|
.append(self.$frame)
|
|
|
|
self.$container = Ox.Element()
|
|
|
|
.append(self.$content)
|
|
|
|
|
|
|
|
that.setElement(
|
|
|
|
Ox.SplitPanel({
|
|
|
|
elements: [
|
|
|
|
{element: self.$toolbar, size: 24},
|
|
|
|
{element: self.$container}
|
|
|
|
],
|
|
|
|
orientation: 'vertical'
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2012-04-15 19:13:18 +00:00
|
|
|
Ox.get(self.options.js, function(js) {
|
|
|
|
self.hasUI = /Ox\.load\(.+UI.+,/.test(js);
|
|
|
|
!self.hasUI && self.$switchButton.options({disabled: true});
|
|
|
|
});
|
|
|
|
|
2012-05-28 14:06:22 +00:00
|
|
|
Ox.$window.on({
|
2012-04-04 14:59:58 +00:00
|
|
|
resize: function() {
|
|
|
|
setSize();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(setSize, 100);
|
|
|
|
|
|
|
|
function setSize() {
|
|
|
|
self.options.width = that.width();
|
|
|
|
self.options.height = that.height();
|
|
|
|
self.$content.css({
|
2012-05-26 15:48:19 +00:00
|
|
|
width: self.options.width * 2 + 'px'
|
2012-04-04 14:59:58 +00:00
|
|
|
})
|
|
|
|
self.$viewer.css({
|
|
|
|
width: self.options.width + 'px',
|
|
|
|
height: self.options.height - 24 + 'px'
|
|
|
|
})
|
|
|
|
self.$frame.attr({
|
|
|
|
width: self.options.width,
|
|
|
|
height: self.options.height - 24
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|