Skip to content

Commit

Permalink
Merge pull request #54 from syoichi/pr2-e4x
Browse files Browse the repository at this point in the history
Remove E4X code for Firefox 20+ #53
  • Loading branch information
to committed Apr 7, 2013
2 parents acbb07f + e7c8000 commit 94e90d6
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 137 deletions.
37 changes: 20 additions & 17 deletions xpi/chrome/content/library/01_utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -1815,12 +1815,7 @@ function convertToHTMLDocument(html, doc) {
return doc
}

function convertToXML(text){
return new XML(text.replace(/<\?.*\?>/gm,'').replace(/<!.*?>/gm, '').replace(/xmlns=["'].*?["']/g,''));
}

function convertToXULElement(str){
str = str.toXMLString? str.toXMLString() : str;
var xul = (
'<box xmlns="'+XUL_NS+'" >'+
str +
Expand Down Expand Up @@ -2276,12 +2271,12 @@ function selectRegion(doc){
doc.documentElement.style.cursor = 'crosshair';

var style = doc.createElement('style');
style.innerHTML = <><![CDATA[
style.innerHTML = commentToText(function(){/*
* {
cursor: crosshair !important;
-moz-user-select: none;
}
]]></>.toString();
*/});
doc.body.appendChild(style);

var region, p, d, moving, square;
Expand Down Expand Up @@ -2319,14 +2314,14 @@ function selectRegion(doc){

p = mouse(e);
region = doc.createElement('div');
region.setAttribute('style', <>
background : #888;
opacity : 0.5;
position : fixed;
z-index : 999999999;
top : {p.y}px;
left : {p.x}px;
</>.toString());
region.setAttribute('style', [
'background : #888;',
'opacity : 0.5;',
'position : fixed;',
'z-index : 999999999;',
'top : ' + p.y + 'px;',
'left : ' + p.x + 'px;'
].join('\n'));
doc.body.appendChild(region);

doc.addEventListener('mousemove', onMouseMove, true);
Expand Down Expand Up @@ -2407,13 +2402,13 @@ function flashView(doc){
var d = new Deferred();
var doc = doc || currentDocument();
var flash = doc.createElement('div');
flash.setAttribute('style', <>
flash.setAttribute('style', commentToText(function(){/*
background : #EEE;
position : fixed;
z-index : 999999999;
top : 0;
left : 0;
</>.toString());
*/}));
setElementDimensions(flash, getViewDimensions());
doc.body.appendChild(flash);
fade(flash, {
Expand Down Expand Up @@ -2490,3 +2485,11 @@ AbstractSessionService = {
}
},
}

function commentToText(commentFunc) {
return commentFunc.toString().replace(/^.*?\r?\n/, '').replace(/\r?\n.*?$/, '');
}

function getTextContent(node) {
return node ? node.textContent : '';
}
100 changes: 48 additions & 52 deletions xpi/chrome/content/library/10_Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,7 @@ function Entity(def){
},

deinitialize : function(){
return Model.db.execute(<>
DROP TABLE {def.name}
</>);
return Model.db.execute('DROP TABLE ' + def.name);
},

insert : function(model){
Expand All @@ -418,31 +416,29 @@ function Entity(def){
},

deleteById : function(id){
return Model.db.execute(<>
DELETE FROM {def.name}
WHERE
id = :id
</>, id);
return Model.db.execute([
'DELETE FROM ' + def.name + ' ',
'WHERE',
' id = :id'
].join('\n'), id);
},

deleteAll : function(){
return Model.db.execute(<>
DELETE FROM {def.name}
</>);
return Model.db.execute('DELETE FROM ' + def.name);
},

countAll : function(){
return Model.db.execute(<>
SELECT count(*) AS count
FROM {def.name}
</>)[0].count;
return Model.db.execute([
'SELECT count(*) AS count ',
'FROM ' + def.name
].join('\n'))[0].count;
},

findAll : function(){
return this.find(<>
SELECT *
FROM {def.name}
</>);
return this.find([
'SELECT * ',
'FROM ' + def.name
].join('\n'));
},

rowToObject : function(obj){
Expand Down Expand Up @@ -473,18 +469,18 @@ function Entity(def){

switch(type){
case 'find':
sql = Entity.compactSQL(<>
SELECT *
FROM {def.name}
{Entity.createWhereClause(fields)}
</>)
sql = Entity.compactSQL([
'SELECT * ',
'FROM ' + def.name + ' ',
Entity.createWhereClause(fields)
].join('\n'))
break;
case 'count':
sql = Entity.compactSQL(<>
SELECT count(id) AS count
FROM {def.name}
{Entity.createWhereClause(fields)}
</>)
sql = Entity.compactSQL([
'SELECT count(id) AS count',
'FROM ' + def.name + ' ',
Entity.createWhereClause(fields)
].join('\n'))
break;
}

Expand All @@ -506,36 +502,36 @@ function Entity(def){

extend(Entity, {
createWhereClause : function(fields){
return Entity.compactSQL(<>
WHERE
{fields.map(function(p){return p + '=:' + p}).join(' AND ')}
</>);
return Entity.compactSQL([
'WHERE',
' ' + fields.map(function(p){return p + '=:' + p}).join(' AND ')
].join('\n'));
},

createInitializeSQL : function(def){
var fields = [];
for(var p in def.fields)
fields.push(p + ' ' + def.fields[p].replace('TIMESTAMP', 'INTEGER').replace('LIST', 'TEXT'));

return Entity.compactSQL(<>
CREATE TABLE IF NOT EXISTS {def.name} (
{fields.join(', ')}
)
</>);
return Entity.compactSQL([
'CREATE TABLE IF NOT EXISTS ' + def.name + ' (',
' ' + fields.join(', ') + ' ',
')'
].join('\n'));
},

createInsertSQL : function(def){
var fields = keys(def.fields);
var params = fields.map(function(p){
return ':' + p
});
return Entity.compactSQL(<>
INSERT INTO {def.name} (
{fields.join(', ')}
) VALUES (
{params.join(', ')}
)
</>);
return Entity.compactSQL([
'INSERT INTO ' + def.name + ' (',
' ' + fields.join(', '),
') VALUES (',
' ' + params.join(', '),
')'
].join('\n'));
},

createUpdateSQL : function(def){
Expand All @@ -545,13 +541,13 @@ extend(Entity, {
return p + '=:' + p;
}).join(', ');

return Entity.compactSQL(<>
UPDATE {def.name}
SET
{fields}
WHERE
id = :id
</>);
return Entity.compactSQL([
'UPDATE ' + def.name + ' ',
'SET ',
' ' + fields + ' ',
'WHERE ',
' id = :id'
].join('\n'));
},

/**
Expand Down
12 changes: 5 additions & 7 deletions xpi/chrome/content/library/20_Tombloo.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var Tombloo = {

Tag.initialize();

db.execute(<>
db.execute(commentToText(function(){/*
CREATE TABLE temp (
id INTEGER PRIMARY KEY,
user TEXT,
Expand All @@ -77,7 +77,7 @@ var Tombloo = {
photos;
DROP TABLE photos;
ALTER TABLE temp RENAME TO photos;
</>);
*/}));

db.version = SCHEMA_VERSION;
db.vacuum();
Expand Down Expand Up @@ -300,7 +300,7 @@ extend(Tombloo.Post, {

initialize : function(){
try{
return this.db.execute(<>
return this.db.execute(commentToText(function(){/*
CREATE VIEW posts AS
SELECT "regular" AS type, id, user, date,
title,
Expand Down Expand Up @@ -349,13 +349,11 @@ extend(Tombloo.Post, {
"" AS player,
"" AS imageId
FROM quotes
</>);
*/}));
} catch(e if e instanceof Database.AlreadyExistsException){}
},

deinitialize : function(){
return this.db.execute(<>
DROP VIEW posts
</>);
return this.db.execute('DROP VIEW posts');
},
});
Loading

0 comments on commit 94e90d6

Please sign in to comment.