omi v0.4.5 - fix event problem

This commit is contained in:
dntzhang 2017-03-10 11:40:23 +08:00
parent 2ceffe8da6
commit ebb4b90280
10 changed files with 413 additions and 570 deletions

View File

@ -65,10 +65,10 @@ $ npm install omi
## CDN
* [https://unpkg.com/omi@0.4.4/dist/omi.min.js](https://unpkg.com/omi@0.4.4/dist/omi.min.js)
* [https://unpkg.com/omi@0.4.4/dist/omi.js](https://unpkg.com/omi@0.4.4/dist/omi.js)
* [https://unpkg.com/omi@0.4.4/dist/omi.lite.min.js](https://unpkg.com/omi@0.4.4/dist/omi.lite.min.js)
* [https://unpkg.com/omi@0.4.4/dist/omi.lite.js](https://unpkg.com/omi@0.4.4/dist/omi.lite.js)
* [https://unpkg.com/omi@0.4.5/dist/omi.min.js](https://unpkg.com/omi@0.4.5/dist/omi.min.js)
* [https://unpkg.com/omi@0.4.5/dist/omi.js](https://unpkg.com/omi@0.4.5/dist/omi.js)
* [https://unpkg.com/omi@0.4.5/dist/omi.lite.min.js](https://unpkg.com/omi@0.4.5/dist/omi.lite.min.js)
* [https://unpkg.com/omi@0.4.5/dist/omi.lite.js](https://unpkg.com/omi@0.4.5/dist/omi.lite.js)
## [中文](https://github.com/AlloyTeam/omi#中文--english) | English
@ -124,10 +124,10 @@ if using 'omi.lite.js' (without [mustache.js](https://github.com/janl/mustache.j
## CDN
* [https://unpkg.com/omi@0.4.4/dist/omi.min.js](https://unpkg.com/omi@0.4.4/dist/omi.min.js)
* [https://unpkg.com/omi@0.4.4/dist/omi.js](https://unpkg.com/omi@0.4.4/dist/omi.js)
* [https://unpkg.com/omi@0.4.4/dist/omi.lite.min.js](https://unpkg.com/omi@0.4.4/dist/omi.lite.min.js)
* [https://unpkg.com/omi@0.4.4/dist/omi.lite.js](https://unpkg.com/omi@0.4.4/dist/omi.lite.js)
* [https://unpkg.com/omi@0.4.5/dist/omi.min.js](https://unpkg.com/omi@0.4.5/dist/omi.min.js)
* [https://unpkg.com/omi@0.4.5/dist/omi.js](https://unpkg.com/omi@0.4.5/dist/omi.js)
* [https://unpkg.com/omi@0.4.5/dist/omi.lite.min.js](https://unpkg.com/omi@0.4.5/dist/omi.lite.min.js)
* [https://unpkg.com/omi@0.4.5/dist/omi.lite.js](https://unpkg.com/omi@0.4.5/dist/omi.lite.js)
## Contributors

49
dist/omi.js vendored
View File

@ -1,5 +1,5 @@
/*!
* Omi v0.4.4 By dntzhang
* Omi v0.4.5 By dntzhang
* Github: https://github.com/AlloyTeam/omi
* MIT Licensed.
*/
@ -1623,53 +1623,14 @@ return /******/ (function(modules) { // webpackBootstrap
Object.defineProperty(exports, "__esModule", {
value: true
});
function exchange(str, a, b) {
return str.split(a).map(function (item) {
return item.replace(new RegExp(b, 'g'), a);
}).join(b);
}
function safeDoubleQuote(str) {
return JSON.stringify(str).replace(/(^"|"$)/g, '');
}
function safeSingleQuote(str) {
str = exchange(str, "'", '"');
return exchange(safeDoubleQuote(str), "'", '"');
}
function escapeHtml(unsafe) {
return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
}
function endsWith(str, end) {
if (String.prototype.endsWith) {
return String.prototype.endsWith.call(str, end);
} else {
return str.substr(str.length - 1, 1) === end;
}
}
function scopedEvent(tpl, id) {
return tpl.replace(/<[\s\S]*?[^=]>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=('|"|{)([\s\S]*)('|"|})/g, function (eventStr, eventName, open, str, close) {
if (str.indexOf('Omi.instances[') === 0 || str.indexOf('new Function(') === 0) {
return tpl.replace(/<[\s\S]*?>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=('|")([\s\S]*?)\([\s\S]*?\)/g, function (eventStr, b, c, d) {
if (d.indexOf('Omi.instances[') === 0) {
return eventStr;
}
if (open === '{') {
// JSX-like event bind
var funcBody = '(' + str + ').bind(Omi.instances[' + id + '])(event)';
var result = 'on' + eventName + '="new Function(\'event\', \'' + escapeHtml(safeSingleQuote(funcBody)) + '\')(event)"';
return result.split('\n').map(function (line) {
return endsWith(line, ';') ? line : line + ';';
}).join('');
} else {
if (!str.match(/.*?\(.*?\)/)) {
// if is not JSX-like event and is not a function call (func(xxx, ttt))
return eventStr;
}
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
}
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
});
});
};

49
dist/omi.lite.js vendored
View File

@ -1,5 +1,5 @@
/*!
* Omi v0.4.4 By dntzhang
* Omi v0.4.5 By dntzhang
* Github: https://github.com/AlloyTeam/omi
* MIT Licensed.
*/
@ -1007,53 +1007,14 @@ return /******/ (function(modules) { // webpackBootstrap
Object.defineProperty(exports, "__esModule", {
value: true
});
function exchange(str, a, b) {
return str.split(a).map(function (item) {
return item.replace(new RegExp(b, 'g'), a);
}).join(b);
}
function safeDoubleQuote(str) {
return JSON.stringify(str).replace(/(^"|"$)/g, '');
}
function safeSingleQuote(str) {
str = exchange(str, "'", '"');
return exchange(safeDoubleQuote(str), "'", '"');
}
function escapeHtml(unsafe) {
return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
}
function endsWith(str, end) {
if (String.prototype.endsWith) {
return String.prototype.endsWith.call(str, end);
} else {
return str.substr(str.length - 1, 1) === end;
}
}
function scopedEvent(tpl, id) {
return tpl.replace(/<[\s\S]*?[^=]>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=('|"|{)([\s\S]*)('|"|})/g, function (eventStr, eventName, open, str, close) {
if (str.indexOf('Omi.instances[') === 0 || str.indexOf('new Function(') === 0) {
return tpl.replace(/<[\s\S]*?>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=('|")([\s\S]*?)\([\s\S]*?\)/g, function (eventStr, b, c, d) {
if (d.indexOf('Omi.instances[') === 0) {
return eventStr;
}
if (open === '{') {
// JSX-like event bind
var funcBody = '(' + str + ').bind(Omi.instances[' + id + '])(event)';
var result = 'on' + eventName + '="new Function(\'event\', \'' + escapeHtml(safeSingleQuote(funcBody)) + '\')(event)"';
return result.split('\n').map(function (line) {
return endsWith(line, ';') ? line : line + ';';
}).join('');
} else {
if (!str.match(/.*?\(.*?\)/)) {
// if is not JSX-like event and is not a function call (func(xxx, ttt))
return eventStr;
}
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
}
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
});
});
};

File diff suppressed because one or more lines are too long

6
dist/omi.min.js vendored

File diff suppressed because one or more lines are too long

401
dist/omi.server.js vendored
View File

@ -1,26 +1,26 @@
/*!
* Omi v0.1.0 By dntzhang
* Github: https://github.com/AlloyTeam/omi
* MIT Licensed.
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = global.document ?
factory( global, true ) :
function( w ) {
if ( !w.document ) {
throw new Error( 'Omi requires a window with a document' );
}
return factory( w );
};
else if(typeof define === 'function' && define.amd)
define('Omi', [], factory);
else if(typeof exports === 'object')
exports['Omi'] = factory();
else
root['Omi'] = factory();
})(typeof window !== 'undefined' ? window : this, function( window, noGlobal ) {
var document = window.document;
/*!
* Omi v0.1.0 By dntzhang
* Github: https://github.com/AlloyTeam/omi
* MIT Licensed.
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = global.document ?
factory( global, true ) :
function( w ) {
if ( !w.document ) {
throw new Error( 'Omi requires a window with a document' );
}
return factory( w );
};
else if(typeof define === 'function' && define.amd)
define('Omi', [], factory);
else if(typeof exports === 'object')
exports['Omi'] = factory();
else
root['Omi'] = factory();
})(typeof window !== 'undefined' ? window : this, function( window, noGlobal ) {
var document = window.document;
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
@ -137,14 +137,14 @@
};
}
/**
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
* (technically, since host objects have been implementation-dependent,
* at least before ES6, IE hasn't needed to work this way).
* Also works on strings, fixes IE < 9 to allow an explicit undefined
* for the 2nd argument (as in Firefox), and prevents errors when
* called on other DOM objects.
/**
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
* (technically, since host objects have been implementation-dependent,
* at least before ES6, IE hasn't needed to work this way).
* Also works on strings, fixes IE < 9 to allow an explicit undefined
* for the 2nd argument (as in Firefox), and prevents errors when
* called on other DOM objects.
*/
(function () {
'use strict';
@ -402,9 +402,9 @@
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
*/
/*global define: false Mustache: true*/
@ -429,9 +429,9 @@
return typeof object === 'function';
}
/**
* More correct typeof string handling array
* which normally returns typeof 'object'
/**
* More correct typeof string handling array
* which normally returns typeof 'object'
*/
function typeStr(obj) {
return isArray(obj) ? 'array' : typeof obj === 'undefined' ? 'undefined' : _typeof(obj);
@ -441,9 +441,9 @@
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
}
/**
* Null safe way of checking whether or not an object,
* including its prototype, has a given property
/**
* Null safe way of checking whether or not an object,
* including its prototype, has a given property
*/
function hasProperty(obj, propName) {
return obj != null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && propName in obj;
@ -484,27 +484,27 @@
var curlyRe = /\s*\}/;
var tagRe = /#|\^|\/|>|\{|&|=|!/;
/**
* Breaks up the given `template` string into a tree of tokens. If the `tags`
* argument is given here it must be an array with two string values: the
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
* course, the default is to use mustaches (i.e. mustache.tags).
*
* A token is an array with at least 4 elements. The first element is the
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
* did not contain a symbol (i.e. {{myValue}}) this element is "name". For
* all text that appears outside a symbol this element is "text".
*
* The second element of a token is its "value". For mustache tags this is
* whatever else was inside the tag besides the opening symbol. For text tokens
* this is the text itself.
*
* The third and fourth elements of the token are the start and end indices,
* respectively, of the token in the original template.
*
* Tokens that are the root node of a subtree contain two more elements: 1) an
* array of tokens in the subtree and 2) the index in the original template at
* which the closing tag for that section begins.
/**
* Breaks up the given `template` string into a tree of tokens. If the `tags`
* argument is given here it must be an array with two string values: the
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
* course, the default is to use mustaches (i.e. mustache.tags).
*
* A token is an array with at least 4 elements. The first element is the
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
* did not contain a symbol (i.e. {{myValue}}) this element is "name". For
* all text that appears outside a symbol this element is "text".
*
* The second element of a token is its "value". For mustache tags this is
* whatever else was inside the tag besides the opening symbol. For text tokens
* this is the text itself.
*
* The third and fourth elements of the token are the start and end indices,
* respectively, of the token in the original template.
*
* Tokens that are the root node of a subtree contain two more elements: 1) an
* array of tokens in the subtree and 2) the index in the original template at
* which the closing tag for that section begins.
*/
function parseTemplate(template, tags) {
if (!template) return [];
@ -624,9 +624,9 @@
return nestTokens(squashTokens(tokens));
}
/**
* Combines the values of consecutive text tokens in the given `tokens` array
* to a single token.
/**
* Combines the values of consecutive text tokens in the given `tokens` array
* to a single token.
*/
function squashTokens(tokens) {
var squashedTokens = [];
@ -649,11 +649,11 @@
return squashedTokens;
}
/**
* Forms the given array of `tokens` into a nested tree structure where
* tokens that represent a section have two additional items: 1) an array of
* all tokens that appear in that section and 2) the index in the original
* template that represents the end of that section.
/**
* Forms the given array of `tokens` into a nested tree structure where
* tokens that represent a section have two additional items: 1) an array of
* all tokens that appear in that section and 2) the index in the original
* template that represents the end of that section.
*/
function nestTokens(tokens) {
var nestedTokens = [];
@ -684,9 +684,9 @@
return nestedTokens;
}
/**
* A simple string scanner that is used by the template parser to find
* tokens in template strings.
/**
* A simple string scanner that is used by the template parser to find
* tokens in template strings.
*/
function Scanner(string) {
this.string = string;
@ -694,16 +694,16 @@
this.pos = 0;
}
/**
* Returns `true` if the tail is empty (end of string).
/**
* Returns `true` if the tail is empty (end of string).
*/
Scanner.prototype.eos = function eos() {
return this.tail === '';
};
/**
* Tries to match the given regular expression at the current position.
* Returns the matched text if it can match, the empty string otherwise.
/**
* Tries to match the given regular expression at the current position.
* Returns the matched text if it can match, the empty string otherwise.
*/
Scanner.prototype.scan = function scan(re) {
var match = this.tail.match(re);
@ -718,9 +718,9 @@
return string;
};
/**
* Skips all text until the given regular expression can be matched. Returns
* the skipped string, which is the entire tail if no match can be made.
/**
* Skips all text until the given regular expression can be matched. Returns
* the skipped string, which is the entire tail if no match can be made.
*/
Scanner.prototype.scanUntil = function scanUntil(re) {
var index = this.tail.search(re),
@ -744,9 +744,9 @@
return match;
};
/**
* Represents a rendering context by wrapping a view object and
* maintaining a reference to the parent context.
/**
* Represents a rendering context by wrapping a view object and
* maintaining a reference to the parent context.
*/
function Context(view, parentContext) {
this.view = view;
@ -754,17 +754,17 @@
this.parent = parentContext;
}
/**
* Creates a new context using the given view with this context
* as the parent.
/**
* Creates a new context using the given view with this context
* as the parent.
*/
Context.prototype.push = function push(view) {
return new Context(view, this);
};
/**
* Returns the value of the given name in this context, traversing
* up the context hierarchy if the value is absent in this context's view.
/**
* Returns the value of the given name in this context, traversing
* up the context hierarchy if the value is absent in this context's view.
*/
Context.prototype.lookup = function lookup(name) {
var cache = this.cache;
@ -784,16 +784,16 @@
names = name.split('.');
index = 0;
/**
* Using the dot notion path in `name`, we descend through the
* nested objects.
*
* To be certain that the lookup has been successful, we have to
* check if the last object in the path actually has the property
* we are looking for. We store the result in `lookupHit`.
*
* This is specially necessary for when the value has been set to
* `undefined` and we want to avoid looking up parent contexts.
/**
* Using the dot notion path in `name`, we descend through the
* nested objects.
*
* To be certain that the lookup has been successful, we have to
* check if the last object in the path actually has the property
* we are looking for. We store the result in `lookupHit`.
*
* This is specially necessary for when the value has been set to
* `undefined` and we want to avoid looking up parent contexts.
**/
while (value != null && index < names.length) {
if (index === names.length - 1) lookupHit = hasProperty(value, names[index]);
@ -818,25 +818,25 @@
return value;
};
/**
* A Writer knows how to take a stream of tokens and render them to a
* string, given a context. It also maintains a cache of templates to
* avoid the need to parse the same template twice.
/**
* A Writer knows how to take a stream of tokens and render them to a
* string, given a context. It also maintains a cache of templates to
* avoid the need to parse the same template twice.
*/
function Writer() {
this.cache = {};
}
/**
* Clears all cached templates in this writer.
/**
* Clears all cached templates in this writer.
*/
Writer.prototype.clearCache = function clearCache() {
this.cache = {};
};
/**
* Parses and caches the given `template` and returns the array of tokens
* that is generated from the parse.
/**
* Parses and caches the given `template` and returns the array of tokens
* that is generated from the parse.
*/
Writer.prototype.parse = function parse(template, tags) {
var cache = this.cache;
@ -847,14 +847,14 @@
return tokens;
};
/**
* High-level method that is used to render the given `template` with
* the given `view`.
*
* The optional `partials` argument may be an object that contains the
* names and templates of partials that are used in the template. It may
* also be a function that is used to load partial templates on the fly
* that takes a single argument: the name of the partial.
/**
* High-level method that is used to render the given `template` with
* the given `view`.
*
* The optional `partials` argument may be an object that contains the
* names and templates of partials that are used in the template. It may
* also be a function that is used to load partial templates on the fly
* that takes a single argument: the name of the partial.
*/
Writer.prototype.render = function render(template, view, partials) {
var tokens = this.parse(template);
@ -862,14 +862,14 @@
return this.renderTokens(tokens, context, partials, template);
};
/**
* Low-level method that renders the given array of `tokens` using
* the given `context` and `partials`.
*
* Note: The `originalTemplate` is only ever used to extract the portion
* of the original template that was contained in a higher-order section.
* If the template doesn't use higher-order sections, this argument may
* be omitted.
/**
* Low-level method that renders the given array of `tokens` using
* the given `context` and `partials`.
*
* Note: The `originalTemplate` is only ever used to extract the portion
* of the original template that was contained in a higher-order section.
* If the template doesn't use higher-order sections, this argument may
* be omitted.
*/
Writer.prototype.renderTokens = function renderTokens(tokens, context, partials, originalTemplate) {
var buffer = '';
@ -956,25 +956,25 @@
// All high-level mustache.* functions use this writer.
var defaultWriter = new Writer();
/**
* Clears all cached templates in the default writer.
/**
* Clears all cached templates in the default writer.
*/
mustache.clearCache = function clearCache() {
return defaultWriter.clearCache();
};
/**
* Parses and caches the given template in the default writer and returns the
* array of tokens it contains. Doing this ahead of time avoids the need to
* parse templates on the fly as they are rendered.
/**
* Parses and caches the given template in the default writer and returns the
* array of tokens it contains. Doing this ahead of time avoids the need to
* parse templates on the fly as they are rendered.
*/
mustache.parse = function parse(template, tags) {
return defaultWriter.parse(template, tags);
};
/**
* Renders the `template` with the given `view` and `partials` using the
* default writer.
/**
* Renders the `template` with the given `view` and `partials` using the
* default writer.
*/
mustache.render = function render(template, view, partials) {
if (typeof template !== 'string') {
@ -1631,53 +1631,14 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
function exchange(str, a, b) {
return str.split(a).map(function (item) {
return item.replace(new RegExp(b, 'g'), a);
}).join(b);
}
function safeDoubleQuote(str) {
return JSON.stringify(str).replace(/(^"|"$)/g, '');
}
function safeSingleQuote(str) {
str = exchange(str, "'", '"');
return exchange(safeDoubleQuote(str), "'", '"');
}
function escapeHtml(unsafe) {
return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
}
function endsWith(str, end) {
if (String.prototype.endsWith) {
return String.prototype.endsWith.call(str, end);
} else {
return str.substr(str.length - 1, 1) === end;
}
}
function scopedEvent(tpl, id) {
return tpl.replace(/<[\s\S]*?[^=]>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=('|"|{)([\s\S]*)('|"|})/g, function (eventStr, eventName, open, str, close) {
if (str.indexOf('Omi.instances[') === 0 || str.indexOf('new Function(') === 0) {
return tpl.replace(/<[\s\S]*?>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=('|")([\s\S]*?)\([\s\S]*?\)/g, function (eventStr, b, c, d) {
if (d.indexOf('Omi.instances[') === 0) {
return eventStr;
}
if (open === '{') {
// JSX-like event bind
var funcBody = '(' + str + ').bind(Omi.instances[' + id + '])(event)';
var result = 'on' + eventName + '="new Function(\'event\', \'' + escapeHtml(safeSingleQuote(funcBody)) + '\')(event)"';
return result.split('\n').map(function (line) {
return endsWith(line, ';') ? line : line + ';';
}).join('');
} else {
if (!str.match(/.*?\(.*?\)/)) {
// if is not JSX-like event and is not a function call (func(xxx, ttt))
return eventStr;
}
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
}
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
});
});
};
@ -1740,15 +1701,15 @@
return fragment.childNodes[0];
}
/**
* Returns true if two node's names are the same.
*
* NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same
* nodeName and different namespace URIs.
*
* @param {Element} a
* @param {Element} b The target element
* @return {boolean}
/**
* Returns true if two node's names are the same.
*
* NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same
* nodeName and different namespace URIs.
*
* @param {Element} a
* @param {Element} b The target element
* @return {boolean}
*/
function compareNodeNames(fromEl, toEl) {
var fromNodeName = fromEl.nodeName;
@ -1769,21 +1730,21 @@
}
}
/**
* Create an element, optionally with a known namespace URI.
*
* @param {string} name the element name, e.g. 'div' or 'svg'
* @param {string} [namespaceURI] the element's namespace URI, i.e. the value of
* its `xmlns` attribute or its inferred namespace.
*
* @return {Element}
/**
* Create an element, optionally with a known namespace URI.
*
* @param {string} name the element name, e.g. 'div' or 'svg'
* @param {string} [namespaceURI] the element's namespace URI, i.e. the value of
* its `xmlns` attribute or its inferred namespace.
*
* @return {Element}
*/
function createElementNS(name, namespaceURI) {
return !namespaceURI || namespaceURI === NS_XHTML ? doc.createElement(name) : doc.createElementNS(namespaceURI, name);
}
/**
* Copies the children of one DOM element to another DOM element
/**
* Copies the children of one DOM element to another DOM element
*/
function moveChildren(fromEl, toEl) {
var curChild = fromEl.firstChild;
@ -1863,18 +1824,18 @@
}
var specialElHandlers = {
/**
* Needed for IE. Apparently IE doesn't think that "selected" is an
* attribute when reading over the attributes using selectEl.attributes
/**
* Needed for IE. Apparently IE doesn't think that "selected" is an
* attribute when reading over the attributes using selectEl.attributes
*/
OPTION: function OPTION(fromEl, toEl) {
syncBooleanAttrProp(fromEl, toEl, 'selected');
},
/**
* The "value" attribute is special for the <input> element since it sets
* the initial value. Changing the "value" attribute without changing the
* "value" property will have no effect since it is only used to the set the
* initial value. Similar for the "checked" attribute, and "disabled".
/**
* The "value" attribute is special for the <input> element since it sets
* the initial value. Changing the "value" attribute without changing the
* "value" property will have no effect since it is only used to the set the
* initial value. Similar for the "checked" attribute, and "disabled".
*/
INPUT: function INPUT(fromEl, toEl) {
syncBooleanAttrProp(fromEl, toEl, 'checked');
@ -2002,13 +1963,13 @@
}
}
/**
* Removes a DOM node out of the original DOM
*
* @param {Node} node The node to remove
* @param {Node} parentNode The nodes parent
* @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.
* @return {undefined}
/**
* Removes a DOM node out of the original DOM
*
* @param {Node} node The node to remove
* @param {Node} parentNode The nodes parent
* @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.
* @return {undefined}
*/
function removeNode(node, parentNode, skipKeyedNodes) {
if (onBeforeNodeDiscarded(node) === false) {
@ -2373,16 +2334,16 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
/*
* html2json for omi
* https://github.com/AlloyTeam/omi
*
* Original code by John Resig (ejohn.org)
* http://ejohn.org/blog/pure-javascript-html-parser/
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
* Original code by Jxck
* https://github.com/Jxck/html2json
/*
* html2json for omi
* https://github.com/AlloyTeam/omi
*
* Original code by John Resig (ejohn.org)
* http://ejohn.org/blog/pure-javascript-html-parser/
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
* Original code by Jxck
* https://github.com/Jxck/html2json
*/
// Regular Expressions for parsing tags and attributes

View File

@ -1,57 +1,57 @@
{
"name": "omi",
"version": "0.4.4",
"description": "Open and modern framework for building user interfaces.",
"main": "dist/omi.js",
"scripts": {
"build": "webpack -w",
"build_min": "webpack -w",
"build_server": "node asset/build_server.js",
"nest": "webpack -w",
"curd": "webpack -w",
"textarea": "webpack -w",
"svg": "webpack -w",
"hello": "webpack -w",
"group_data": "webpack -w",
"jsx-like-event":"webpack -w",
"loop": "webpack -w",
"plugin": "webpack -w",
"order": "webpack -w",
"timer": "webpack -w",
"communication": "webpack -w",
"todo": "webpack -w",
"artTemplate": "webpack -w",
"todo_nest": "webpack -w",
"pagination": "webpack -w",
"server_rendering": "node example/server_rendering/app.js",
"test": "karma start test/karma.conf.js"
},
"devDependencies": {
"babel-core": "^6.0.20",
"babel-loader": "^6.0.1",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0",
"babel-preset-es2015": "^6.0.15",
"jasmine-core": "^2.5.2",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-jasmine": "^1.1.0",
"karma-webpack": "^1.8.1",
"md-text-loader": "^0.1.0",
"node-libs-browser": "^0.5.3",
"webpack": "^1.14.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AlloyTeam/omi.git"
},
"keywords": [
"omi"
],
"author": "dntzhang",
"license": "MIT",
"bugs": {
"url": "https://github.com/AlloyTeam/omi/issues/new"
},
"homepage": "http://alloyteam.github.io/omi"
}
{
"name": "omi",
"version": "0.4.5",
"description": "Open and modern framework for building user interfaces.",
"main": "dist/omi.js",
"scripts": {
"build": "webpack -w",
"build_min": "webpack -w",
"build_server": "node asset/build_server.js",
"nest": "webpack -w",
"curd": "webpack -w",
"textarea": "webpack -w",
"svg": "webpack -w",
"hello": "webpack -w",
"group_data": "webpack -w",
"jsx-like-event":"webpack -w",
"loop": "webpack -w",
"plugin": "webpack -w",
"order": "webpack -w",
"timer": "webpack -w",
"communication": "webpack -w",
"todo": "webpack -w",
"artTemplate": "webpack -w",
"todo_nest": "webpack -w",
"pagination": "webpack -w",
"server_rendering": "node example/server_rendering/app.js",
"test": "karma start test/karma.conf.js"
},
"devDependencies": {
"babel-core": "^6.0.20",
"babel-loader": "^6.0.1",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0",
"babel-preset-es2015": "^6.0.15",
"jasmine-core": "^2.5.2",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-jasmine": "^1.1.0",
"karma-webpack": "^1.8.1",
"md-text-loader": "^0.1.0",
"node-libs-browser": "^0.5.3",
"webpack": "^1.14.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AlloyTeam/omi.git"
},
"keywords": [
"omi"
],
"author": "dntzhang",
"license": "MIT",
"bugs": {
"url": "https://github.com/AlloyTeam/omi/issues/new"
},
"homepage": "http://alloyteam.github.io/omi"
}

View File

@ -1,55 +1,13 @@
function exchange(str, a, b) {
return str.split(a).map(function(item){return item.replace(new RegExp(b, 'g'), a)}).join(b);
}
function safeDoubleQuote(str) {
return JSON.stringify(str).replace(/(^"|"$)/g, '');
}
function safeSingleQuote(str) {
str = exchange(str, "'", '"');
return exchange(safeDoubleQuote(str), "'", '"');
}
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
function endsWith(str,end) {
if (String.prototype.endsWith) {
return String.prototype.endsWith.call(str, end);
} else {
return str.substr(str.length-1,1) === end;
}
}
function scopedEvent(tpl,id) {
return tpl.replace(/<[\s\S]*?[^=]>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=('|"|{)([\s\S]*)('|"|})/g, function (eventStr, eventName, open, str, close) {
if (str.indexOf('Omi.instances[') === 0 || str.indexOf('new Function(') === 0){
return eventStr;
}
if (open === '{') {
// JSX-like event bind
const funcBody = `(${str}).bind(Omi.instances[${id}])(event)`;
const result = `on${eventName}="new Function('event', '${escapeHtml(safeSingleQuote(funcBody))}')(event)"`;
return result.split('\n').map(function(line) {
return endsWith(line, ';') ? line : line + ';';
}).join('');
} else {
if (!str.match(/.*?\(.*?\)/)) {
// if is not JSX-like event and is not a function call (func(xxx, ttt))
return eventStr;
}
}
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
});
});
};
export default scopedEvent;
function scopedEvent(tpl,id) {
return tpl.replace(/<[\s\S]*?>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=('|")([\s\S]*?)\([\s\S]*?\)/g, function (eventStr, b, c, d) {
if (d.indexOf( 'Omi.instances[')===0){
return eventStr;
}else {
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
}
});
});
};
export default scopedEvent;

View File

@ -1,36 +1,38 @@
import scopedEvent from '../../src/event.js';
describe("scopedEvent", function() {
var result = scopedEvent("<div onclick='adfd()'>sfsdf </div>",1);
it("and so is a spec", function() {
expect(result).toBe("<div onclick='Omi.instances[1].adfd()'>sfsdf </div>");
expect( scopedEvent(result)).toBe("<div onclick='Omi.instances[1].adfd()'>sfsdf </div>");
});
});
describe("scopedEvent2", function() {
var result = scopedEvent("<div onclick='adfd'>sfsdf </div>",1);
it("and so is a spec", function() {
expect(result).toBe("<div onclick='adfd'>sfsdf </div>");
});
});
describe("jsx-like event binding", function() {
var result = scopedEvent("<div onclick={function(e){console.log(this)}}>sfsdf </div>",1);
it("and so is a spec", function() {
expect(result).toBe(`<div onclick="new Function('event', '(function(e){console.log(this)}).bind(Omi.instances[1])(event)')(event)";>sfsdf </div>`);
});
});
describe("jsx-like event binding with quote", function() {
var result = scopedEvent('<div onclick={function(e){console.log("string with sigal quote \' and double quote \"")}}>sfsdf </div>',1);
it("and so is a spec", function() {
expect(result).toBe(`<div onclick="new Function('event', '(function(e){console.log(&quot;string with sigal quote \\&#039; and double quote &quot;&quot;)}).bind(Omi.instances[1])(event)')(event)";>sfsdf </div>`);
});
});
import scopedEvent from '../../src/event.js';
describe("scopedEvent", function() {
var result2 = scopedEvent("<div onclick='adfd()' onblur='adfd()'>sfsdf </div>",1);
var result3 = scopedEvent("<div onblur='adfd'>sfsdf </div>",1);
var result = scopedEvent("<div onclick='adfd()'>sfsdf </div>",1);
it("and so is a spec", function() {
expect(result).toBe("<div onclick='Omi.instances[1].adfd()'>sfsdf </div>");
expect( scopedEvent(result)).toBe("<div onclick='Omi.instances[1].adfd()'>sfsdf </div>");
expect(result2).toBe("<div onclick='Omi.instances[1].adfd()' onblur='Omi.instances[1].adfd()'>sfsdf </div>");
expect(result3).toBe("<div onblur='adfd'>sfsdf </div>");
});
});
describe("scopedEvent2", function() {
var result = scopedEvent("<div onclick='adfd'>sfsdf </div>",1);
it("and so is a spec", function() {
expect(result).toBe("<div onclick='adfd'>sfsdf </div>");
});
});
//describe("jsx-like event binding", function() {
//
// var result = scopedEvent("<div onclick={function(e){console.log(this)}}>sfsdf </div>",1);
// it("and so is a spec", function() {
// expect(result).toBe(`<div onclick="new Function('event', '(function(e){console.log(this)}).bind(Omi.instances[1])(event)')(event)";>sfsdf </div>`);
// });
//});
//
//describe("jsx-like event binding with quote", function() {
//
// var result = scopedEvent('<div onclick={function(e){console.log("string with sigal quote \' and double quote \"")}}>sfsdf </div>',1);
// it("and so is a spec", function() {
// expect(result).toBe(`<div onclick="new Function('event', '(function(e){console.log(&quot;string with sigal quote \\&#039; and double quote &quot;&quot;)}).bind(Omi.instances[1])(event)')(event)";>sfsdf </div>`);
// });
//});

View File

@ -1,101 +1,101 @@
var path = require('path');
var webpack = require('webpack');
/**
* Env
* Get npm lifecycle event to identify the environment
*/
var ENV = process.env.npm_lifecycle_event;
var config = {
entry: './example/todo/main.js',
output: {
// path: __dirname,
path: './example/todo/',
filename: 'bundler.js'
},
module: {
loaders: [
{
loader: 'babel-loader',
test: /\.js$/,
query: {
presets: 'es2015',
plugins : [
"transform-es3-property-literals",
"transform-es3-member-expression-literals"
]
}
}
]
},
plugins: [
// Avoid publishing files when compilation fails
new webpack.NoErrorsPlugin()
],
stats: {
// Nice colored output
colors: true
},
// Create Sourcemaps for the bundle
// devtool: 'source-map',
};
if(ENV === 'build'||ENV === 'build_min'){
config = {
entry: {
omi: './src/index.js',
'omi.lite': './src/index.lite.js'
},
output: {
// path: __dirname,
path: 'dist/',
library:'Omi',
libraryTarget: 'umd',
filename: '[name].js'
//umdNamedDefine: true
},
module: {
loaders: [
{
loader: 'babel-loader',
test: path.join(__dirname, 'src'),
query: {
presets: 'es2015',
plugins : [
"transform-es3-property-literals",
"transform-es3-member-expression-literals"
]
},
}
]
},
plugins: [
// Avoid publishing files when compilation fails
new webpack.BannerPlugin(" Omi v0.4.4 By dntzhang \r\n Github: https://github.com/AlloyTeam/omi\r\n MIT Licensed."),
new webpack.NoErrorsPlugin()
],
stats: {
// Nice colored output
colors: true
},
// Create Sourcemaps for the bundle
// devtool: 'source-map',
};
if(ENV === 'build_min'){
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
config.entry = {
'omi.min': './src/index.js',
'omi.lite.min': './src/index.lite.js'
};
}
}else{
config.entry = './example/' + ENV + '/main.js';
config.output.path = './example/' + ENV + '/';
}
//console.log(ENV);
module.exports = config;
var path = require('path');
var webpack = require('webpack');
/**
* Env
* Get npm lifecycle event to identify the environment
*/
var ENV = process.env.npm_lifecycle_event;
var config = {
entry: './example/todo/main.js',
output: {
// path: __dirname,
path: './example/todo/',
filename: 'bundler.js'
},
module: {
loaders: [
{
loader: 'babel-loader',
test: /\.js$/,
query: {
presets: 'es2015',
plugins : [
"transform-es3-property-literals",
"transform-es3-member-expression-literals"
]
}
}
]
},
plugins: [
// Avoid publishing files when compilation fails
new webpack.NoErrorsPlugin()
],
stats: {
// Nice colored output
colors: true
},
// Create Sourcemaps for the bundle
// devtool: 'source-map',
};
if(ENV === 'build'||ENV === 'build_min'){
config = {
entry: {
omi: './src/index.js',
'omi.lite': './src/index.lite.js'
},
output: {
// path: __dirname,
path: 'dist/',
library:'Omi',
libraryTarget: 'umd',
filename: '[name].js'
//umdNamedDefine: true
},
module: {
loaders: [
{
loader: 'babel-loader',
test: path.join(__dirname, 'src'),
query: {
presets: 'es2015',
plugins : [
"transform-es3-property-literals",
"transform-es3-member-expression-literals"
]
},
}
]
},
plugins: [
// Avoid publishing files when compilation fails
new webpack.BannerPlugin(" Omi v0.4.5 By dntzhang \r\n Github: https://github.com/AlloyTeam/omi\r\n MIT Licensed."),
new webpack.NoErrorsPlugin()
],
stats: {
// Nice colored output
colors: true
},
// Create Sourcemaps for the bundle
// devtool: 'source-map',
};
if(ENV === 'build_min'){
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
config.entry = {
'omi.min': './src/index.js',
'omi.lite.min': './src/index.lite.js'
};
}
}else{
config.entry = './example/' + ENV + '/main.js';
config.output.path = './example/' + ENV + '/';
}
//console.log(ENV);
module.exports = config;