Search is not available for this dataset
id
stringlengths
1
8
text
stringlengths
72
9.81M
addition_count
int64
0
10k
commit_subject
stringlengths
0
3.7k
deletion_count
int64
0
8.43k
file_extension
stringlengths
0
32
lang
stringlengths
1
94
license
stringclasses
10 values
repo_name
stringlengths
9
59
10067050
<NME> module.toHTML.js <BEF> describe('View#toHTML()', function() { var viewToTest; beforeEach(function() { viewToTest = helpers.createView(); assert.isTrue('string' === typeof html); }, "Should print the child html into the corresponding slot": function() { var apple = new Apple({ slot: 1 }); var layout = new Layout({ test("Should print the child html into the corresponding slot", function() { var apple = new Apple({ slot: 1 }); var layout = new Layout({ children: [apple] }); var appleHtml = apple.toHTML(); var layoutHtml = layout.toHTML(); expect(layoutHtml.indexOf(appleHtml)).toBeGreaterThan(-1); }); test("Should print the child html by id if no slot is found (backwards compatable)", function() { var apple = new Apple({ id: 1 }); var layout = new Layout({ children: [apple] }); var appleHtml = apple.toHTML(); var layoutHtml = layout.toHTML(); expect(layoutHtml.indexOf(appleHtml)).toBeGreaterThan(-1); }); test("Should fallback to printing children by id if no slot is present", function() { var layout = new Layout({ children: [ { module: 'apple', id: 1 } ] }); }, "tearDown": helpers.destroyView }); }); afterEach(function() { helpers.destroyView(); viewToTest = null; }); }); <MSG> Merge pull request #64 from ftlabs/before-tohtml Add `before tohtml` event <DFF> @@ -7,6 +7,14 @@ buster.testCase('View#toHTML()', { assert.isTrue('string' === typeof html); }, + "Should fire `before tohtml event`": function() { + var spy = this.spy(); + this.view.on('before tohtml', spy); + var html = this.view.toHTML(); + assert.isTrue('string' === typeof html); + assert.called(spy); + }, + "Should print the child html into the corresponding slot": function() { var apple = new Apple({ slot: 1 }); var layout = new Layout({ @@ -47,4 +55,4 @@ buster.testCase('View#toHTML()', { }, "tearDown": helpers.destroyView -}); \ No newline at end of file +});
9
Merge pull request #64 from ftlabs/before-tohtml
1
.js
toHTML
mit
ftlabs/fruitmachine
10067051
<NME> README.md <BEF> # FruitMachine [![Build Status](https://api.travis-ci.com/ftlabs/fruitmachine.svg)](https://travis-ci.com/ftlabs/fruitmachine) [![Coverage Status](https://coveralls.io/repos/ftlabs/fruitmachine/badge.png)](https://coveralls.io/r/ftlabs/fruitmachine) A lightweight component layout engine for client and server. FruitMachine is designed to build rich interactive layouts from modular, reusable components. It's light and unopinionated so that it can be applied to almost any layout problem. FruitMachine is currently powering the [FT Web App](http://apps.ft.com/ftwebapp/). ```js // Define a module var Apple = fruitmachine.define({ name: 'apple', template: function(){ return 'hello' } }); // Create a module var apple = new Apple(); // Render it apple.render(); apple.el.outerHTML; //=> <div class="apple">hello</div> ``` ## Installation ``` $ npm install fruitmachine ``` or ``` $ bower install fruitmachine ``` or ### View#child(); Returns the first child - [Queries](docs/queries.md) - [Helpers](docs/module-helpers.md) - [Removing & destroying](docs/removing-and-destroying.md) - [Extending](docs/extending-modules.md) - [Server-side rendering](docs/server-side-rendering.md) - [API](docs/api.md) - [Events](docs/events.md) ## Tests #### With PhantomJS ``` $ npm install $ npm test ``` #### Without PhantomJS ``` $ node_modules/.bin/buster-static ``` ...then visit http://localhost:8282/ in browser ## Author - **Wilson Page** - [@wilsonpage](http://github.com/wilsonpage) ## Contributors - **Wilson Page** - [@wilsonpage](http://github.com/wilsonpage) - **Matt Andrews** - [@matthew-andrews](http://github.com/matthew-andrews) ## License Copyright (c) 2018 The Financial Times Limited Licensed under the MIT license. ## Credits and collaboration FruitMachine is largely unmaintained/finished. All open source code released by FT Labs is licenced under the MIT licence. We welcome comments, feedback and suggestions. Please feel free to raise an issue or pull request. <MSG> Update readme <DFF> @@ -38,6 +38,22 @@ arguments, returns this view's id. +### View#module(); + +Returns the first descendent +View with the passed module type. + + + +### View#modules(); + +Returns a list of descendent +Views that match the module +type given (Similar to +Element.querySelector();). + + + ### View#child(); Returns the first child
16
Update readme
0
.md
md
mit
ftlabs/fruitmachine
10067052
<NME> README.md <BEF> # LoadJS <img src="https://www.muicss.com/static/images/loadjs.svg" width="250px"> LoadJS is a tiny async loader for modern browsers (899 bytes). [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs?type=dev) [![CDNJS](https://img.shields.io/cdnjs/v/loadjs.svg)](https://cdnjs.com/libraries/loadjs) ## Introduction LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript, CSS and image files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code of [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) in your &lt;html&gt; (possibly in the &lt;head&gt; tag) and then use the `loadjs` global to manage JavaScript dependencies after pageload. LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 899 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle and execute code when it loads loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); </script> ``` You can also use more advanced syntax for more options: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle with advanced options loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: function(path, scriptEl) { /* execute code before fetch */ }, async: true, // load files synchronously or asynchronously (default: true) numRetries: 3 // see caveats about using numRetries with async:false (default: 0), returnPromise: false // return Promise object (default: false) }); loadjs.ready('foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(depsNotFound) { /* foobar bundle load failed */ }, }); </script> ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js) (for development) * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js) (for production) It's also available from these public CDNs: * UNPKG * [https://unpkg.com/[email protected]/dist/loadjs.js](https://unpkg.com/[email protected]/dist/loadjs.js) (for development) * [https://unpkg.com/[email protected]/dist/loadjs.min.js](https://unpkg.com/[email protected]/dist/loadjs.min.js) (for production) * CDNJS * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js) (for development) * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js) (for production) You can also use it as a CJS or AMD module: ```bash $ npm install --save loadjs ``` ```javascript var loadjs = require('loadjs'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` ## Browser Support * IE9+ (`async: false` support only works in IE10+) * Opera 12+ * Safari 5+ * Chrome * Firefox * iOS 6+ * Android 4.4+ LoadJS also detects script load failures from AdBlock Plus and Ghostery in: * Safari * Chrome Note: LoadJS treats empty CSS files as load failures in IE9-11 and uses `rel="preload"` to load CSS files in Edge (to get around lack of support for onerror events on `<link rel="stylesheet">` tags) ## Documentation 1. Load a single file ```javascript loadjs('/path/to/foo.js', function() { /* foo.js loaded */ }); ``` 1. Fetch files in parallel and load them asynchronously ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() { /* foo.js and bar.js loaded */ }); ``` 1. Fetch JavaScript, CSS and image files ```javascript loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() { /* foo.css, bar.png and thunk.js loaded */ }); ``` 1. Force treat file as CSS stylesheet ```javascript loadjs(['css!/path/to/cssfile.custom'], function() { /* cssfile.custom loaded as stylesheet */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs .ready('foo', function() { /* foo.js loaded */ }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Use Promises to register callbacks ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true}) .then(function() { /* foo.js & bar.js loaded */ }) .catch(function(pathsNotFound) { /* at least one didn't load */ }); ``` 1. Check if bundle has already been defined ```javascript if (!loadjs.isDefined('foobar')) { loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() { /* foo.js and bar.js loaded in series */ }, async: false }); ``` 1. Add an error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ } }); ``` 1. Retry files before calling the error callback }); ``` 1. Execute a callback after bundle finishes loading ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Chain .ready() together ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs .ready('foo', function() { /* foo.js loaded */ }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Compose more complex dependency lists ```javascript loadjs('/path/to/foo.js', 'foo'); // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries ``` 1. Execute a callback before script tags are embedded ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { /* called for each script node before being embedded */ if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; } }); ``` 1. Bypass LoadJS default DOM insertion mechanism (DOM `<head>`) ```javascript loadjs(['/path/to/foo.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { document.body.appendChild(scriptEl); /* return `false` to bypass default DOM insertion mechanism */ return false; } }); ``` 1. Use bundle ids in error callback ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs(['/path/to/thunkor.js', '/path/to/thunky.js'], 'thunk'); // wait for multiple depdendencies loadjs.ready(['foo', 'bar', 'thunk'], { success: function() { // foo.js & bar.js & thunkor.js & thunky.js loaded }, error: function(depsNotFound) { if (depsNotFound.indexOf('foo') > -1) {}; // foo failed if (depsNotFound.indexOf('bar') > -1) {}; // bar failed if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed } }); ``` 1. Use .done() for more control ```javascript loadjs.ready(['dependency1', 'dependency2'], function() { /* run code after dependencies have been met */ }); function fn1() { loadjs.done('dependency1'); } function fn2() { loadjs.done('dependency2'); } ``` 1. Reset dependency trackers ```javascript loadjs.reset(); ``` 1. Implement a require-like dependency manager ```javascript var bundles = { 'bundleA': ['/file1.js', '/file2.js'], 'bundleB': ['/file3.js', '/file4.js'] }; function require(bundleIds, callbackFn) { bundleIds.forEach(function(bundleId) { if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId); }); loadjs.ready(bundleIds, callbackFn); } require(['bundleA'], function() { /* bundleA loaded */ }); require(['bundleB'], function() { /* bundleB loaded */ }); require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ }); ``` ## Directory structure <pre> loadjs/ β”œβ”€β”€ dist β”‚Β Β  β”œβ”€β”€ loadjs.js β”‚Β Β  β”œβ”€β”€ loadjs.min.js β”‚Β Β  └── loadjs.umd.js β”œβ”€β”€ examples β”œβ”€β”€ gulpfile.js β”œβ”€β”€ LICENSE.txt β”œβ”€β”€ package.json β”œβ”€β”€ README.md β”œβ”€β”€ src β”‚Β Β  └── loadjs.js β”œβ”€β”€ test └── umd-templates </pre> ## Development Quickstart 1. Install dependencies * [nodejs](http://nodejs.org/) * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository ```bash $ git clone [email protected]:muicss/loadjs.git $ cd loadjs ``` 1. Install node dependencies using npm ```bash $ npm install ``` 1. Build examples ```bash $ npm run build-examples ``` To view the examples you can use any static file server. To use the `nodejs` http-server module: ```bash $ npm install http-server $ npm run http-server -- -p 3000 ``` Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files ```bash $ npm run build-dist ``` The files will be located in the `dist` directory. 1. Run tests To run the browser tests first build the `loadjs` library: ```bash $ npm run build-tests ``` Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files ```bash $ npm run build-all ``` <MSG> improvements to README <DFF> @@ -128,6 +128,42 @@ Note: LoadJS treats empty CSS files as load failures in IE (to get around lack o } ``` +1. Use bundle ids in dependency lists + + ```javascript + loadjs(['/path/to/foo1.js', '/path/to/foo2.js'], 'foo'); + loadjs(['/path/to/bar1.js', '/path/to/bar2.js'], 'bar'); + + loadjs(['foo', 'bar'], function() { + /* foo1.js & foo2.js & bar1.js & bar2.js loaded */ + }); + ``` + +1. Use .ready() to define bundles and callbacks separately + + ```javascript + loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); + + loadjs.ready('foobar', function() { + /* foo.js & bar.js loaded */ + }); + ``` + +1. Chain .ready() together + + ```javascript + loadjs('/path/to/foo.js', 'foo'); + loadjs('/path/to/bar.js', 'bar'); + + loadjs + .ready('foo', function() { + /* foo.js loaded */ + }) + .ready('bar', function() { + /* bar.js loaded */ + }); + ``` + 1. Fetch files in parallel and load them in series ```javascript @@ -184,32 +220,7 @@ Note: LoadJS treats empty CSS files as load failures in IE (to get around lack o }); ``` -1. Execute a callback after bundle finishes loading - - ```javascript - loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); - - loadjs.ready('foobar', function() { - /* foo.js & bar.js loaded */ - }); - ``` - -1. Chain .ready() together - - ```javascript - loadjs('/path/to/foo.js', 'foo'); - loadjs('/path/to/bar.js', 'bar'); - - loadjs - .ready('foo', function() { - /* foo.js loaded */ - }) - .ready('bar', function() { - /* bar.js loaded */ - }); - ``` - -1. Compose more complex dependency lists +1. Use bundle ids in error callback ```javascript loadjs('/path/to/foo.js', 'foo');
37
improvements to README
26
.md
md
mit
muicss/loadjs
10067053
<NME> README.md <BEF> # LoadJS <img src="https://www.muicss.com/static/images/loadjs.svg" width="250px"> LoadJS is a tiny async loader for modern browsers (899 bytes). [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs?type=dev) [![CDNJS](https://img.shields.io/cdnjs/v/loadjs.svg)](https://cdnjs.com/libraries/loadjs) ## Introduction LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript, CSS and image files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code of [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) in your &lt;html&gt; (possibly in the &lt;head&gt; tag) and then use the `loadjs` global to manage JavaScript dependencies after pageload. LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 899 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle and execute code when it loads loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); </script> ``` You can also use more advanced syntax for more options: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle with advanced options loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: function(path, scriptEl) { /* execute code before fetch */ }, async: true, // load files synchronously or asynchronously (default: true) numRetries: 3 // see caveats about using numRetries with async:false (default: 0), returnPromise: false // return Promise object (default: false) }); loadjs.ready('foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(depsNotFound) { /* foobar bundle load failed */ }, }); </script> ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js) (for development) * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js) (for production) It's also available from these public CDNs: * UNPKG * [https://unpkg.com/[email protected]/dist/loadjs.js](https://unpkg.com/[email protected]/dist/loadjs.js) (for development) * [https://unpkg.com/[email protected]/dist/loadjs.min.js](https://unpkg.com/[email protected]/dist/loadjs.min.js) (for production) * CDNJS * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js) (for development) * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js) (for production) You can also use it as a CJS or AMD module: ```bash $ npm install --save loadjs ``` ```javascript var loadjs = require('loadjs'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` ## Browser Support * IE9+ (`async: false` support only works in IE10+) * Opera 12+ * Safari 5+ * Chrome * Firefox * iOS 6+ * Android 4.4+ LoadJS also detects script load failures from AdBlock Plus and Ghostery in: * Safari * Chrome Note: LoadJS treats empty CSS files as load failures in IE9-11 and uses `rel="preload"` to load CSS files in Edge (to get around lack of support for onerror events on `<link rel="stylesheet">` tags) ## Documentation 1. Load a single file ```javascript loadjs('/path/to/foo.js', function() { /* foo.js loaded */ }); ``` 1. Fetch files in parallel and load them asynchronously ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() { /* foo.js and bar.js loaded */ }); ``` 1. Fetch JavaScript, CSS and image files ```javascript loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() { /* foo.css, bar.png and thunk.js loaded */ }); ``` 1. Force treat file as CSS stylesheet ```javascript loadjs(['css!/path/to/cssfile.custom'], function() { /* cssfile.custom loaded as stylesheet */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs .ready('foo', function() { /* foo.js loaded */ }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Use Promises to register callbacks ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true}) .then(function() { /* foo.js & bar.js loaded */ }) .catch(function(pathsNotFound) { /* at least one didn't load */ }); ``` 1. Check if bundle has already been defined ```javascript if (!loadjs.isDefined('foobar')) { loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() { /* foo.js and bar.js loaded in series */ }, async: false }); ``` 1. Add an error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ } }); ``` 1. Retry files before calling the error callback }); ``` 1. Execute a callback after bundle finishes loading ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Chain .ready() together ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs .ready('foo', function() { /* foo.js loaded */ }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Compose more complex dependency lists ```javascript loadjs('/path/to/foo.js', 'foo'); // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries ``` 1. Execute a callback before script tags are embedded ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { /* called for each script node before being embedded */ if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; } }); ``` 1. Bypass LoadJS default DOM insertion mechanism (DOM `<head>`) ```javascript loadjs(['/path/to/foo.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { document.body.appendChild(scriptEl); /* return `false` to bypass default DOM insertion mechanism */ return false; } }); ``` 1. Use bundle ids in error callback ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs(['/path/to/thunkor.js', '/path/to/thunky.js'], 'thunk'); // wait for multiple depdendencies loadjs.ready(['foo', 'bar', 'thunk'], { success: function() { // foo.js & bar.js & thunkor.js & thunky.js loaded }, error: function(depsNotFound) { if (depsNotFound.indexOf('foo') > -1) {}; // foo failed if (depsNotFound.indexOf('bar') > -1) {}; // bar failed if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed } }); ``` 1. Use .done() for more control ```javascript loadjs.ready(['dependency1', 'dependency2'], function() { /* run code after dependencies have been met */ }); function fn1() { loadjs.done('dependency1'); } function fn2() { loadjs.done('dependency2'); } ``` 1. Reset dependency trackers ```javascript loadjs.reset(); ``` 1. Implement a require-like dependency manager ```javascript var bundles = { 'bundleA': ['/file1.js', '/file2.js'], 'bundleB': ['/file3.js', '/file4.js'] }; function require(bundleIds, callbackFn) { bundleIds.forEach(function(bundleId) { if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId); }); loadjs.ready(bundleIds, callbackFn); } require(['bundleA'], function() { /* bundleA loaded */ }); require(['bundleB'], function() { /* bundleB loaded */ }); require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ }); ``` ## Directory structure <pre> loadjs/ β”œβ”€β”€ dist β”‚Β Β  β”œβ”€β”€ loadjs.js β”‚Β Β  β”œβ”€β”€ loadjs.min.js β”‚Β Β  └── loadjs.umd.js β”œβ”€β”€ examples β”œβ”€β”€ gulpfile.js β”œβ”€β”€ LICENSE.txt β”œβ”€β”€ package.json β”œβ”€β”€ README.md β”œβ”€β”€ src β”‚Β Β  └── loadjs.js β”œβ”€β”€ test └── umd-templates </pre> ## Development Quickstart 1. Install dependencies * [nodejs](http://nodejs.org/) * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository ```bash $ git clone [email protected]:muicss/loadjs.git $ cd loadjs ``` 1. Install node dependencies using npm ```bash $ npm install ``` 1. Build examples ```bash $ npm run build-examples ``` To view the examples you can use any static file server. To use the `nodejs` http-server module: ```bash $ npm install http-server $ npm run http-server -- -p 3000 ``` Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files ```bash $ npm run build-dist ``` The files will be located in the `dist` directory. 1. Run tests To run the browser tests first build the `loadjs` library: ```bash $ npm run build-tests ``` Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files ```bash $ npm run build-all ``` <MSG> improvements to README <DFF> @@ -128,6 +128,42 @@ Note: LoadJS treats empty CSS files as load failures in IE (to get around lack o } ``` +1. Use bundle ids in dependency lists + + ```javascript + loadjs(['/path/to/foo1.js', '/path/to/foo2.js'], 'foo'); + loadjs(['/path/to/bar1.js', '/path/to/bar2.js'], 'bar'); + + loadjs(['foo', 'bar'], function() { + /* foo1.js & foo2.js & bar1.js & bar2.js loaded */ + }); + ``` + +1. Use .ready() to define bundles and callbacks separately + + ```javascript + loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); + + loadjs.ready('foobar', function() { + /* foo.js & bar.js loaded */ + }); + ``` + +1. Chain .ready() together + + ```javascript + loadjs('/path/to/foo.js', 'foo'); + loadjs('/path/to/bar.js', 'bar'); + + loadjs + .ready('foo', function() { + /* foo.js loaded */ + }) + .ready('bar', function() { + /* bar.js loaded */ + }); + ``` + 1. Fetch files in parallel and load them in series ```javascript @@ -184,32 +220,7 @@ Note: LoadJS treats empty CSS files as load failures in IE (to get around lack o }); ``` -1. Execute a callback after bundle finishes loading - - ```javascript - loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); - - loadjs.ready('foobar', function() { - /* foo.js & bar.js loaded */ - }); - ``` - -1. Chain .ready() together - - ```javascript - loadjs('/path/to/foo.js', 'foo'); - loadjs('/path/to/bar.js', 'bar'); - - loadjs - .ready('foo', function() { - /* foo.js loaded */ - }) - .ready('bar', function() { - /* bar.js loaded */ - }); - ``` - -1. Compose more complex dependency lists +1. Use bundle ids in error callback ```javascript loadjs('/path/to/foo.js', 'foo');
37
improvements to README
26
.md
md
mit
muicss/loadjs
10067054
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067055
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067056
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067057
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067058
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067059
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067060
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067061
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067062
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067063
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067064
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067065
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067066
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067067
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067068
<NME> TextEditorModelTests.cs <BEF> ADDFILE <MSG> Merge pull request #186 from AvaloniaUI/improve-TM-perf Improve TextMate performance <DFF> @@ -0,0 +1,279 @@ +ο»Ώusing AvaloniaEdit.Document; +using AvaloniaEdit.Rendering; +using AvaloniaEdit.TextMate; + +using NUnit.Framework; + +namespace AvaloniaEdit.Tests.TextMate +{ + [TestFixture] + internal class TextEditorModelTests + { + [Test] + public void Lines_Should_Have_Valid_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + } + + [Test] + public void Lines_Should_Have_Valid_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + Assert.AreEqual("puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy", textEditorModel.GetLineText(0)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(1)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(2)); + } + + [Test] + public void Editing_Line_Should_Update_The_Line_Length() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + Assert.AreEqual("cutty puppy".Length, textEditorModel.GetLineLength(0)); + } + + [Test] + public void Inserting_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + Assert.AreEqual("lion", textEditorModel.GetLineText(0)); + Assert.AreEqual("puppy", textEditorModel.GetLineText(1)); + Assert.AreEqual("pussy", textEditorModel.GetLineText(2)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(3)); + } + + [Test] + public void Removing_Line_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Removing_Line_With_LFCR_Should_Update_The_Line_Ranges() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\r\npussy\r\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + Assert.AreEqual("pussy", textEditorModel.GetLineText(0)); + Assert.AreEqual("birdie", textEditorModel.GetLineText(1)); + } + + [Test] + public void Document_Lines_Count_Should_Match_Model_Lines_Count() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Edit_Document_Line_Should_Not_Add_Or_Remove_Model_Lines() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "cutty "); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Insert_Document_Line_Should_Insert_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Insert(0, "lion\n"); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Remove_Document_Line_Should_Remove_Model_Line() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Remove( + document.Lines[0].Offset, + document.Lines[0].TotalLength); + + int count = 0; + textEditorModel.ForEach((m) => count++); + + Assert.AreEqual(document.LineCount, count); + } + + [Test] + public void Replace_Text_Of_Same_Length_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "P"); + + Assert.AreEqual("Puppy", textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Text_Of_Same_Length_With_CR_Should_Update_Line_Content() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + + document.Replace(0, 1, "\n"); + + Assert.AreEqual("", textEditorModel.GetLineText(0)); + } + + [Test] + public void Remove_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = string.Empty; + Assert.AreEqual(1, textEditorModel.GetNumberOfLines()); + Assert.AreEqual(string.Empty, textEditorModel.GetLineText(0)); + } + + [Test] + public void Replace_Document_Text_Should_Update_Line_Contents() + { + TextView textView = new TextView(); + TextDocument document = new TextDocument(); + + TextEditorModel textEditorModel = new TextEditorModel( + textView, document, null); + + document.Text = "puppy\npussy\nbirdie"; + Assert.AreEqual(3, textEditorModel.GetNumberOfLines()); + + document.Text = "one\ntwo\nthree\nfour"; + Assert.AreEqual(4, textEditorModel.GetNumberOfLines()); + + Assert.AreEqual("one", textEditorModel.GetLineText(0)); + Assert.AreEqual("two", textEditorModel.GetLineText(1)); + Assert.AreEqual("three", textEditorModel.GetLineText(2)); + Assert.AreEqual("four", textEditorModel.GetLineText(3)); + } + } +}
279
Merge pull request #186 from AvaloniaUI/improve-TM-perf
0
.cs
Tests/TextMate/TextEditorModelTests
mit
AvaloniaUI/AvaloniaEdit
10067069
<NME> tests.js <BEF> /** * loadjs tests * @module test/tests.js */ var pathsLoaded = null, // file register testEl = null, expect = chai.expect; describe('loadjs tests', function() { beforeEach(function() { // reset register pathsLoaded = {}; // reset loadjs dependencies loadjs.reset(); }); // ========================================================================== // JavaScript file loading tests // ========================================================================== describe('JavaScript file loading tests', function() { it('should call success callback on valid path', function(done) { loadjs(['assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); done(); } }); }); it('should call error callback on invalid path', function(done) { loadjs(['assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should call before callback before embedding into document', function(done) { var scriptTags = []; loadjs(['assets/file1.js', 'assets/file2.js'], { before: function(path, el) { scriptTags.push({ path: path, done(); }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); // define callback loadjs.ready('bundle1', function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); }); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle2', function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); }); // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); }); it('should throw an error if bundle is already defined', function() { } }, success: function() { assert.equal(scriptTags[0].path, 'assets/file1.js'); assert.equal(scriptTags[1].path, 'assets/file2.js'); loadjs(['assets/file1.js'], 'bundle3'); }; expect(fn).to.throw(Error, /already been defined/); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', function() { it('should bypass insertion if before returns `false`', function(done) { loadjs(['assets/file1.js'], { before: function(path, el) { // append to body (instead of head) document.body.appendChild(el); // return `false` to bypass default DOM insertion return false; }, success: function() { assert.equal(pathsLoaded['file1.js'], true); // verify that file was added to body var els = document.body.querySelectorAll('script'), el; for (var i=0; i < els.length; i++) { el = els[i]; if (el.src.indexOf('assets/file1.js') !== -1) done(); } } }); }); it('should call success callback on two valid paths', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should call error callback on one invalid path', function(done) { loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, error: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should support async false', function(done) { this.timeout(5000); var numCompleted = 0, numTests = 20, paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; // run tests sequentially var testFn = function(paths) { // add cache busters var pathsUncached = paths.slice(0); pathsUncached[0] += '?_=' + Math.random(); loadjs.done('plugin1'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin2'); // check load order assert.isTrue(pathsLoaded[f1]); assert.isFalse(pathsLoaded[f2]); done(); }); }); }); }); }); // Un-'x' this for testing ad blocked scripts. // Ghostery: Disallow "Google Adservices" // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a // custom filter under Options // xit('it should report ad blocked scripts as missing', function(done) { var s1 = 'https://www.googletagservices.com/tag/js/gpt.js', s2 = 'https://munchkin.marketo.net/munchkin-beta.js'; loadjs([s1, s2, 'assets/file1.js'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 2); assert.equal(pathsNotFound[0], s1); assert.equal(pathsNotFound[1], s2); done(); } }); }); }); // ========================================================================== // CSS file loading tests // ========================================================================== describe('CSS file loading tests', function() { before(function() { // add test div to body for css tests testEl = document.createElement('div'); testEl.className = 'test-div mui-container'; testEl.style.display = 'inline-block'; document.body.appendChild(testEl); }); afterEach(function() { var els = document.getElementsByTagName('link'), i = els.length, el; // iteratete through stylesheets while (i--) { el = els[i]; // remove test stylesheets if (el.href.indexOf('mocha.css') === -1) { el.parentNode.removeChild(el); } } }); it('should load one file', function(done) { loadjs(['assets/file1.css'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should load multiple files', function(done) { loadjs(['assets/file1.css', 'assets/file2.css'], { success: function() { assert.equal(testEl.offsetWidth, 200); done(); } }); }); it('should call error callback on one invalid path', function(done) { loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(testEl.offsetWidth, 100); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css'); done(); } }); }); it('should support mix of css and js', function(done) { loadjs(['assets/file1.css', 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should support forced "css!" files', function(done) { loadjs(['css!assets/file1.css'], { success: function() { // loop through files var els = document.getElementsByTagName('link'), i = els.length, el; while (i--) { if (els[i].href.indexOf('file1.css') !== -1) done(); } } }); }); it('supports urls with query arguments', function(done) { loadjs(['assets/file1.css?x=x'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('supports urls with anchor tags', function(done) { loadjs(['assets/file1.css#anchortag'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('supports urls with query arguments and anchor tags', function(done) { loadjs(['assets/file1.css?x=x#anchortag'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should load external css files', function(done) { this.timeout(0); loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui.min.css'], { success: function() { var styleObj = getComputedStyle(testEl); assert.equal(styleObj.getPropertyValue('padding-left'), '15px'); done(); } }); }); it('should call error on missing external file', function(done) { this.timeout(0); loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui-doesnotexist.min.css'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { var styleObj = getComputedStyle(testEl); assert.equal(styleObj.getPropertyValue('padding-left'), '0px'); assert.equal(pathsNotFound.length, 1); done(); } }); }); // teardown return after(function() { // remove test div testEl.parentNode.removeChild(testEl); }); }); // ========================================================================== // Image file loading tests // ========================================================================== describe('Image file loading tests', function() { function assertLoaded(src) { // loop through images var imgs = document.getElementsByTagName('img'); Array.prototype.slice.call(imgs).forEach(function(img) { // verify image was loaded if (img.src === src) assert.equal(img.naturalWidth > 0, true); }); } function assertNotLoaded(src) { // loop through images var imgs = document.getElementsByTagName('img'); Array.prototype.slice.call(imgs).forEach(function(img) { // fail if image was loaded if (img.src === src) assert.equal(img.naturalWidth, 0); }); } it('should load one file', function(done) { loadjs(['assets/flash.png'], { success: function() { assertLoaded('assets/flash.png'); done(); } }); }); it('should load multiple files', function(done) { loadjs(['assets/flash.png', 'assets/flash.jpg'], { success: function() { assertLoaded('assets/flash.png'); assertLoaded('assets/flash.jpg'); done(); } }); }); it('detects png|gif|jpg|svg|webp extensions', function(done) { let files = [ 'assets/flash.png', 'assets/flash.gif', 'assets/flash.jpg', 'assets/flash.svg', 'assets/flash.webp' ]; loadjs(files, function() { files.forEach(file => {assertLoaded(file);}); done(); }); }); it('supports urls with query arguments', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('supports urls with anchor tags', function(done) { var src = 'assets/flash.png#' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('supports urls with query arguments and anchor tags', function(done) { var src = 'assets/flash.png'; src += '?' + Math.random(); src += '#' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('should support forced "img!" files', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error callback on one invalid path', function(done) { var src1 = 'assets/flash.png?' + Math.random(), src2 = 'assets/flash-doesntexist.png?' + Math.random(); loadjs(['img!' + src1, 'img!' + src2], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assertLoaded(src1); assertNotLoaded(src2); done(); } }); }); it('should support mix of img and js', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src, 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assertLoaded(src); done(); } }); }); it('should load external img files', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/mui-logo.png?'; src += Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error on missing external file', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/'; src += 'mui-logo-doesntexist.png?' + Math.random(); loadjs(['img!' + src], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assertNotLoaded(src); done(); } }); }); }); // ========================================================================== // API tests // ========================================================================== describe('API tests', function() { it('should throw an error if bundle is already defined', function() { // define bundle loadjs(['assets/file1.js'], 'bundle'); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'bundle'); }; expect(fn).to.throw("LoadJS"); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should chain loadjs object', function(done) { function bothDone() { if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } // define bundles loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs .ready('bundle1', { success: function() { assert.equal(pathsLoaded['file1.js'], true); bothDone(); }}) .ready('bundle2', { success: function() { assert.equal(pathsLoaded['file2.js'], true); bothDone(); } }); }); it('should handle multiple dependencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should error on missing depdendencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file-doesntexist.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { throw "Executed success callback"; }, error: function(depsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(depsNotFound.length, 1); assert.equal(depsNotFound[0], 'bundle2'); done(); } }); }); it('should execute callbacks on .done()', function(done) { // add handler loadjs.ready('plugin', { success: function() { done(); } }); // execute done loadjs.done('plugin'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin'); // add handler loadjs.ready('plugin', { success: function() { done(); } }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); // use 1 second delay to let files load setTimeout(function() { loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }, 1000); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); // use 1 second delay setTimeout(function() { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); }, 1000); }); it('should reset dependencies statuses', function() { loadjs(['assets/file1.js'], 'cleared'); loadjs.reset(); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'cleared'); }; expect(fn).not.to.throw("LoadJS"); }); it('should indicate if bundle has already been defined', function() { loadjs(['assets/file1/js'], 'bundle1'); assert.equal(loadjs.isDefined('bundle1'), true); assert.equal(loadjs.isDefined('bundleXX'), false); }); it('should accept success callback functions to loadjs()', function(done) { loadjs('assets/file1.js', function() { done(); }); }); it('should accept success callback functions to .ready()', function(done) { loadjs.done('plugin'); loadjs.ready('plugin', function() { done(); }); }); it('should return Promise object if returnPromise is true', function() { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); // verify that response object is a Promise assert.equal(prom instanceof Promise, true); }); it('Promise object should support resolutions', function(done) { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); prom.then(function() { assert.equal(pathsLoaded['file1.js'], true); done(); }); }); it('Promise object should support rejections', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom.then( function(){}, function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } ); }); it('Promise object should support catches', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom .catch(function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); }); }); it('supports Promises and success callbacks', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; var prom = loadjs('assets/file1.js', { success: completedFn, returnPromise: true }); prom.then(completedFn); }); it('supports Promises and bundle ready events', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; loadjs('assets/file1.js', 'bundle1', {returnPromise: true}) .then(completedFn); loadjs.ready('bundle1', completedFn); }); }); }); <MSG> Refactored code using pubsub model, 590 bytes gzipped <DFF> @@ -8,7 +8,7 @@ var pathsLoaded = null, // file register expect = chai.expect; -describe('loadjs tests', function() { +describe('LoadJS tests', function() { beforeEach(function() { @@ -59,32 +59,6 @@ describe('loadjs tests', function() { done(); }); }); - - - it('should define bundles', function(done) { - // define bundle - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); - - // define callback - loadjs.ready('bundle1', function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); - }); - }); - - - it('should allow bundle callbacks before definitions', function(done) { - // define callback - loadjs.ready('bundle2', function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); - }); - - // define bundle - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); - }); it('should throw an error if bundle is already defined', function() { @@ -96,9 +70,9 @@ describe('loadjs tests', function() { loadjs(['assets/file1.js'], 'bundle3'); }; - expect(fn).to.throw(Error, /already been defined/); + expect(fn).to.throw(Error, "LoadJS: Bundle already defined"); }); - + it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', function() { @@ -169,7 +143,7 @@ describe('loadjs tests', function() { loadjs.done('plugin1'); }); - + it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin2'); @@ -179,4 +153,34 @@ describe('loadjs tests', function() { done(); }); }); + + + it('should define bundles', function(done) { + // define bundle + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); + + // use 1 second delay to let files load + setTimeout(function() { + loadjs.ready('bundle1', function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + }); + }, 1000); + }); + + + it('should allow bundle callbacks before definitions', function(done) { + // define callback + loadjs.ready('bundle2', function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + }); + + // use 1 second delay + setTimeout(function() { + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); + }, 1000); + }); });
34
Refactored code using pubsub model, 590 bytes gzipped
30
.js
js
mit
muicss/loadjs
10067070
<NME> tests.js <BEF> /** * loadjs tests * @module test/tests.js */ var pathsLoaded = null, // file register testEl = null, expect = chai.expect; describe('loadjs tests', function() { beforeEach(function() { // reset register pathsLoaded = {}; // reset loadjs dependencies loadjs.reset(); }); // ========================================================================== // JavaScript file loading tests // ========================================================================== describe('JavaScript file loading tests', function() { it('should call success callback on valid path', function(done) { loadjs(['assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); done(); } }); }); it('should call error callback on invalid path', function(done) { loadjs(['assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should call before callback before embedding into document', function(done) { var scriptTags = []; loadjs(['assets/file1.js', 'assets/file2.js'], { before: function(path, el) { scriptTags.push({ path: path, done(); }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); // define callback loadjs.ready('bundle1', function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); }); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle2', function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); }); // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); }); it('should throw an error if bundle is already defined', function() { } }, success: function() { assert.equal(scriptTags[0].path, 'assets/file1.js'); assert.equal(scriptTags[1].path, 'assets/file2.js'); loadjs(['assets/file1.js'], 'bundle3'); }; expect(fn).to.throw(Error, /already been defined/); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', function() { it('should bypass insertion if before returns `false`', function(done) { loadjs(['assets/file1.js'], { before: function(path, el) { // append to body (instead of head) document.body.appendChild(el); // return `false` to bypass default DOM insertion return false; }, success: function() { assert.equal(pathsLoaded['file1.js'], true); // verify that file was added to body var els = document.body.querySelectorAll('script'), el; for (var i=0; i < els.length; i++) { el = els[i]; if (el.src.indexOf('assets/file1.js') !== -1) done(); } } }); }); it('should call success callback on two valid paths', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should call error callback on one invalid path', function(done) { loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, error: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should support async false', function(done) { this.timeout(5000); var numCompleted = 0, numTests = 20, paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; // run tests sequentially var testFn = function(paths) { // add cache busters var pathsUncached = paths.slice(0); pathsUncached[0] += '?_=' + Math.random(); loadjs.done('plugin1'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin2'); // check load order assert.isTrue(pathsLoaded[f1]); assert.isFalse(pathsLoaded[f2]); done(); }); }); }); }); }); // Un-'x' this for testing ad blocked scripts. // Ghostery: Disallow "Google Adservices" // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a // custom filter under Options // xit('it should report ad blocked scripts as missing', function(done) { var s1 = 'https://www.googletagservices.com/tag/js/gpt.js', s2 = 'https://munchkin.marketo.net/munchkin-beta.js'; loadjs([s1, s2, 'assets/file1.js'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 2); assert.equal(pathsNotFound[0], s1); assert.equal(pathsNotFound[1], s2); done(); } }); }); }); // ========================================================================== // CSS file loading tests // ========================================================================== describe('CSS file loading tests', function() { before(function() { // add test div to body for css tests testEl = document.createElement('div'); testEl.className = 'test-div mui-container'; testEl.style.display = 'inline-block'; document.body.appendChild(testEl); }); afterEach(function() { var els = document.getElementsByTagName('link'), i = els.length, el; // iteratete through stylesheets while (i--) { el = els[i]; // remove test stylesheets if (el.href.indexOf('mocha.css') === -1) { el.parentNode.removeChild(el); } } }); it('should load one file', function(done) { loadjs(['assets/file1.css'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should load multiple files', function(done) { loadjs(['assets/file1.css', 'assets/file2.css'], { success: function() { assert.equal(testEl.offsetWidth, 200); done(); } }); }); it('should call error callback on one invalid path', function(done) { loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(testEl.offsetWidth, 100); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css'); done(); } }); }); it('should support mix of css and js', function(done) { loadjs(['assets/file1.css', 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should support forced "css!" files', function(done) { loadjs(['css!assets/file1.css'], { success: function() { // loop through files var els = document.getElementsByTagName('link'), i = els.length, el; while (i--) { if (els[i].href.indexOf('file1.css') !== -1) done(); } } }); }); it('supports urls with query arguments', function(done) { loadjs(['assets/file1.css?x=x'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('supports urls with anchor tags', function(done) { loadjs(['assets/file1.css#anchortag'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('supports urls with query arguments and anchor tags', function(done) { loadjs(['assets/file1.css?x=x#anchortag'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should load external css files', function(done) { this.timeout(0); loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui.min.css'], { success: function() { var styleObj = getComputedStyle(testEl); assert.equal(styleObj.getPropertyValue('padding-left'), '15px'); done(); } }); }); it('should call error on missing external file', function(done) { this.timeout(0); loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui-doesnotexist.min.css'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { var styleObj = getComputedStyle(testEl); assert.equal(styleObj.getPropertyValue('padding-left'), '0px'); assert.equal(pathsNotFound.length, 1); done(); } }); }); // teardown return after(function() { // remove test div testEl.parentNode.removeChild(testEl); }); }); // ========================================================================== // Image file loading tests // ========================================================================== describe('Image file loading tests', function() { function assertLoaded(src) { // loop through images var imgs = document.getElementsByTagName('img'); Array.prototype.slice.call(imgs).forEach(function(img) { // verify image was loaded if (img.src === src) assert.equal(img.naturalWidth > 0, true); }); } function assertNotLoaded(src) { // loop through images var imgs = document.getElementsByTagName('img'); Array.prototype.slice.call(imgs).forEach(function(img) { // fail if image was loaded if (img.src === src) assert.equal(img.naturalWidth, 0); }); } it('should load one file', function(done) { loadjs(['assets/flash.png'], { success: function() { assertLoaded('assets/flash.png'); done(); } }); }); it('should load multiple files', function(done) { loadjs(['assets/flash.png', 'assets/flash.jpg'], { success: function() { assertLoaded('assets/flash.png'); assertLoaded('assets/flash.jpg'); done(); } }); }); it('detects png|gif|jpg|svg|webp extensions', function(done) { let files = [ 'assets/flash.png', 'assets/flash.gif', 'assets/flash.jpg', 'assets/flash.svg', 'assets/flash.webp' ]; loadjs(files, function() { files.forEach(file => {assertLoaded(file);}); done(); }); }); it('supports urls with query arguments', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('supports urls with anchor tags', function(done) { var src = 'assets/flash.png#' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('supports urls with query arguments and anchor tags', function(done) { var src = 'assets/flash.png'; src += '?' + Math.random(); src += '#' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('should support forced "img!" files', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error callback on one invalid path', function(done) { var src1 = 'assets/flash.png?' + Math.random(), src2 = 'assets/flash-doesntexist.png?' + Math.random(); loadjs(['img!' + src1, 'img!' + src2], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assertLoaded(src1); assertNotLoaded(src2); done(); } }); }); it('should support mix of img and js', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src, 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assertLoaded(src); done(); } }); }); it('should load external img files', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/mui-logo.png?'; src += Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error on missing external file', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/'; src += 'mui-logo-doesntexist.png?' + Math.random(); loadjs(['img!' + src], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assertNotLoaded(src); done(); } }); }); }); // ========================================================================== // API tests // ========================================================================== describe('API tests', function() { it('should throw an error if bundle is already defined', function() { // define bundle loadjs(['assets/file1.js'], 'bundle'); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'bundle'); }; expect(fn).to.throw("LoadJS"); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should chain loadjs object', function(done) { function bothDone() { if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } // define bundles loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs .ready('bundle1', { success: function() { assert.equal(pathsLoaded['file1.js'], true); bothDone(); }}) .ready('bundle2', { success: function() { assert.equal(pathsLoaded['file2.js'], true); bothDone(); } }); }); it('should handle multiple dependencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should error on missing depdendencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file-doesntexist.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { throw "Executed success callback"; }, error: function(depsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(depsNotFound.length, 1); assert.equal(depsNotFound[0], 'bundle2'); done(); } }); }); it('should execute callbacks on .done()', function(done) { // add handler loadjs.ready('plugin', { success: function() { done(); } }); // execute done loadjs.done('plugin'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin'); // add handler loadjs.ready('plugin', { success: function() { done(); } }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); // use 1 second delay to let files load setTimeout(function() { loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }, 1000); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); // use 1 second delay setTimeout(function() { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); }, 1000); }); it('should reset dependencies statuses', function() { loadjs(['assets/file1.js'], 'cleared'); loadjs.reset(); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'cleared'); }; expect(fn).not.to.throw("LoadJS"); }); it('should indicate if bundle has already been defined', function() { loadjs(['assets/file1/js'], 'bundle1'); assert.equal(loadjs.isDefined('bundle1'), true); assert.equal(loadjs.isDefined('bundleXX'), false); }); it('should accept success callback functions to loadjs()', function(done) { loadjs('assets/file1.js', function() { done(); }); }); it('should accept success callback functions to .ready()', function(done) { loadjs.done('plugin'); loadjs.ready('plugin', function() { done(); }); }); it('should return Promise object if returnPromise is true', function() { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); // verify that response object is a Promise assert.equal(prom instanceof Promise, true); }); it('Promise object should support resolutions', function(done) { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); prom.then(function() { assert.equal(pathsLoaded['file1.js'], true); done(); }); }); it('Promise object should support rejections', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom.then( function(){}, function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } ); }); it('Promise object should support catches', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom .catch(function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); }); }); it('supports Promises and success callbacks', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; var prom = loadjs('assets/file1.js', { success: completedFn, returnPromise: true }); prom.then(completedFn); }); it('supports Promises and bundle ready events', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; loadjs('assets/file1.js', 'bundle1', {returnPromise: true}) .then(completedFn); loadjs.ready('bundle1', completedFn); }); }); }); <MSG> Refactored code using pubsub model, 590 bytes gzipped <DFF> @@ -8,7 +8,7 @@ var pathsLoaded = null, // file register expect = chai.expect; -describe('loadjs tests', function() { +describe('LoadJS tests', function() { beforeEach(function() { @@ -59,32 +59,6 @@ describe('loadjs tests', function() { done(); }); }); - - - it('should define bundles', function(done) { - // define bundle - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); - - // define callback - loadjs.ready('bundle1', function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); - }); - }); - - - it('should allow bundle callbacks before definitions', function(done) { - // define callback - loadjs.ready('bundle2', function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); - }); - - // define bundle - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); - }); it('should throw an error if bundle is already defined', function() { @@ -96,9 +70,9 @@ describe('loadjs tests', function() { loadjs(['assets/file1.js'], 'bundle3'); }; - expect(fn).to.throw(Error, /already been defined/); + expect(fn).to.throw(Error, "LoadJS: Bundle already defined"); }); - + it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', function() { @@ -169,7 +143,7 @@ describe('loadjs tests', function() { loadjs.done('plugin1'); }); - + it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin2'); @@ -179,4 +153,34 @@ describe('loadjs tests', function() { done(); }); }); + + + it('should define bundles', function(done) { + // define bundle + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); + + // use 1 second delay to let files load + setTimeout(function() { + loadjs.ready('bundle1', function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + }); + }, 1000); + }); + + + it('should allow bundle callbacks before definitions', function(done) { + // define callback + loadjs.ready('bundle2', function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + }); + + // use 1 second delay + setTimeout(function() { + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); + }, 1000); + }); });
34
Refactored code using pubsub model, 590 bytes gzipped
30
.js
js
mit
muicss/loadjs
10067071
<NME> fruitmachine.js <BEF> /*jslint browser:true, node:true*/ /** * FruitMachine * * Renders layouts/modules from a basic layout definition. * If views require custom interactions devs can extend * the basic functionality. * * @version 0.3.3 * @copyright The Financial Times Limited [All Rights Reserved] * @author Wilson Page <[email protected]> */ 'use strict'; /** * Module Dependencies */ var mod = require('./module'); var define = require('./define'); var utils = require('utils'); var events = require('evt'); /** * Creates a fruitmachine * * Options: * * - `Model` A model constructor to use (must have `.toJSON()`) * * @param {Object} options */ module.exports = function(options) { /** * Shortcut method for * creating lazy views. * * @param {Object} options * @return {Module} */ function fm(options) { var Module = fm.modules[options.module]; if (Module) { return new Module(options); } throw new Error("Unable to find module '" + options.module + "'"); } fm.create = module.exports; fm.Model = options.Model; fm.Events = events; fm.Module = mod(fm); fm.define = define(fm); fm.util = utils; fm.modules = {}; fm.config = { templateIterator: 'children', templateInstance: 'child' }; // Mixin events and return return events(fm); }; return store.templates[module]; }; var stopPropagation = function() { this.propagate = false; }; var View = FruitMachine.View = function(options) { options = mixin({}, options); if (options.module) return create(options); this._configure(options); this.add(options.children); this.onInitialize(options); this.trigger('initialize', options); }; /** return new Module(options); } // Mixin Events and extend the prototype mixin(View.prototype, { on: Events.on, this.setElement(el); // Handy hook this.trigger('render'); return this; }, if (this.isSetup) this.teardown({ shallow: true }); // Fire the `setup` event hook this.trigger('setup'); // Run onSetup custom function this.onSetup(); // variables if setup hasn't run. if (!this.isSetup) return this; this.trigger('teardown'); this.onTeardown(); this.isSetup = false; // Trigger a destroy event // for custom Views to bind to. this.trigger('destroy'); this.onDestroy(); // Remove the model 'change' event <MSG> Stop internally triggered events from propagating <DFF> @@ -325,17 +325,13 @@ return store.templates[module]; }; - var stopPropagation = function() { - this.propagate = false; - }; - var View = FruitMachine.View = function(options) { options = mixin({}, options); if (options.module) return create(options); this._configure(options); this.add(options.children); this.onInitialize(options); - this.trigger('initialize', options); + this.trigger('initialize', [options], { propagate: false }); }; /** @@ -357,6 +353,10 @@ return new Module(options); } + var stopPropagation = function() { + this.propagate = false; + }; + // Mixin Events and extend the prototype mixin(View.prototype, { on: Events.on, @@ -686,7 +686,7 @@ this.setElement(el); // Handy hook - this.trigger('render'); + this.trigger('render', { propagate: false }); return this; }, @@ -727,7 +727,7 @@ if (this.isSetup) this.teardown({ shallow: true }); // Fire the `setup` event hook - this.trigger('setup'); + this.trigger('setup', { propagate: false }); // Run onSetup custom function this.onSetup(); @@ -758,7 +758,7 @@ // variables if setup hasn't run. if (!this.isSetup) return this; - this.trigger('teardown'); + this.trigger('teardown', { propagate: false }); this.onTeardown(); this.isSetup = false; @@ -799,7 +799,7 @@ // Trigger a destroy event // for custom Views to bind to. - this.trigger('destroy'); + this.trigger('destroy', { propagate: false }); this.onDestroy(); // Remove the model 'change' event
9
Stop internally triggered events from propagating
9
.js
js
mit
ftlabs/fruitmachine
10067072
<NME> buster.js <BEF> ADDFILE <MSG> Added test for beforeinitialized event when a view is created using fruitmachine. - This test only tests that the callback was invoked, it does not test the parameters passed to the callback function <DFF> @@ -0,0 +1,12 @@ +var config = module.exports; + +config["FruitMachineTests"] = { + rootPath: '../', + environment: "browser", + sources: [ + 'lib/fruitmachine.js' + ], + tests: [ + 'test/fruitmachine_test.js' + ] +};
12
Added test for beforeinitialized event when a view is created using fruitmachine. - This test only tests that the callback was invoked, it does not test the parameters passed to the callback function
0
.js
js
mit
ftlabs/fruitmachine
10067073
<NME> fruitmachine.js <BEF> /*jslint browser:true, node:true*/ /** * FruitMachine * * Renders layouts/modules from a basic layout definition. * If views require custom interactions devs can extend * the basic functionality. * * @version 0.3.3 * @copyright The Financial Times Limited [All Rights Reserved] * @author Wilson Page <[email protected]> */ 'use strict'; /** * Module Dependencies */ var mod = require('./module'); var define = require('./define'); var utils = require('utils'); var events = require('evt'); /** * Creates a fruitmachine * * Options: * * - `Model` A model constructor to use (must have `.toJSON()`) * * @param {Object} options */ module.exports = function(options) { /** * Shortcut method for * creating lazy views. * * @param {Object} options * @return {Module} */ function fm(options) { var Module = fm.modules[options.module]; if (Module) { return new Module(options); } throw new Error("Unable to find module '" + options.module + "'"); } fm.create = module.exports; fm.Model = options.Model; fm.Events = events; fm.Module = mod(fm); fm.define = define(fm); fm.util = utils; fm.modules = {}; fm.config = { templateIterator: 'children', templateInstance: 'child' }; // Mixin events and return return events(fm); }; toHTML: function() { var data = {}; var children = this.children(); var child, html; data.children = []; // Use cache if populated if (this.html) return this.html; for (var i = 0, l = children.length; i < l; i++) { child = children[i]; html = child.toHTML(); data[child.id()] = html; data.children.push(mixin({ child: html }, child.model.get())); } html = this.template(mixin(data, this.model.get())); setup: function(options) { var shallow = options && options.shallow; var children = this.children(); // Call 'setup' on all subviews // first (bottom up recursion). if (!shallow) { for (var i = 0, l = children.length; i < l; i++) { children[i].setup(); } } // If this is already setup, call teardown: function(options) { var shallow = options && options.shallow; var children = this.children(); // Call 'setup' on all subviews // first (bottom up recursion). if (!shallow) { for (var i = 0, l = children.length; i < l; i++) { children[i].teardown(); } } // Clear the el cache this.onTeardown(); this.isSetup = false; // For chaining return this; }, }, purgeElementCaches: function() { var children = this.children(); var l = children.length, i; for (i = 0; i < l; i++) children[i].purgeElementCaches(); this.clearElement(); }, toJSON: function() { var json = {}; var children = this.children(); json.children = []; // Recurse for (var i = 0, l = children.length; i < l; i++) { json.children.push(children[i].toJSON()); } json.id = this.id(); json.fmid = this._fmid; <MSG> Replace all for loops with View#each() <DFF> @@ -481,19 +481,18 @@ toHTML: function() { var data = {}; - var children = this.children(); - var child, html; + var html; data.children = []; // Use cache if populated if (this.html) return this.html; - for (var i = 0, l = children.length; i < l; i++) { - child = children[i]; + // Loop each child + this.each(function(child) { html = child.toHTML(); data[child.id()] = html; data.children.push(mixin({ child: html }, child.model.get())); - } + }); html = this.template(mixin(data, this.model.get())); @@ -533,14 +532,13 @@ setup: function(options) { var shallow = options && options.shallow; - var children = this.children(); // Call 'setup' on all subviews // first (bottom up recursion). if (!shallow) { - for (var i = 0, l = children.length; i < l; i++) { - children[i].setup(); - } + this.each(function(child) { + child.setup(); + }); } // If this is already setup, call @@ -558,14 +556,13 @@ teardown: function(options) { var shallow = options && options.shallow; - var children = this.children(); // Call 'setup' on all subviews // first (bottom up recursion). if (!shallow) { - for (var i = 0, l = children.length; i < l; i++) { - children[i].teardown(); - } + this.each(function(child) { + child.teardown(); + }); } // Clear the el cache @@ -575,8 +572,6 @@ this.onTeardown(); this.isSetup = false; - - // For chaining return this; }, @@ -691,10 +686,10 @@ }, purgeElementCaches: function() { - var children = this.children(); - var l = children.length, i; + this.each(function(child) { + child.purgeElementCaches(); + }); - for (i = 0; i < l; i++) children[i].purgeElementCaches(); this.clearElement(); }, @@ -779,13 +774,12 @@ toJSON: function() { var json = {}; - var children = this.children(); json.children = []; // Recurse - for (var i = 0, l = children.length; i < l; i++) { - json.children.push(children[i].toJSON()); - } + this.each(function(child) { + json.children.push(child.toJSON()); + }); json.id = this.id(); json.fmid = this._fmid;
16
Replace all for loops with View#each()
22
.js
js
mit
ftlabs/fruitmachine
10067074
<NME> tests.js <BEF> /** * loadjs tests * @module test/tests.js */ var pathsLoaded = null, // file register assert = chai.assert, expect = chai.expect; describe('LoadJS tests', function() { beforeEach(function() { // reset register pathsLoaded = {}; }); it('should call success callback on valid path', function(done) { loadjs(['assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); done(); } }); }); it('should call fail callback on invalid path', function(done) { loadjs(['assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, fail: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should call success callback on two valid paths', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should call fail callback on one invalid path', function(done) { loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, fail: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should throw an error if bundle is already defined', function() { // define bundle loadjs(['assets/file1.js'], 'bundle3'); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'bundle3'); }; expect(fn).to.throw(Error, "LoadJS: Bundle already defined"); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should chain loadjs object', function(done) { function bothDone() { if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } // define bundles loadjs('assets/file1.js', 'bundle5'); loadjs('assets/file2.js', 'bundle6'); loadjs .ready('bundle5', { success: function() { assert.equal(pathsLoaded['file1.js'], true); bothDone(); }}) .ready('bundle6', { success: function() { assert.equal(pathsLoaded['file2.js'], true); bothDone(); } }); }); it('should handle multiple dependencies', function(done) { loadjs('assets/file1.js', 'bundle7'); loadjs('assets/file2.js', 'bundle8'); loadjs.ready(['bundle7', 'bundle8'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should fail on missing depdendencies', function(done) { loadjs('assets/file1.js', 'bundle9'); loadjs('assets/file-doesntexist.js', 'bundle10'); loadjs.ready(['bundle9', 'bundle10'], { success: function() { throw "Executed success callback"; }, fail: function(depsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(depsNotFound.length, 1); assert.equal(depsNotFound[0], 'bundle10'); done(); } }); }); it('should execute callbacks on .done()', function(done) { // add handler loadjs.ready('plugin1', { success: function() { done(); } }); // execute done loadjs.done('plugin1'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin2'); // add handler loadjs.ready('plugin2', { success: function() { done(); } }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); // use 1 second delay to let files load setTimeout(function() { loadjs.ready('bundle1', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }, 1000); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle2', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); // use 1 second delay setTimeout(function() { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); }, 1000); }); it('should support async false', function(done) { var numCompleted = 0, numTests = 20, paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; // run tests sequentially var testFn = function(paths) { loadjs(paths, { success: function() { var f1 = paths[0].replace('assets/', ''); var f2 = paths[1].replace('assets/', ''); // check load order assert.isTrue(pathsLoaded[f1]); assert.isFalse(pathsLoaded[f2]); // increment tests numCompleted += 1; if (numCompleted === numTests) { // exit done(); } else { // reset register pathsLoaded = {}; // run test again paths.reverse(); testFn(paths); } }, async: false }); } // run tests testFn(paths); }); // Un-'x' this for testing ad blocked scripts. // Ghostery: Disallow "Google Adservices" // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a // custom filter under Options // xit('it should report ad blocked scripts as missing', function(done) { var blockedScript = 'https://www.googletagservices.com/tag/js/gpt.js'; loadjs([blockedScript, 'assets/file1.js'], { success: function() { throw "Executed success callback"; }, fail: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], blockedScript); done(); } }); }); }); var imgs = document.getElementsByTagName('img'); Array.prototype.slice.call(imgs).forEach(function(img) { // verify image was loaded if (img.src === src) assert.equal(img.naturalWidth > 0, true); }); } function assertNotLoaded(src) { // loop through images var imgs = document.getElementsByTagName('img'); Array.prototype.slice.call(imgs).forEach(function(img) { // fail if image was loaded if (img.src === src) assert.equal(img.naturalWidth, 0); }); } it('should load one file', function(done) { loadjs(['assets/flash.png'], { success: function() { assertLoaded('assets/flash.png'); done(); } }); }); it('should load multiple files', function(done) { loadjs(['assets/flash.png', 'assets/flash.jpg'], { success: function() { assertLoaded('assets/flash.png'); assertLoaded('assets/flash.jpg'); done(); } }); }); it('detects png|gif|jpg|svg|webp extensions', function(done) { let files = [ 'assets/flash.png', 'assets/flash.gif', 'assets/flash.jpg', 'assets/flash.svg', 'assets/flash.webp' ]; loadjs(files, function() { files.forEach(file => {assertLoaded(file);}); done(); }); }); it('supports urls with query arguments', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('supports urls with anchor tags', function(done) { var src = 'assets/flash.png#' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('supports urls with query arguments and anchor tags', function(done) { var src = 'assets/flash.png'; src += '?' + Math.random(); src += '#' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('should support forced "img!" files', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error callback on one invalid path', function(done) { var src1 = 'assets/flash.png?' + Math.random(), src2 = 'assets/flash-doesntexist.png?' + Math.random(); loadjs(['img!' + src1, 'img!' + src2], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assertLoaded(src1); assertNotLoaded(src2); done(); } }); }); it('should support mix of img and js', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src, 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assertLoaded(src); done(); } }); }); it('should load external img files', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/mui-logo.png?'; src += Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error on missing external file', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/'; src += 'mui-logo-doesntexist.png?' + Math.random(); loadjs(['img!' + src], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assertNotLoaded(src); done(); } }); }); }); // ========================================================================== // API tests // ========================================================================== describe('API tests', function() { it('should throw an error if bundle is already defined', function() { // define bundle loadjs(['assets/file1.js'], 'bundle'); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'bundle'); }; expect(fn).to.throw("LoadJS"); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should chain loadjs object', function(done) { function bothDone() { if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } // define bundles loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs .ready('bundle1', { success: function() { assert.equal(pathsLoaded['file1.js'], true); bothDone(); }}) .ready('bundle2', { success: function() { assert.equal(pathsLoaded['file2.js'], true); bothDone(); } }); }); it('should handle multiple dependencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should error on missing depdendencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file-doesntexist.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { throw "Executed success callback"; }, error: function(depsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(depsNotFound.length, 1); assert.equal(depsNotFound[0], 'bundle2'); done(); } }); }); it('should execute callbacks on .done()', function(done) { // add handler loadjs.ready('plugin', { success: function() { done(); } }); // execute done loadjs.done('plugin'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin'); // add handler loadjs.ready('plugin', { success: function() { done(); } }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); // use 1 second delay to let files load setTimeout(function() { loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }, 1000); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); // use 1 second delay setTimeout(function() { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); }, 1000); }); it('should reset dependencies statuses', function() { loadjs(['assets/file1.js'], 'cleared'); loadjs.reset(); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'cleared'); }; expect(fn).not.to.throw("LoadJS"); }); it('should indicate if bundle has already been defined', function() { loadjs(['assets/file1/js'], 'bundle1'); assert.equal(loadjs.isDefined('bundle1'), true); assert.equal(loadjs.isDefined('bundleXX'), false); }); it('should accept success callback functions to loadjs()', function(done) { loadjs('assets/file1.js', function() { done(); }); }); it('should accept success callback functions to .ready()', function(done) { loadjs.done('plugin'); loadjs.ready('plugin', function() { done(); }); }); it('should return Promise object if returnPromise is true', function() { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); // verify that response object is a Promise assert.equal(prom instanceof Promise, true); }); it('Promise object should support resolutions', function(done) { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); prom.then(function() { assert.equal(pathsLoaded['file1.js'], true); done(); }); }); it('Promise object should support rejections', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom.then( function(){}, function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } ); }); it('Promise object should support catches', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom .catch(function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); }); }); it('supports Promises and success callbacks', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; var prom = loadjs('assets/file1.js', { success: completedFn, returnPromise: true }); prom.then(completedFn); }); it('supports Promises and bundle ready events', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; loadjs('assets/file1.js', 'bundle1', {returnPromise: true}) .then(completedFn); loadjs.ready('bundle1', completedFn); }); }); }); <MSG> Support for loading CSS files <DFF> @@ -4,6 +4,7 @@ */ var pathsLoaded = null, // file register + testEl = null, assert = chai.assert, expect = chai.expect; @@ -17,254 +18,370 @@ describe('LoadJS tests', function() { }); - it('should call success callback on valid path', function(done) { - loadjs(['assets/file1.js'], { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - done(); - } + + // ========================================================================== + // JavaScript file loading tests + // ========================================================================== + + describe('JavaScript file loading tests', function() { + + it('should call success callback on valid path', function(done) { + loadjs(['assets/file1.js'], { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + done(); + } + }); + }); + + + it('should call fail callback on invalid path', function(done) { + loadjs(['assets/file-doesntexist.js'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(pathsNotFound.length, 1); + assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); + done(); + } + }); + }); + + + it('should call success callback on two valid paths', function(done) { + loadjs(['assets/file1.js', 'assets/file2.js'], { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + } + }); }); - }); + + it('should call fail callback on one invalid path', function(done) { + loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsNotFound.length, 1); + assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); + done(); + } + }); + }); - it('should call fail callback on invalid path', function(done) { - loadjs(['assets/file-doesntexist.js'], { - success: function() { - throw "Executed success callback"; - }, - fail: function(pathsNotFound) { - assert.equal(pathsNotFound.length, 1); - assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); - done(); + + it('should support async false', function(done) { + var numCompleted = 0, + numTests = 20, + paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; + + // run tests sequentially + var testFn = function(paths) { + loadjs(paths, { + success: function() { + var f1 = paths[0].replace('assets/', ''); + var f2 = paths[1].replace('assets/', ''); + + // check load order + assert.isTrue(pathsLoaded[f1]); + assert.isFalse(pathsLoaded[f2]); + + // increment tests + numCompleted += 1; + + if (numCompleted === numTests) { + // exit + done(); + } else { + // reset register + pathsLoaded = {}; + + // run test again + paths.reverse(); + testFn(paths); + } + }, + async: false + }); } + + // run tests + testFn(paths); }); - }); - it('should call success callback on two valid paths', function(done) { - loadjs(['assets/file1.js', 'assets/file2.js'], { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); - } + // Un-'x' this for testing ad blocked scripts. + // Ghostery: Disallow "Google Adservices" + // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a + // custom filter under Options + // + xit('it should report ad blocked scripts as missing', function(done) { + var blockedScript = 'https://www.googletagservices.com/tag/js/gpt.js'; + + loadjs([blockedScript, 'assets/file1.js'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsNotFound.length, 1); + assert.equal(pathsNotFound[0], blockedScript); + done(); + } + }); }); }); - it('should call fail callback on one invalid path', function(done) { - loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { - success: function() { - throw "Executed success callback"; - }, - fail: function(pathsNotFound) { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsNotFound.length, 1); - assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); - done(); - } + + // ========================================================================== + // CSS file loading tests + // ========================================================================== + + describe('CSS file loading tests', function() { + + before(function() { + // add test div to body for css tests + testEl = document.createElement('div'); + testEl.className = 'test-div'; + testEl.style.display = 'inline-block'; + document.body.appendChild(testEl); }); - }); - it('should throw an error if bundle is already defined', function() { - // define bundle - loadjs(['assets/file1.js'], 'bundle3'); + afterEach(function() { + var els = document.getElementsByTagName('link'), + i = els.length, + el; - // define bundle again - var fn = function() { - loadjs(['assets/file1.js'], 'bundle3'); - }; + // iteratete through stylesheets + while (i--) { + el = els[i]; - expect(fn).to.throw(Error, "LoadJS: Bundle already defined"); - }); - - - it('should create a bundle id and a callback inline', function(done) { - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); + // remove test stylesheets + if (el.href.indexOf('assets/file') != -1) { + el.parentNode.removeChild(el); + } } }); - }); - it('should chain loadjs object', function(done) { - function bothDone() { - if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); - } + it('should load one file', function(done) { + loadjs(['assets/file1.css'], { + success: function() { + assert.equal(testEl.offsetWidth, 100); + done(); + } + }); + }); - // define bundles - loadjs('assets/file1.js', 'bundle5'); - loadjs('assets/file2.js', 'bundle6'); - - loadjs - .ready('bundle5', { + + it('should load multiple files', function(done) { + loadjs(['assets/file1.css', 'assets/file2.css'], { success: function() { - assert.equal(pathsLoaded['file1.js'], true); - bothDone(); - }}) - .ready('bundle6', { + assert.equal(testEl.offsetWidth, 200); + done(); + } + }); + }); + + + it('should call fail callback on one invalid path', function(done) { + loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], { success: function() { - assert.equal(pathsLoaded['file2.js'], true); - bothDone(); + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(testEl.offsetWidth, 100); + assert.equal(pathsNotFound.length, 1); + assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css'); + done(); } }); - }); - + }); - it('should handle multiple dependencies', function(done) { - loadjs('assets/file1.js', 'bundle7'); - loadjs('assets/file2.js', 'bundle8'); - loadjs.ready(['bundle7', 'bundle8'], { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); - } + it('should support mix of css and js', function(done) { + loadjs(['assets/file1.css', 'assets/file1.js'], { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(testEl.offsetWidth, 100); + done(); + } + }); }); - }); - - it('should fail on missing depdendencies', function(done) { - loadjs('assets/file1.js', 'bundle9'); - loadjs('assets/file-doesntexist.js', 'bundle10'); - loadjs.ready(['bundle9', 'bundle10'], { - success: function() { - throw "Executed success callback"; - }, - fail: function(depsNotFound) { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(depsNotFound.length, 1); - assert.equal(depsNotFound[0], 'bundle10'); - done(); - } + it('should call fail callback on empty css', function(done) { + loadjs(['assets/emptycss'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(pathsNotFound.length, 1); + done(); + } + }); }); - }); - it('should execute callbacks on .done()', function(done) { - // add handler - loadjs.ready('plugin1', { - success: function() { - done(); - } + // teardown + return after(function() { + // remove test div + testEl.parentNode.removeChild(testEl); }); - - // execute done - loadjs.done('plugin1'); }); - it('should execute callbacks created after .done()', function(done) { - // execute done - loadjs.done('plugin2'); - - // add handler - loadjs.ready('plugin2', { - success: function() { - done(); - } - }); - }); + // ========================================================================== + // API tests + // ========================================================================== - it('should define bundles', function(done) { - // define bundle - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); + describe('API tests', function() { - // use 1 second delay to let files load - setTimeout(function() { - loadjs.ready('bundle1', { + it('should throw an error if bundle is already defined', function() { + // define bundle + loadjs(['assets/file1.js'], 'bundle3'); + + // define bundle again + var fn = function() { + loadjs(['assets/file1.js'], 'bundle3'); + }; + + expect(fn).to.throw(Error, "LoadJS"); + }); + + + it('should create a bundle id and a callback inline', function(done) { + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); - }, 1000); - }); + }); - it('should allow bundle callbacks before definitions', function(done) { - // define callback - loadjs.ready('bundle2', { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); + it('should chain loadjs object', function(done) { + function bothDone() { + if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } + + // define bundles + loadjs('assets/file1.js', 'bundle5'); + loadjs('assets/file2.js', 'bundle6'); + + loadjs + .ready('bundle5', { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + bothDone(); + }}) + .ready('bundle6', { + success: function() { + assert.equal(pathsLoaded['file2.js'], true); + bothDone(); + } + }); }); - - // use 1 second delay - setTimeout(function() { - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); - }, 1000); - }); - - - it('should support async false', function(done) { - var numCompleted = 0, - numTests = 20, - paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; - - // run tests sequentially - var testFn = function(paths) { - loadjs(paths, { + + + it('should handle multiple dependencies', function(done) { + loadjs('assets/file1.js', 'bundle7'); + loadjs('assets/file2.js', 'bundle8'); + + loadjs.ready(['bundle7', 'bundle8'], { success: function() { - var f1 = paths[0].replace('assets/', ''); - var f2 = paths[1].replace('assets/', ''); - - // check load order - assert.isTrue(pathsLoaded[f1]); - assert.isFalse(pathsLoaded[f2]); - - // increment tests - numCompleted += 1; - - if (numCompleted === numTests) { - // exit + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + } + }); + }); + + + it('should fail on missing depdendencies', function(done) { + loadjs('assets/file1.js', 'bundle9'); + loadjs('assets/file-doesntexist.js', 'bundle10'); + + loadjs.ready(['bundle9', 'bundle10'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(depsNotFound) { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(depsNotFound.length, 1); + assert.equal(depsNotFound[0], 'bundle10'); + done(); + } + }); + }); + + + it('should execute callbacks on .done()', function(done) { + // add handler + loadjs.ready('plugin1', { + success: function() { + done(); + } + }); + + // execute done + loadjs.done('plugin1'); + }); + + + it('should execute callbacks created after .done()', function(done) { + // execute done + loadjs.done('plugin2'); + + // add handler + loadjs.ready('plugin2', { + success: function() { + done(); + } + }); + }); + + + it('should define bundles', function(done) { + // define bundle + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); + + // use 1 second delay to let files load + setTimeout(function() { + loadjs.ready('bundle1', { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); done(); - } else { - // reset register - pathsLoaded = {}; - - // run test again - paths.reverse(); - testFn(paths); } - }, - async: false + }); + }, 1000); + }); + + + it('should allow bundle callbacks before definitions', function(done) { + // define callback + loadjs.ready('bundle2', { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + } }); - } - - // run tests - testFn(paths); - }); - - - // Un-'x' this for testing ad blocked scripts. - // Ghostery: Disallow "Google Adservices" - // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a - // custom filter under Options - // - xit('it should report ad blocked scripts as missing', function(done) { - var blockedScript = 'https://www.googletagservices.com/tag/js/gpt.js'; - - loadjs([blockedScript, 'assets/file1.js'], { - success: function() { - throw "Executed success callback"; - }, - fail: function(pathsNotFound) { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsNotFound.length, 1); - assert.equal(pathsNotFound[0], blockedScript); - done(); - } + + // use 1 second delay + setTimeout(function() { + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); + }, 1000); }); }); });
311
Support for loading CSS files
194
.js
js
mit
muicss/loadjs
10067075
<NME> tests.js <BEF> /** * loadjs tests * @module test/tests.js */ var pathsLoaded = null, // file register assert = chai.assert, expect = chai.expect; describe('LoadJS tests', function() { beforeEach(function() { // reset register pathsLoaded = {}; }); it('should call success callback on valid path', function(done) { loadjs(['assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); done(); } }); }); it('should call fail callback on invalid path', function(done) { loadjs(['assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, fail: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should call success callback on two valid paths', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should call fail callback on one invalid path', function(done) { loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, fail: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should throw an error if bundle is already defined', function() { // define bundle loadjs(['assets/file1.js'], 'bundle3'); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'bundle3'); }; expect(fn).to.throw(Error, "LoadJS: Bundle already defined"); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should chain loadjs object', function(done) { function bothDone() { if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } // define bundles loadjs('assets/file1.js', 'bundle5'); loadjs('assets/file2.js', 'bundle6'); loadjs .ready('bundle5', { success: function() { assert.equal(pathsLoaded['file1.js'], true); bothDone(); }}) .ready('bundle6', { success: function() { assert.equal(pathsLoaded['file2.js'], true); bothDone(); } }); }); it('should handle multiple dependencies', function(done) { loadjs('assets/file1.js', 'bundle7'); loadjs('assets/file2.js', 'bundle8'); loadjs.ready(['bundle7', 'bundle8'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should fail on missing depdendencies', function(done) { loadjs('assets/file1.js', 'bundle9'); loadjs('assets/file-doesntexist.js', 'bundle10'); loadjs.ready(['bundle9', 'bundle10'], { success: function() { throw "Executed success callback"; }, fail: function(depsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(depsNotFound.length, 1); assert.equal(depsNotFound[0], 'bundle10'); done(); } }); }); it('should execute callbacks on .done()', function(done) { // add handler loadjs.ready('plugin1', { success: function() { done(); } }); // execute done loadjs.done('plugin1'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin2'); // add handler loadjs.ready('plugin2', { success: function() { done(); } }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); // use 1 second delay to let files load setTimeout(function() { loadjs.ready('bundle1', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }, 1000); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle2', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); // use 1 second delay setTimeout(function() { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); }, 1000); }); it('should support async false', function(done) { var numCompleted = 0, numTests = 20, paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; // run tests sequentially var testFn = function(paths) { loadjs(paths, { success: function() { var f1 = paths[0].replace('assets/', ''); var f2 = paths[1].replace('assets/', ''); // check load order assert.isTrue(pathsLoaded[f1]); assert.isFalse(pathsLoaded[f2]); // increment tests numCompleted += 1; if (numCompleted === numTests) { // exit done(); } else { // reset register pathsLoaded = {}; // run test again paths.reverse(); testFn(paths); } }, async: false }); } // run tests testFn(paths); }); // Un-'x' this for testing ad blocked scripts. // Ghostery: Disallow "Google Adservices" // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a // custom filter under Options // xit('it should report ad blocked scripts as missing', function(done) { var blockedScript = 'https://www.googletagservices.com/tag/js/gpt.js'; loadjs([blockedScript, 'assets/file1.js'], { success: function() { throw "Executed success callback"; }, fail: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], blockedScript); done(); } }); }); }); var imgs = document.getElementsByTagName('img'); Array.prototype.slice.call(imgs).forEach(function(img) { // verify image was loaded if (img.src === src) assert.equal(img.naturalWidth > 0, true); }); } function assertNotLoaded(src) { // loop through images var imgs = document.getElementsByTagName('img'); Array.prototype.slice.call(imgs).forEach(function(img) { // fail if image was loaded if (img.src === src) assert.equal(img.naturalWidth, 0); }); } it('should load one file', function(done) { loadjs(['assets/flash.png'], { success: function() { assertLoaded('assets/flash.png'); done(); } }); }); it('should load multiple files', function(done) { loadjs(['assets/flash.png', 'assets/flash.jpg'], { success: function() { assertLoaded('assets/flash.png'); assertLoaded('assets/flash.jpg'); done(); } }); }); it('detects png|gif|jpg|svg|webp extensions', function(done) { let files = [ 'assets/flash.png', 'assets/flash.gif', 'assets/flash.jpg', 'assets/flash.svg', 'assets/flash.webp' ]; loadjs(files, function() { files.forEach(file => {assertLoaded(file);}); done(); }); }); it('supports urls with query arguments', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('supports urls with anchor tags', function(done) { var src = 'assets/flash.png#' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('supports urls with query arguments and anchor tags', function(done) { var src = 'assets/flash.png'; src += '?' + Math.random(); src += '#' + Math.random(); loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('should support forced "img!" files', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error callback on one invalid path', function(done) { var src1 = 'assets/flash.png?' + Math.random(), src2 = 'assets/flash-doesntexist.png?' + Math.random(); loadjs(['img!' + src1, 'img!' + src2], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assertLoaded(src1); assertNotLoaded(src2); done(); } }); }); it('should support mix of img and js', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src, 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assertLoaded(src); done(); } }); }); it('should load external img files', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/mui-logo.png?'; src += Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error on missing external file', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/'; src += 'mui-logo-doesntexist.png?' + Math.random(); loadjs(['img!' + src], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assertNotLoaded(src); done(); } }); }); }); // ========================================================================== // API tests // ========================================================================== describe('API tests', function() { it('should throw an error if bundle is already defined', function() { // define bundle loadjs(['assets/file1.js'], 'bundle'); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'bundle'); }; expect(fn).to.throw("LoadJS"); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should chain loadjs object', function(done) { function bothDone() { if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } // define bundles loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs .ready('bundle1', { success: function() { assert.equal(pathsLoaded['file1.js'], true); bothDone(); }}) .ready('bundle2', { success: function() { assert.equal(pathsLoaded['file2.js'], true); bothDone(); } }); }); it('should handle multiple dependencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should error on missing depdendencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file-doesntexist.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { throw "Executed success callback"; }, error: function(depsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(depsNotFound.length, 1); assert.equal(depsNotFound[0], 'bundle2'); done(); } }); }); it('should execute callbacks on .done()', function(done) { // add handler loadjs.ready('plugin', { success: function() { done(); } }); // execute done loadjs.done('plugin'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin'); // add handler loadjs.ready('plugin', { success: function() { done(); } }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); // use 1 second delay to let files load setTimeout(function() { loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }, 1000); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); // use 1 second delay setTimeout(function() { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); }, 1000); }); it('should reset dependencies statuses', function() { loadjs(['assets/file1.js'], 'cleared'); loadjs.reset(); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'cleared'); }; expect(fn).not.to.throw("LoadJS"); }); it('should indicate if bundle has already been defined', function() { loadjs(['assets/file1/js'], 'bundle1'); assert.equal(loadjs.isDefined('bundle1'), true); assert.equal(loadjs.isDefined('bundleXX'), false); }); it('should accept success callback functions to loadjs()', function(done) { loadjs('assets/file1.js', function() { done(); }); }); it('should accept success callback functions to .ready()', function(done) { loadjs.done('plugin'); loadjs.ready('plugin', function() { done(); }); }); it('should return Promise object if returnPromise is true', function() { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); // verify that response object is a Promise assert.equal(prom instanceof Promise, true); }); it('Promise object should support resolutions', function(done) { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); prom.then(function() { assert.equal(pathsLoaded['file1.js'], true); done(); }); }); it('Promise object should support rejections', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom.then( function(){}, function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } ); }); it('Promise object should support catches', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom .catch(function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); }); }); it('supports Promises and success callbacks', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; var prom = loadjs('assets/file1.js', { success: completedFn, returnPromise: true }); prom.then(completedFn); }); it('supports Promises and bundle ready events', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; loadjs('assets/file1.js', 'bundle1', {returnPromise: true}) .then(completedFn); loadjs.ready('bundle1', completedFn); }); }); }); <MSG> Support for loading CSS files <DFF> @@ -4,6 +4,7 @@ */ var pathsLoaded = null, // file register + testEl = null, assert = chai.assert, expect = chai.expect; @@ -17,254 +18,370 @@ describe('LoadJS tests', function() { }); - it('should call success callback on valid path', function(done) { - loadjs(['assets/file1.js'], { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - done(); - } + + // ========================================================================== + // JavaScript file loading tests + // ========================================================================== + + describe('JavaScript file loading tests', function() { + + it('should call success callback on valid path', function(done) { + loadjs(['assets/file1.js'], { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + done(); + } + }); + }); + + + it('should call fail callback on invalid path', function(done) { + loadjs(['assets/file-doesntexist.js'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(pathsNotFound.length, 1); + assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); + done(); + } + }); + }); + + + it('should call success callback on two valid paths', function(done) { + loadjs(['assets/file1.js', 'assets/file2.js'], { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + } + }); }); - }); + + it('should call fail callback on one invalid path', function(done) { + loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsNotFound.length, 1); + assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); + done(); + } + }); + }); - it('should call fail callback on invalid path', function(done) { - loadjs(['assets/file-doesntexist.js'], { - success: function() { - throw "Executed success callback"; - }, - fail: function(pathsNotFound) { - assert.equal(pathsNotFound.length, 1); - assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); - done(); + + it('should support async false', function(done) { + var numCompleted = 0, + numTests = 20, + paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; + + // run tests sequentially + var testFn = function(paths) { + loadjs(paths, { + success: function() { + var f1 = paths[0].replace('assets/', ''); + var f2 = paths[1].replace('assets/', ''); + + // check load order + assert.isTrue(pathsLoaded[f1]); + assert.isFalse(pathsLoaded[f2]); + + // increment tests + numCompleted += 1; + + if (numCompleted === numTests) { + // exit + done(); + } else { + // reset register + pathsLoaded = {}; + + // run test again + paths.reverse(); + testFn(paths); + } + }, + async: false + }); } + + // run tests + testFn(paths); }); - }); - it('should call success callback on two valid paths', function(done) { - loadjs(['assets/file1.js', 'assets/file2.js'], { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); - } + // Un-'x' this for testing ad blocked scripts. + // Ghostery: Disallow "Google Adservices" + // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a + // custom filter under Options + // + xit('it should report ad blocked scripts as missing', function(done) { + var blockedScript = 'https://www.googletagservices.com/tag/js/gpt.js'; + + loadjs([blockedScript, 'assets/file1.js'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsNotFound.length, 1); + assert.equal(pathsNotFound[0], blockedScript); + done(); + } + }); }); }); - it('should call fail callback on one invalid path', function(done) { - loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { - success: function() { - throw "Executed success callback"; - }, - fail: function(pathsNotFound) { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsNotFound.length, 1); - assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); - done(); - } + + // ========================================================================== + // CSS file loading tests + // ========================================================================== + + describe('CSS file loading tests', function() { + + before(function() { + // add test div to body for css tests + testEl = document.createElement('div'); + testEl.className = 'test-div'; + testEl.style.display = 'inline-block'; + document.body.appendChild(testEl); }); - }); - it('should throw an error if bundle is already defined', function() { - // define bundle - loadjs(['assets/file1.js'], 'bundle3'); + afterEach(function() { + var els = document.getElementsByTagName('link'), + i = els.length, + el; - // define bundle again - var fn = function() { - loadjs(['assets/file1.js'], 'bundle3'); - }; + // iteratete through stylesheets + while (i--) { + el = els[i]; - expect(fn).to.throw(Error, "LoadJS: Bundle already defined"); - }); - - - it('should create a bundle id and a callback inline', function(done) { - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); + // remove test stylesheets + if (el.href.indexOf('assets/file') != -1) { + el.parentNode.removeChild(el); + } } }); - }); - it('should chain loadjs object', function(done) { - function bothDone() { - if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); - } + it('should load one file', function(done) { + loadjs(['assets/file1.css'], { + success: function() { + assert.equal(testEl.offsetWidth, 100); + done(); + } + }); + }); - // define bundles - loadjs('assets/file1.js', 'bundle5'); - loadjs('assets/file2.js', 'bundle6'); - - loadjs - .ready('bundle5', { + + it('should load multiple files', function(done) { + loadjs(['assets/file1.css', 'assets/file2.css'], { success: function() { - assert.equal(pathsLoaded['file1.js'], true); - bothDone(); - }}) - .ready('bundle6', { + assert.equal(testEl.offsetWidth, 200); + done(); + } + }); + }); + + + it('should call fail callback on one invalid path', function(done) { + loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], { success: function() { - assert.equal(pathsLoaded['file2.js'], true); - bothDone(); + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(testEl.offsetWidth, 100); + assert.equal(pathsNotFound.length, 1); + assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css'); + done(); } }); - }); - + }); - it('should handle multiple dependencies', function(done) { - loadjs('assets/file1.js', 'bundle7'); - loadjs('assets/file2.js', 'bundle8'); - loadjs.ready(['bundle7', 'bundle8'], { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); - } + it('should support mix of css and js', function(done) { + loadjs(['assets/file1.css', 'assets/file1.js'], { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(testEl.offsetWidth, 100); + done(); + } + }); }); - }); - - it('should fail on missing depdendencies', function(done) { - loadjs('assets/file1.js', 'bundle9'); - loadjs('assets/file-doesntexist.js', 'bundle10'); - loadjs.ready(['bundle9', 'bundle10'], { - success: function() { - throw "Executed success callback"; - }, - fail: function(depsNotFound) { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(depsNotFound.length, 1); - assert.equal(depsNotFound[0], 'bundle10'); - done(); - } + it('should call fail callback on empty css', function(done) { + loadjs(['assets/emptycss'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(pathsNotFound) { + assert.equal(pathsNotFound.length, 1); + done(); + } + }); }); - }); - it('should execute callbacks on .done()', function(done) { - // add handler - loadjs.ready('plugin1', { - success: function() { - done(); - } + // teardown + return after(function() { + // remove test div + testEl.parentNode.removeChild(testEl); }); - - // execute done - loadjs.done('plugin1'); }); - it('should execute callbacks created after .done()', function(done) { - // execute done - loadjs.done('plugin2'); - - // add handler - loadjs.ready('plugin2', { - success: function() { - done(); - } - }); - }); + // ========================================================================== + // API tests + // ========================================================================== - it('should define bundles', function(done) { - // define bundle - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); + describe('API tests', function() { - // use 1 second delay to let files load - setTimeout(function() { - loadjs.ready('bundle1', { + it('should throw an error if bundle is already defined', function() { + // define bundle + loadjs(['assets/file1.js'], 'bundle3'); + + // define bundle again + var fn = function() { + loadjs(['assets/file1.js'], 'bundle3'); + }; + + expect(fn).to.throw(Error, "LoadJS"); + }); + + + it('should create a bundle id and a callback inline', function(done) { + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle4', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); - }, 1000); - }); + }); - it('should allow bundle callbacks before definitions', function(done) { - // define callback - loadjs.ready('bundle2', { - success: function() { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsLoaded['file2.js'], true); - done(); + it('should chain loadjs object', function(done) { + function bothDone() { + if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } + + // define bundles + loadjs('assets/file1.js', 'bundle5'); + loadjs('assets/file2.js', 'bundle6'); + + loadjs + .ready('bundle5', { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + bothDone(); + }}) + .ready('bundle6', { + success: function() { + assert.equal(pathsLoaded['file2.js'], true); + bothDone(); + } + }); }); - - // use 1 second delay - setTimeout(function() { - loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); - }, 1000); - }); - - - it('should support async false', function(done) { - var numCompleted = 0, - numTests = 20, - paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; - - // run tests sequentially - var testFn = function(paths) { - loadjs(paths, { + + + it('should handle multiple dependencies', function(done) { + loadjs('assets/file1.js', 'bundle7'); + loadjs('assets/file2.js', 'bundle8'); + + loadjs.ready(['bundle7', 'bundle8'], { success: function() { - var f1 = paths[0].replace('assets/', ''); - var f2 = paths[1].replace('assets/', ''); - - // check load order - assert.isTrue(pathsLoaded[f1]); - assert.isFalse(pathsLoaded[f2]); - - // increment tests - numCompleted += 1; - - if (numCompleted === numTests) { - // exit + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + } + }); + }); + + + it('should fail on missing depdendencies', function(done) { + loadjs('assets/file1.js', 'bundle9'); + loadjs('assets/file-doesntexist.js', 'bundle10'); + + loadjs.ready(['bundle9', 'bundle10'], { + success: function() { + throw "Executed success callback"; + }, + fail: function(depsNotFound) { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(depsNotFound.length, 1); + assert.equal(depsNotFound[0], 'bundle10'); + done(); + } + }); + }); + + + it('should execute callbacks on .done()', function(done) { + // add handler + loadjs.ready('plugin1', { + success: function() { + done(); + } + }); + + // execute done + loadjs.done('plugin1'); + }); + + + it('should execute callbacks created after .done()', function(done) { + // execute done + loadjs.done('plugin2'); + + // add handler + loadjs.ready('plugin2', { + success: function() { + done(); + } + }); + }); + + + it('should define bundles', function(done) { + // define bundle + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle1'); + + // use 1 second delay to let files load + setTimeout(function() { + loadjs.ready('bundle1', { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); done(); - } else { - // reset register - pathsLoaded = {}; - - // run test again - paths.reverse(); - testFn(paths); } - }, - async: false + }); + }, 1000); + }); + + + it('should allow bundle callbacks before definitions', function(done) { + // define callback + loadjs.ready('bundle2', { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assert.equal(pathsLoaded['file2.js'], true); + done(); + } }); - } - - // run tests - testFn(paths); - }); - - - // Un-'x' this for testing ad blocked scripts. - // Ghostery: Disallow "Google Adservices" - // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a - // custom filter under Options - // - xit('it should report ad blocked scripts as missing', function(done) { - var blockedScript = 'https://www.googletagservices.com/tag/js/gpt.js'; - - loadjs([blockedScript, 'assets/file1.js'], { - success: function() { - throw "Executed success callback"; - }, - fail: function(pathsNotFound) { - assert.equal(pathsLoaded['file1.js'], true); - assert.equal(pathsNotFound.length, 1); - assert.equal(pathsNotFound[0], blockedScript); - done(); - } + + // use 1 second delay + setTimeout(function() { + loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle2'); + }, 1000); }); }); });
311
Support for loading CSS files
194
.js
js
mit
muicss/loadjs
10067076
<NME> README.md <BEF> # LoadJS <img src="https://www.muicss.com/static/images/loadjs.svg" width="250px"> LoadJS is a tiny async loader for modern browsers (899 bytes). [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs?type=dev) [![CDNJS](https://img.shields.io/cdnjs/v/loadjs.svg)](https://cdnjs.com/libraries/loadjs) LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript and CSS files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code in your &lt;html&gt; and then use the `loadjs` global to manage JavaScript dependencies after pageload. LoadJS is based on the excellent <a href="https://github.com/ded/script.js">$script</a> library by <a href="https://github.com/ded">Dustin Diaz</a>. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 710 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle and execute code when it loads loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.js) * [loadjs.min.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) You can also use it as a CJS or AMD module: // define a dependency bundle with advanced options loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: function(path, scriptEl) { /* execute code before fetch */ }, async: true, // load files synchronously or asynchronously (default: true) numRetries: 3 // see caveats about using numRetries with async:false (default: 0), returnPromise: false // return Promise object (default: false) }); loadjs.ready('foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(depsNotFound) { /* foobar bundle load failed */ }, }); </script> ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js) (for development) * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js) (for production) It's also available from these public CDNs: * UNPKG * [https://unpkg.com/[email protected]/dist/loadjs.js](https://unpkg.com/[email protected]/dist/loadjs.js) (for development) * [https://unpkg.com/[email protected]/dist/loadjs.min.js](https://unpkg.com/[email protected]/dist/loadjs.min.js) (for production) * CDNJS * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js) (for development) * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js) (for production) You can also use it as a CJS or AMD module: ```bash $ npm install --save loadjs ``` ```javascript var loadjs = require('loadjs'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` ## Browser Support * IE9+ (`async: false` support only works in IE10+) * Opera 12+ * Safari 5+ * Chrome * Firefox * iOS 6+ * Android 4.4+ LoadJS also detects script load failures from AdBlock Plus and Ghostery in: * Safari * Chrome Note: LoadJS treats empty CSS files as load failures in IE9-11 and uses `rel="preload"` to load CSS files in Edge (to get around lack of support for onerror events on `<link rel="stylesheet">` tags) ## Documentation 1. Load a single file ```javascript loadjs('/path/to/foo.js', function() { /* foo.js loaded */ }); ``` 1. Fetch files in parallel and load them asynchronously ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() { /* foo.js and bar.js loaded */ }); ``` 1. Fetch JavaScript, CSS and image files ```javascript loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() { /* foo.css, bar.png and thunk.js loaded */ }); ``` 1. Force treat file as CSS stylesheet ```javascript loadjs(['css!/path/to/cssfile.custom'], function() { /* cssfile.custom loaded as stylesheet */ }); ``` 1. Force treat file as image ```javascript loadjs(['img!/path/to/image.custom'], function() { /* image.custom loaded */ }); ``` 1. Add a bundle id ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Use .ready() to define bundles and callbacks separately ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Use multiple bundles in .ready() dependency lists ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs(['/path/to/bar1.js', '/path/to/bar2.js'], 'bar'); loadjs.ready(['foo', 'bar'], function() { /* foo.js & bar1.js & bar2.js loaded */ }); ``` 1. Chain .ready() together ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs .ready('foo', function() { /* foo.js loaded */ }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Use Promises to register callbacks ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true}) .then(function() { /* foo.js & bar.js loaded */ }) .catch(function(pathsNotFound) { /* at least one didn't load */ }); ``` 1. Check if bundle has already been defined ```javascript if (!loadjs.isDefined('foobar')) { loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() { /* foo.js and bar.js loaded in series */ }, async: false }); ``` 1. Add an error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ } }); ``` 1. Retry files before calling the error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ }, numRetries: 3 }); // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries ``` 1. Install dependencies * nodejs (http://nodejs.org/) * npm (https://www.npmjs.org/) * http-server (via npm) 1. Clone repository /* called for each script node before being embedded */ if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; } }); ``` 1. Bypass LoadJS default DOM insertion mechanism (DOM `<head>`) ```javascript loadjs(['/path/to/foo.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { document.body.appendChild(scriptEl); /* return `false` to bypass default DOM insertion mechanism */ return false; } }); ``` 1. Use bundle ids in error callback $ npm run http-server -- -p 3000 ``` Then visit http://localhost:3000/examples 1. Build distribution files loadjs.ready(['foo', 'bar', 'thunk'], { success: function() { // foo.js & bar.js & thunkor.js & thunky.js loaded }, error: function(depsNotFound) { if (depsNotFound.indexOf('foo') > -1) {}; // foo failed if (depsNotFound.indexOf('bar') > -1) {}; // bar failed if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed } }); ``` $ npm run build-tests ``` Then visit http://localhost:3000/test 1. Build all files function fn1() { loadjs.done('dependency1'); } function fn2() { loadjs.done('dependency2'); } ``` 1. Reset dependency trackers ```javascript loadjs.reset(); ``` 1. Implement a require-like dependency manager ```javascript var bundles = { 'bundleA': ['/file1.js', '/file2.js'], 'bundleB': ['/file3.js', '/file4.js'] }; function require(bundleIds, callbackFn) { bundleIds.forEach(function(bundleId) { if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId); }); loadjs.ready(bundleIds, callbackFn); } require(['bundleA'], function() { /* bundleA loaded */ }); require(['bundleB'], function() { /* bundleB loaded */ }); require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ }); ``` ## Directory structure <pre> loadjs/ β”œβ”€β”€ dist β”‚Β Β  β”œβ”€β”€ loadjs.js β”‚Β Β  β”œβ”€β”€ loadjs.min.js β”‚Β Β  └── loadjs.umd.js β”œβ”€β”€ examples β”œβ”€β”€ gulpfile.js β”œβ”€β”€ LICENSE.txt β”œβ”€β”€ package.json β”œβ”€β”€ README.md β”œβ”€β”€ src β”‚Β Β  └── loadjs.js β”œβ”€β”€ test └── umd-templates </pre> ## Development Quickstart 1. Install dependencies * [nodejs](http://nodejs.org/) * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository ```bash $ git clone [email protected]:muicss/loadjs.git $ cd loadjs ``` 1. Install node dependencies using npm ```bash $ npm install ``` 1. Build examples ```bash $ npm run build-examples ``` To view the examples you can use any static file server. To use the `nodejs` http-server module: ```bash $ npm install http-server $ npm run http-server -- -p 3000 ``` Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files ```bash $ npm run build-dist ``` The files will be located in the `dist` directory. 1. Run tests To run the browser tests first build the `loadjs` library: ```bash $ npm run build-tests ``` Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files ```bash $ npm run build-all ``` <MSG> updated readme <DFF> @@ -11,7 +11,7 @@ LoadJS is a tiny async loader for modern browsers (710 bytes). LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript and CSS files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code in your &lt;html&gt; and then use the `loadjs` global to manage JavaScript dependencies after pageload. -LoadJS is based on the excellent <a href="https://github.com/ded/script.js">$script</a> library by <a href="https://github.com/ded">Dustin Diaz</a>. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 710 bytes (minified + gzipped). +LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 710 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: @@ -27,8 +27,8 @@ loadjs.ready('foobar', { ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: - * [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.js) - * [loadjs.min.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) + * [loadjs.js](dist/loadjs.js) + * [loadjs.min.js](dist/loadjs.min.js) You can also use it as a CJS or AMD module: @@ -229,8 +229,8 @@ loadjs/ 1. Install dependencies - * nodejs (http://nodejs.org/) - * npm (https://www.npmjs.org/) + * [nodejs](http://nodejs.org/) + * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository @@ -259,7 +259,7 @@ loadjs/ $ npm run http-server -- -p 3000 ``` - Then visit http://localhost:3000/examples + Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files @@ -277,7 +277,7 @@ loadjs/ $ npm run build-tests ``` - Then visit http://localhost:3000/test + Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files
7
updated readme
7
.md
md
mit
muicss/loadjs
10067077
<NME> README.md <BEF> # LoadJS <img src="https://www.muicss.com/static/images/loadjs.svg" width="250px"> LoadJS is a tiny async loader for modern browsers (899 bytes). [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs?type=dev) [![CDNJS](https://img.shields.io/cdnjs/v/loadjs.svg)](https://cdnjs.com/libraries/loadjs) LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript and CSS files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code in your &lt;html&gt; and then use the `loadjs` global to manage JavaScript dependencies after pageload. LoadJS is based on the excellent <a href="https://github.com/ded/script.js">$script</a> library by <a href="https://github.com/ded">Dustin Diaz</a>. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 710 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle and execute code when it loads loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.js) * [loadjs.min.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) You can also use it as a CJS or AMD module: // define a dependency bundle with advanced options loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: function(path, scriptEl) { /* execute code before fetch */ }, async: true, // load files synchronously or asynchronously (default: true) numRetries: 3 // see caveats about using numRetries with async:false (default: 0), returnPromise: false // return Promise object (default: false) }); loadjs.ready('foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(depsNotFound) { /* foobar bundle load failed */ }, }); </script> ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js) (for development) * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js) (for production) It's also available from these public CDNs: * UNPKG * [https://unpkg.com/[email protected]/dist/loadjs.js](https://unpkg.com/[email protected]/dist/loadjs.js) (for development) * [https://unpkg.com/[email protected]/dist/loadjs.min.js](https://unpkg.com/[email protected]/dist/loadjs.min.js) (for production) * CDNJS * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js) (for development) * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js) (for production) You can also use it as a CJS or AMD module: ```bash $ npm install --save loadjs ``` ```javascript var loadjs = require('loadjs'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` ## Browser Support * IE9+ (`async: false` support only works in IE10+) * Opera 12+ * Safari 5+ * Chrome * Firefox * iOS 6+ * Android 4.4+ LoadJS also detects script load failures from AdBlock Plus and Ghostery in: * Safari * Chrome Note: LoadJS treats empty CSS files as load failures in IE9-11 and uses `rel="preload"` to load CSS files in Edge (to get around lack of support for onerror events on `<link rel="stylesheet">` tags) ## Documentation 1. Load a single file ```javascript loadjs('/path/to/foo.js', function() { /* foo.js loaded */ }); ``` 1. Fetch files in parallel and load them asynchronously ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() { /* foo.js and bar.js loaded */ }); ``` 1. Fetch JavaScript, CSS and image files ```javascript loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() { /* foo.css, bar.png and thunk.js loaded */ }); ``` 1. Force treat file as CSS stylesheet ```javascript loadjs(['css!/path/to/cssfile.custom'], function() { /* cssfile.custom loaded as stylesheet */ }); ``` 1. Force treat file as image ```javascript loadjs(['img!/path/to/image.custom'], function() { /* image.custom loaded */ }); ``` 1. Add a bundle id ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Use .ready() to define bundles and callbacks separately ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Use multiple bundles in .ready() dependency lists ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs(['/path/to/bar1.js', '/path/to/bar2.js'], 'bar'); loadjs.ready(['foo', 'bar'], function() { /* foo.js & bar1.js & bar2.js loaded */ }); ``` 1. Chain .ready() together ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs .ready('foo', function() { /* foo.js loaded */ }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Use Promises to register callbacks ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true}) .then(function() { /* foo.js & bar.js loaded */ }) .catch(function(pathsNotFound) { /* at least one didn't load */ }); ``` 1. Check if bundle has already been defined ```javascript if (!loadjs.isDefined('foobar')) { loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() { /* foo.js and bar.js loaded in series */ }, async: false }); ``` 1. Add an error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ } }); ``` 1. Retry files before calling the error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ }, numRetries: 3 }); // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries ``` 1. Install dependencies * nodejs (http://nodejs.org/) * npm (https://www.npmjs.org/) * http-server (via npm) 1. Clone repository /* called for each script node before being embedded */ if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; } }); ``` 1. Bypass LoadJS default DOM insertion mechanism (DOM `<head>`) ```javascript loadjs(['/path/to/foo.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { document.body.appendChild(scriptEl); /* return `false` to bypass default DOM insertion mechanism */ return false; } }); ``` 1. Use bundle ids in error callback $ npm run http-server -- -p 3000 ``` Then visit http://localhost:3000/examples 1. Build distribution files loadjs.ready(['foo', 'bar', 'thunk'], { success: function() { // foo.js & bar.js & thunkor.js & thunky.js loaded }, error: function(depsNotFound) { if (depsNotFound.indexOf('foo') > -1) {}; // foo failed if (depsNotFound.indexOf('bar') > -1) {}; // bar failed if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed } }); ``` $ npm run build-tests ``` Then visit http://localhost:3000/test 1. Build all files function fn1() { loadjs.done('dependency1'); } function fn2() { loadjs.done('dependency2'); } ``` 1. Reset dependency trackers ```javascript loadjs.reset(); ``` 1. Implement a require-like dependency manager ```javascript var bundles = { 'bundleA': ['/file1.js', '/file2.js'], 'bundleB': ['/file3.js', '/file4.js'] }; function require(bundleIds, callbackFn) { bundleIds.forEach(function(bundleId) { if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId); }); loadjs.ready(bundleIds, callbackFn); } require(['bundleA'], function() { /* bundleA loaded */ }); require(['bundleB'], function() { /* bundleB loaded */ }); require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ }); ``` ## Directory structure <pre> loadjs/ β”œβ”€β”€ dist β”‚Β Β  β”œβ”€β”€ loadjs.js β”‚Β Β  β”œβ”€β”€ loadjs.min.js β”‚Β Β  └── loadjs.umd.js β”œβ”€β”€ examples β”œβ”€β”€ gulpfile.js β”œβ”€β”€ LICENSE.txt β”œβ”€β”€ package.json β”œβ”€β”€ README.md β”œβ”€β”€ src β”‚Β Β  └── loadjs.js β”œβ”€β”€ test └── umd-templates </pre> ## Development Quickstart 1. Install dependencies * [nodejs](http://nodejs.org/) * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository ```bash $ git clone [email protected]:muicss/loadjs.git $ cd loadjs ``` 1. Install node dependencies using npm ```bash $ npm install ``` 1. Build examples ```bash $ npm run build-examples ``` To view the examples you can use any static file server. To use the `nodejs` http-server module: ```bash $ npm install http-server $ npm run http-server -- -p 3000 ``` Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files ```bash $ npm run build-dist ``` The files will be located in the `dist` directory. 1. Run tests To run the browser tests first build the `loadjs` library: ```bash $ npm run build-tests ``` Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files ```bash $ npm run build-all ``` <MSG> updated readme <DFF> @@ -11,7 +11,7 @@ LoadJS is a tiny async loader for modern browsers (710 bytes). LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript and CSS files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code in your &lt;html&gt; and then use the `loadjs` global to manage JavaScript dependencies after pageload. -LoadJS is based on the excellent <a href="https://github.com/ded/script.js">$script</a> library by <a href="https://github.com/ded">Dustin Diaz</a>. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 710 bytes (minified + gzipped). +LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 710 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: @@ -27,8 +27,8 @@ loadjs.ready('foobar', { ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: - * [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.js) - * [loadjs.min.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) + * [loadjs.js](dist/loadjs.js) + * [loadjs.min.js](dist/loadjs.min.js) You can also use it as a CJS or AMD module: @@ -229,8 +229,8 @@ loadjs/ 1. Install dependencies - * nodejs (http://nodejs.org/) - * npm (https://www.npmjs.org/) + * [nodejs](http://nodejs.org/) + * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository @@ -259,7 +259,7 @@ loadjs/ $ npm run http-server -- -p 3000 ``` - Then visit http://localhost:3000/examples + Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files @@ -277,7 +277,7 @@ loadjs/ $ npm run build-tests ``` - Then visit http://localhost:3000/test + Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files
7
updated readme
7
.md
md
mit
muicss/loadjs
10067078
<NME> fruitmachine.js <BEF> /*jslint browser:true, node:true*/ /** * FruitMachine * * Renders layouts/modules from a basic layout definition. * If views require custom interactions devs can extend * the basic functionality. * * @version 0.3.3 * @copyright The Financial Times Limited [All Rights Reserved] * @author Wilson Page <[email protected]> */ 'use strict'; /** * Module Dependencies */ var mod = require('./module'); var define = require('./define'); var utils = require('utils'); var events = require('evt'); /** * Creates a fruitmachine */ /*jslint browser:true, node:true*/ (function(root) { 'use strict'; var FruitMachine = typeof exports === 'object' ? exports : root.FruitMachine = {}; // Current Version FruitMachine.VERSION = '0.0.1'; // Create local references to some native methods. var slice = Array.prototype.slice; var splitter = /\s+/; var Events = { }; // Mixin events and return return events(fm); }; }; /** * VIEW */ var View = FruitMachine.View = function(options) { }; // Extend the prototype util.extend(View.prototype, Events, { /** * Public Methods */ // Overwrite these yourself // inside your custom view logic. onInitialize: function() {}, onSetup: function() {}, onTeardown: function() {}, onDestroy: function() {}, /** * Declares whether a view has * a child that matches a standard * child query (id or module name). * * @param {String} query * @return {Boolean} */ hasChild: function(query) { return !!this.child(query); }, /** * Adds a child view. * * By default the view is appended, * and if the View has an element, * it is inserted into the parent * element. * * Options: * - `at` A specific index at which to add * - `append` Staes if the View element is added to the parent * * @param {View|Object|Array} view * @param {View} options */ add: function(view, options) { var children; var at = options && options.at; var append = options && options.append; // If the view passed in is not an instance // of `DefaultView` then we need to turn the // json into a View instance and re-add it. // Array#concat() ensures we're always // dealing with an Array. if (!(view instanceof DefaultView)) { children = [].concat(view); for (var i = 0, l = children.length; i < l; i++) { this.add(new View(children[i])); } return this; } // Dont add this child if it already exists if (this.hasChild(view.id())) return this; // Merge the global id reference stores util.extend(this._globals.id, view._globals.id); // Set a refercne back to the parent view.parent = this; util.insert(view, this._children, at); // Store a reference to this child by id on the parent. this._childHash[view._id] = view; // Create a reference for views by module type. There could be // more than one view instance with the same module type so // we use an array for storage. this._childHash[view.module] = this._childHash[view.module] || []; this._childHash[view.module].push(view); // We append the child to the parent view if there is a view // element and the users hasn't flagged `append` false. if (append !== false && view.el) { util.insertChild(view.el, this.el, at); } // Allow chaining return this; }, /** * Renders a View instance. * * Options: * - `asString` Simply returns html. * - `embedData` Embeds view data as an html attribute * - `forClient` Adds extra attributes for client interpretation * * @param {[type]} options [description] * @return {[type]} [description] */ render: function(options) { var html = this._toHTML(options); var asString = options && options.asString; var newEl; // Check html has been generated if ('undefined' === typeof html) return this; // Return html string if requested if (asString) return html; // Replace the contents of the current element with the // newly rendered element. We do this so that the original // view element is not replaced, and we don't loose any delegate // event listeners. newEl = util.toNode(html); // If the view has an element, // replace it with the new element. if (this.el) util.replaceEl(this.el, newEl); // Set the new rendered element // as the view's element. this.el = newEl; // Update the View.els for each child View. this.updateChildEls(); this.trigger('render'); // Return this for chaining. return this; }, /** * Fetches all child View elements, * then allocates each element to * a View instance by id. * * This is run when View#render() is * called to assign newly rendered * View elements to their View instances. * * @return {[type]} [description] */ updateChildEls: function() { var i, l, htmlChildren; this._purgeChildrenFromHtmlCache(); htmlChildren = this._childrenFromHtml(); for (i = 0, l = htmlChildren.length; i < l; i++) { var child = htmlChildren[i]; var match = this.id(child._id); if (!match) continue; match.el = child.el; } return this; }, /** * A single method for getting * and setting view data. * * Example: * * // Getters * var all = view.data(); * var one = view.data('myKey'); * * // Setters * view.data('myKey', 'my value'); * view.data({ * myKey: 'my value', * anotherKey: 10 * }); * * @param {String|Object|null} key * @param {*} value * @return {*} */ data: function(key, value) { // If no key and no value have // been passed then return the // entire data store. if (!key && !value) { return this._data; } // If a string key has been // passed, but no value if (typeof key === 'string' && !value) { return this._data[key]; } // If the user has stated a key // and a value. Set the value on // the key. if (key && value) { this._data[key] = value; this.trigger('datachange', key, value); this.trigger('datachange:' + key, value); return this; } // If the key is an object literal // then we extend the data store with it. if ('object' === typeof key) { util.extend(this._data, key); this.trigger('datachange'); for (var prop in key) this.trigger('datachange:' + prop, key[prop]); return this; } }, /** * Returns a single immediate * child View instance. * * Accepts a module type or view id. * * @param {[type]} query [description] * @return {[type]} [description] */ child: function(query) { var result = this._childHash[query]; return result ? result[0] || result : null; }, /** * Returns an array of children * that match the query. If no * query is passed, all children * are returned. * * @param {String} [query] * @return {Array} */ children: function(query) { return query ? this._childHash[query] : this._children; }, /** * Returns a View instance by id or * if no argument is given the id * of the view. * * @param {String} id * @return {View|String} */ id: function(id) { return id ? this._globals.id[id] : this._id; }, /** * Replaced the contents of the * passed element with the view * element. * * @param {Element} el * @return {FruitMachine.View} */ inject: function(el) { if (!el) return this; el.innerHTML = ''; el.appendChild(this.el); return this; }, /** * Calls the `onSetup` event and * triggers the `setup` event to * allow you to do custom setup logic * inside your custom views. * * Options: * - `shallow` Don't setup recursively * * @return {FruitMachine.View} */ setup: function(options) { var shallow = options && options.shallow; // Call 'setup' on all subviews // first (bottom up recursion). if (!shallow) { for (var i = 0, l = this._children.length; i < l; i++) { this._children[i].setup(); } } // If this is already setup, call // `teardown` first so that we don't // duplicate event bindings and shizzle. if (this.isSetup) this.teardown({ shallow: true }); // If a view doesn't have an element // we will not proceed to setup. // // A view may not have an element // for the following reason // - The {{{fm_classes}}} and {{{fm_attrs}}} hooks // may not be present on the template. // - A child view's html hasn't been printed // into the parent view's template. if (!this.el) return error("FruitMachine - No view.el found for view: '%s'", this.id()); // Trigger the beforesetup event so that // FruitMachine plugins can hook into them FruitMachine.trigger('beforesetup', this); // We trigger a `setup` event and // call the `onSetup` method. You can // listen to the `setup` event, or // overwrite the `onSetup` method in // your custom views to do setup logic. this.trigger('setup'); this.onSetup(); this.isSetup = true; // For chaining return this; }, /** * Teardown calls the `teardown` * event on all children then on itself. * * Teardown allows custom views to listen to * the event and unbind event listeners etc. * * Teardown should be used if the view * itself is not going to be destroyed; * just updated in some way. * * Options: * - `shallow` Don't teardown recursively * * @return {View} */ teardown: function(options) { var shallow = options && options.shallow; // If the shollow options is not // declared, run teardown recursively. if (!shallow) { for (var i = 0, l = this._children.length; i < l; i++) { this._children[i].teardown(); } } // Trigger the `beforeteardown` event so that // FruitMachine plugins can hook into them FruitMachine.trigger('beforeteardown', this); this.trigger('teardown'); this.onTeardown(); this.isSetup = false; // For chaining return this; }, /** * Destroys all children. * * @return {View} */ empty: function() { while (this._children.length) { this._children[0].destroy(); } return this; }, /** * Recursively destroys all child views. * This includes running `teardown`, * detaching itself from the DOM and parent * and unsetting any referenced. * * A `destroy` event is triggered and * the `onDestroy` method is called. * This allows you to bind to this event * and destroy logic inside your custom views. * * @param {Object} options * @return void */ destroy: function(options) { // Recursively run on children // first (bottom up). // // We don't waste time removing // the child elements as they will // get removed when the parent // element is removed. while (this._children.length) { this._children[0].destroy({ skipEl: true }); } // Run teardown so custom // views can bind logic to it this.teardown(options); // Hook for plugins so that functionality // can be triggered before Fruit Machine // object destruction. FruitMachine.trigger('beforedestroy', this); // Detach this view from its // parent and unless otherwise // stated, from the DOM. this._detach(options); // Trigger a destroy event // for custom Views to bind to. this.trigger('destroy'); this.onDestroy(); // Set a flag to say this view // has been destroyed. This is // useful to check for after a // slow ajax call that might come // back after a view has been detroyed. this.destroyed = true; // Clear references this.el = this.module = this._id = this._globals = this._childHash = this._data = null; }, /** * Private Methods */ /** * Configure all options passed * into the constructor. * * @param {Object} options * @return void */ _configure: function(options) { this.parent = options.parent; this.el = options.el; this.module = options.module; this._id = options._id || options.id || util.uniqueId('dynamic'); this._children = []; this._globals = options._globals || { id: {} }; this._childHash = {}; this._data = util.extend({}, options.data); }, /** * An internal api to add child * views. It ensures that globals * are inherited and views with elements * are not appends to the parent view. * * @param {Objecy} options */ _add: function(options) { // Make sure the globals are passed on // as this includes important data. options._globals = this._globals; // Don't append the element into the parent element this.add(new View(options), { append: false }); }, _detach: function(options) { var skipEl = options && options.skipEl; var i; // Remove the view el from the DOM if (!skipEl && this.el && this.el.parentNode) this.el.parentNode.removeChild(this.el); // If there is no parent view reference, return here. if (!this.parent) return this; // Remove reference from children array i = this.parent._children.indexOf(this); this.parent._children.splice(i, 1); // Remove references from childHash i = this.parent._childHash[this.module].indexOf(this); this.parent._childHash[this.module].splice(i, 1); delete this.parent._childHash[this._id]; delete this.parent._globals.id[this._id]; // Return the detached view instance. return this; }, /** * Recursively renders a view, * and all child views, returning * and html string. * * Options: * - `embedData` Embeds view data as an html attribute * - `forClient` Adds extra attributes for client interpretation * * @param {Object} options * @return {String} */ _toHTML: function(options) { var template = SETTINGS.templates(this.module); var renderData = {}; // Don't template models that // are flagged with render: false; if (this.render === false) return; // Check we have a template if (!template) return ""; // Create an array to store child html in. renderData[SETTINGS.mustacheSlotArrayName] = []; if (this._children) { for (var i = 0, l = this._children.length; i < l; i++) { var child = this._children[i]; var html = child._toHTML(options); // Make the sub view html available // to the parent model. So that when the // parent model is rendered it can print // the sub view html into the correct slot. renderData[SETTINGS.mustacheSlotArrayName].push(util.extend({ child: html }, child.data())); renderData[child._id] = html; } } // Prepare the render data. renderData.fm_classes = SETTINGS.slotClass; renderData.fm_attrs = this._htmlAttrs(options); // Call render template. return template(util.extend(renderData, this.data())); }, /** * Creates an html attribute string * for this view element. * * Options: * - `embedData` Embeds view.data() as an html attribute * - `forClient` Adds extra attributes for client interpretation * * @param {Object} options * @return {String} */ _htmlAttrs: function(options) { var attrs = {}; var embedData = options && options.embedData; var forClient = options && options.forClient; // Setup module attributes attrs[SETTINGS.moduleIdAttr] = this._id; attrs[SETTINGS.moduleTypeAttr] = this.module; // If embedded data has been requested // stringify and escape the if (embedData) { attrs[SETTINGS.moduleDataAttr] = util.escape(JSON.stringify(this.data())); } if (forClient && this.parent) { attrs[SETTINGS.parentAttr] = this.parent._id; } return util.attributes(attrs); }, /** * Returns all child views found * in the current View's html. * * @return {Array} */ _childrenFromHtml: function(parentId) { var els, el, child; var children = []; var cache = this._globals.childrenFromHtml; if (!this.el) return children; // If a cache exists, use that if (cache) return parentId ? cache[parentId] : cache; // Else, create a cache cache = this._globals.childrenFromHtml = []; // Look for child elements els = this.el.getElementsByClassName(SETTINGS.slotClass); // Loop over each element found for (var i = 0, l = els.length; i < l; i++) { el = els[i]; child = { el: el, _id: el.getAttribute(SETTINGS.moduleIdAttr) || util.uniqueId('unknown'), module: el.getAttribute(SETTINGS.moduleTypeAttr) || 'undefined', parentId: el.getAttribute(SETTINGS.parentAttr), data: util.extractEmbeddedData(el) }; // If a parent id has not been // stated, or the parentId matches // the html attribute parent id, // add this child to the array. if (!parentId || parentId === child.parentId) children.push(child); // Cache this child cache.push(child); cache[child.parentId] = cache[child.parentId] || []; cache[child.parentId].push(child); } return children; }, /** * Purges any cached children from html, * so that when `childrenFromHtml` is next * run it will search for new elements. * * @return void */ _purgeChildrenFromHtmlCache: function() { delete this._globals.childrenFromHtml; } }); View.extend = function(module, protoProps, staticProps) { FruitMachine.Views[module] = DefaultView.extend(protoProps, staticProps); }; // We add the 'extend' static method to the FruitMachine base // class. This allows you to extend the default View class // to add custom insteractions and logic to more complex modules. // Redefining any of the View.prototype methods will overwrite them. DefaultView.extend = util.inherits; }(this)); <MSG> Basic new version created <DFF> @@ -28,15 +28,34 @@ */ /*jslint browser:true, node:true*/ -(function(root) { +var View = (function() { 'use strict'; - var FruitMachine = typeof exports === 'object' ? exports : root.FruitMachine = {}; - // Current Version - FruitMachine.VERSION = '0.0.1'; + var module = {}; + //var View = typeof exports === 'object' ? exports : root.View = {}; // Create local references to some native methods. var slice = Array.prototype.slice; + var concat = Array.prototype.concat; + var has = Object.prototype.hasOwnProperty; + + function mixin(original) { + // Loop over every argument after the first. + slice.call(arguments, 1).forEach(function(source) { + for (var prop in source) { + original[prop] = source[prop]; + } + }); + return original; + } + + var uniqueId = (function() { + var i = 0; + return function(prefix) { + prefix = prefix || ''; + return prefix + (++i * Math.round(Math.random() * 10000000)); + }; + }()); var splitter = /\s+/; var Events = { @@ -136,682 +155,188 @@ }; + var Modules = {}; + + function create(options) { + var Module = Modules[options.type]; + if (!Module) return; + delete options.type; + return new Module(options); + } + /** * VIEW */ - var View = FruitMachine.View = function(options) { - + var View = module.exports = function (options) { + if (options.type) return create(options); + this._configure(options); + this.add(options.views); + this.initialize(options); }; - // Extend the prototype - util.extend(View.prototype, Events, { - - /** - * Public Methods - */ - - // Overwrite these yourself - // inside your custom view logic. - onInitialize: function() {}, - onSetup: function() {}, - onTeardown: function() {}, - onDestroy: function() {}, - - /** - * Declares whether a view has - * a child that matches a standard - * child query (id or module name). - * - * @param {String} query - * @return {Boolean} - */ - - hasChild: function(query) { - return !!this.child(query); - }, - - /** - * Adds a child view. - * - * By default the view is appended, - * and if the View has an element, - * it is inserted into the parent - * element. - * - * Options: - * - `at` A specific index at which to add - * - `append` Staes if the View element is added to the parent - * - * @param {View|Object|Array} view - * @param {View} options - */ - - add: function(view, options) { - var children; - var at = options && options.at; - var append = options && options.append; - - // If the view passed in is not an instance - // of `DefaultView` then we need to turn the - // json into a View instance and re-add it. - // Array#concat() ensures we're always - // dealing with an Array. - if (!(view instanceof DefaultView)) { - children = [].concat(view); - for (var i = 0, l = children.length; i < l; i++) { - this.add(new View(children[i])); - } - - return this; - } + mixin(View.prototype, Events, { - // Dont add this child if it already exists - if (this.hasChild(view.id())) return this; - - // Merge the global id reference stores - util.extend(this._globals.id, view._globals.id); - - // Set a refercne back to the parent - view.parent = this; - util.insert(view, this._children, at); - - // Store a reference to this child by id on the parent. - this._childHash[view._id] = view; - - // Create a reference for views by module type. There could be - // more than one view instance with the same module type so - // we use an array for storage. - this._childHash[view.module] = this._childHash[view.module] || []; - this._childHash[view.module].push(view); - - // We append the child to the parent view if there is a view - // element and the users hasn't flagged `append` false. - if (append !== false && view.el) { - util.insertChild(view.el, this.el, at); - } - - // Allow chaining - return this; - }, - - /** - * Renders a View instance. - * - * Options: - * - `asString` Simply returns html. - * - `embedData` Embeds view data as an html attribute - * - `forClient` Adds extra attributes for client interpretation - * - * @param {[type]} options [description] - * @return {[type]} [description] - */ - - render: function(options) { - var html = this._toHTML(options); - var asString = options && options.asString; - var newEl; - - // Check html has been generated - if ('undefined' === typeof html) return this; - - // Return html string if requested - if (asString) return html; - - // Replace the contents of the current element with the - // newly rendered element. We do this so that the original - // view element is not replaced, and we don't loose any delegate - // event listeners. - newEl = util.toNode(html); - - // If the view has an element, - // replace it with the new element. - if (this.el) util.replaceEl(this.el, newEl); - - // Set the new rendered element - // as the view's element. - this.el = newEl; - - // Update the View.els for each child View. - this.updateChildEls(); - this.trigger('render'); - - // Return this for chaining. - return this; - }, - - /** - * Fetches all child View elements, - * then allocates each element to - * a View instance by id. - * - * This is run when View#render() is - * called to assign newly rendered - * View elements to their View instances. - * - * @return {[type]} [description] - */ - - updateChildEls: function() { - var i, l, htmlChildren; - - this._purgeChildrenFromHtmlCache(); - htmlChildren = this._childrenFromHtml(); - - for (i = 0, l = htmlChildren.length; i < l; i++) { - var child = htmlChildren[i]; - var match = this.id(child._id); - if (!match) continue; - match.el = child.el; - } - - return this; + _configure: function(options) { + this._id = options.id || uniqueId('auto_'); + this._fmid = uniqueId('fmid'); + this.model = options.model || {}; + this._children = []; + this._lookup = {}; }, - /** - * A single method for getting - * and setting view data. - * - * Example: - * - * // Getters - * var all = view.data(); - * var one = view.data('myKey'); - * - * // Setters - * view.data('myKey', 'my value'); - * view.data({ - * myKey: 'my value', - * anotherKey: 10 - * }); - * - * @param {String|Object|null} key - * @param {*} value - * @return {*} - */ - - data: function(key, value) { - - // If no key and no value have - // been passed then return the - // entire data store. - if (!key && !value) { - return this._data; - } + initialize: function() {}, - // If a string key has been - // passed, but no value - if (typeof key === 'string' && !value) { - return this._data[key]; - } + add: function(views) { + if (!views) return; + var view; - // If the user has stated a key - // and a value. Set the value on - // the key. - if (key && value) { - this._data[key] = value; - this.trigger('datachange', key, value); - this.trigger('datachange:' + key, value); - return this; - } + views = concat.call([], views); - // If the key is an object literal - // then we extend the data store with it. - if ('object' === typeof key) { - util.extend(this._data, key); - this.trigger('datachange'); - for (var prop in key) this.trigger('datachange:' + prop, key[prop]); - return this; + for (var i = 0, l = views.length; i < l; i++) { + view = views[i]; + if (!(view instanceof View)) view = new View(view); + this._children.push(view); + this._lookup[view.id()] = view; + view.parent = this; } - }, - - /** - * Returns a single immediate - * child View instance. - * - * Accepts a module type or view id. - * - * @param {[type]} query [description] - * @return {[type]} [description] - */ - - child: function(query) { - var result = this._childHash[query]; - return result ? result[0] || result : null; - }, - /** - * Returns an array of children - * that match the query. If no - * query is passed, all children - * are returned. - * - * @param {String} [query] - * @return {Array} - */ - - children: function(query) { - return query ? this._childHash[query] : this._children; + return this; }, - /** - * Returns a View instance by id or - * if no argument is given the id - * of the view. - * - * @param {String} id - * @return {View|String} - */ - id: function(id) { - return id ? this._globals.id[id] : this._id; + return id ? this._lookup[id] : this._id; }, - /** - * Replaced the contents of the - * passed element with the view - * element. - * - * @param {Element} el - * @return {FruitMachine.View} - */ - - inject: function(el) { - if (!el) return this; - el.innerHTML = ''; - el.appendChild(this.el); - return this; - }, - - /** - * Calls the `onSetup` event and - * triggers the `setup` event to - * allow you to do custom setup logic - * inside your custom views. - * - * Options: - * - `shallow` Don't setup recursively - * - * @return {FruitMachine.View} - */ - - setup: function(options) { - var shallow = options && options.shallow; - - // Call 'setup' on all subviews - // first (bottom up recursion). - if (!shallow) { - for (var i = 0, l = this._children.length; i < l; i++) { - this._children[i].setup(); - } - } - - // If this is already setup, call - // `teardown` first so that we don't - // duplicate event bindings and shizzle. - if (this.isSetup) this.teardown({ shallow: true }); - - // If a view doesn't have an element - // we will not proceed to setup. - // - // A view may not have an element - // for the following reason - // - The {{{fm_classes}}} and {{{fm_attrs}}} hooks - // may not be present on the template. - // - A child view's html hasn't been printed - // into the parent view's template. - if (!this.el) return error("FruitMachine - No view.el found for view: '%s'", this.id()); - - // Trigger the beforesetup event so that - // FruitMachine plugins can hook into them - FruitMachine.trigger('beforesetup', this); - - // We trigger a `setup` event and - // call the `onSetup` method. You can - // listen to the `setup` event, or - // overwrite the `onSetup` method in - // your custom views to do setup logic. - this.trigger('setup'); - this.onSetup(); - this.isSetup = true; - - // For chaining - return this; + fmid: function() { + return this._fmid; }, - /** - * Teardown calls the `teardown` - * event on all children then on itself. - * - * Teardown allows custom views to listen to - * the event and unbind event listeners etc. - * - * Teardown should be used if the view - * itself is not going to be destroyed; - * just updated in some way. - * - * Options: - * - `shallow` Don't teardown recursively - * - * @return {View} - */ - - teardown: function(options) { - var shallow = options && options.shallow; - - // If the shollow options is not - // declared, run teardown recursively. - if (!shallow) { - for (var i = 0, l = this._children.length; i < l; i++) { - this._children[i].teardown(); - } - } - - // Trigger the `beforeteardown` event so that - // FruitMachine plugins can hook into them - FruitMachine.trigger('beforeteardown', this); - - this.trigger('teardown'); - this.onTeardown(); - this.isSetup = false; - - // For chaining - return this; + data: function() { + if (!this.model) return {}; + if (this.model.toJSON) return this.model.toJSON(); + return this.model; }, - /** - * Destroys all children. - * - * @return {View} - */ - - empty: function() { - while (this._children.length) { - this._children[0].destroy(); - } - - return this; + children: function() { + return this._children; }, - /** - * Recursively destroys all child views. - * This includes running `teardown`, - * detaching itself from the DOM and parent - * and unsetting any referenced. - * - * A `destroy` event is triggered and - * the `onDestroy` method is called. - * This allows you to bind to this event - * and destroy logic inside your custom views. - * - * @param {Object} options - * @return void - */ - - destroy: function(options) { - - // Recursively run on children - // first (bottom up). - // - // We don't waste time removing - // the child elements as they will - // get removed when the parent - // element is removed. - while (this._children.length) { - this._children[0].destroy({ skipEl: true }); + html: function() { + var data = {}; + var children = this.children(); + var child, html; + data.views = []; + + for (var i = 0, l = children.length; i < l; i++) { + child = children[i]; + html = child.html(); + data[child.id()] = html; + data.views.push({ view: html }); } - // Run teardown so custom - // views can bind logic to it - this.teardown(options); - - // Hook for plugins so that functionality - // can be triggered before Fruit Machine - // object destruction. - FruitMachine.trigger('beforedestroy', this); - - // Detach this view from its - // parent and unless otherwise - // stated, from the DOM. - this._detach(options); - - // Trigger a destroy event - // for custom Views to bind to. - this.trigger('destroy'); - this.onDestroy(); - - // Set a flag to say this view - // has been destroyed. This is - // useful to check for after a - // slow ajax call that might come - // back after a view has been detroyed. - this.destroyed = true; - - // Clear references - this.el = this.module = this._id = this._globals = this._childHash = this._data = null; + data.fm_attrs = 'id="' + this.fmid() + '"'; + return this._html = this.template.render(mixin(data, this.data())); }, - /** - * Private Methods - */ - - /** - * Configure all options passed - * into the constructor. - * - * @param {Object} options - * @return void - */ - - _configure: function(options) { - this.parent = options.parent; - this.el = options.el; - this.module = options.module; - this._id = options._id || options.id || util.uniqueId('dynamic'); - this._children = []; - this._globals = options._globals || { id: {} }; - this._childHash = {}; - this._data = util.extend({}, options.data); + render: function() { + return this.update(); }, - /** - * An internal api to add child - * views. It ensures that globals - * are inherited and views with elements - * are not appends to the parent view. - * - * @param {Objecy} options - */ - - _add: function(options) { - - // Make sure the globals are passed on - // as this includes important data. - options._globals = this._globals; + setup: function() { - // Don't append the element into the parent element - this.add(new View(options), { append: false }); }, - _detach: function(options) { - var skipEl = options && options.skipEl; - var i; - - // Remove the view el from the DOM - if (!skipEl && this.el && this.el.parentNode) this.el.parentNode.removeChild(this.el); - - // If there is no parent view reference, return here. - if (!this.parent) return this; - - // Remove reference from children array - i = this.parent._children.indexOf(this); - this.parent._children.splice(i, 1); - - // Remove references from childHash - i = this.parent._childHash[this.module].indexOf(this); - this.parent._childHash[this.module].splice(i, 1); - delete this.parent._childHash[this._id]; - delete this.parent._globals.id[this._id]; - - // Return the detached view instance. - return this; + el: function() { + return this._el || (this._el = document.getElementById(this.fmid())); }, - /** - * Recursively renders a view, - * and all child views, returning - * and html string. - * - * Options: - * - `embedData` Embeds view data as an html attribute - * - `forClient` Adds extra attributes for client interpretation - * - * @param {Object} options - * @return {String} - */ - - _toHTML: function(options) { - var template = SETTINGS.templates(this.module); - var renderData = {}; - - // Don't template models that - // are flagged with render: false; - if (this.render === false) return; - - // Check we have a template - if (!template) return ""; - - // Create an array to store child html in. - renderData[SETTINGS.mustacheSlotArrayName] = []; - - if (this._children) { - for (var i = 0, l = this._children.length; i < l; i++) { - var child = this._children[i]; - var html = child._toHTML(options); - - // Make the sub view html available - // to the parent model. So that when the - // parent model is rendered it can print - // the sub view html into the correct slot. - renderData[SETTINGS.mustacheSlotArrayName].push(util.extend({ child: html }, child.data())); - renderData[child._id] = html; - } - } - - // Prepare the render data. - renderData.fm_classes = SETTINGS.slotClass; - renderData.fm_attrs = this._htmlAttrs(options); - - // Call render template. - return template(util.extend(renderData, this.data())); - }, + update: function() { + var current = this.el(); + var replacement = this.toNode(); - /** - * Creates an html attribute string - * for this view element. - * - * Options: - * - `embedData` Embeds view.data() as an html attribute - * - `forClient` Adds extra attributes for client interpretation - * - * @param {Object} options - * @return {String} - */ - - _htmlAttrs: function(options) { - var attrs = {}; - var embedData = options && options.embedData; - var forClient = options && options.forClient; - - // Setup module attributes - attrs[SETTINGS.moduleIdAttr] = this._id; - attrs[SETTINGS.moduleTypeAttr] = this.module; - - // If embedded data has been requested - // stringify and escape the - if (embedData) { - attrs[SETTINGS.moduleDataAttr] = util.escape(JSON.stringify(this.data())); - } - - if (forClient && this.parent) { - attrs[SETTINGS.parentAttr] = this.parent._id; + if (!current && !current.parentNode) { + this._el = replacement; + return this; } - return util.attributes(attrs); + current.parentNode.replaceChild(replacement, current); + this._el = replacement; + return this; }, - /** - * Returns all child views found - * in the current View's html. - * - * @return {Array} - */ - - _childrenFromHtml: function(parentId) { - var els, el, child; - var children = []; - var cache = this._globals.childrenFromHtml; - - if (!this.el) return children; - - // If a cache exists, use that - if (cache) return parentId ? cache[parentId] : cache; - - // Else, create a cache - cache = this._globals.childrenFromHtml = []; - - // Look for child elements - els = this.el.getElementsByClassName(SETTINGS.slotClass); - - // Loop over each element found - for (var i = 0, l = els.length; i < l; i++) { - el = els[i]; - - child = { - el: el, - _id: el.getAttribute(SETTINGS.moduleIdAttr) || util.uniqueId('unknown'), - module: el.getAttribute(SETTINGS.moduleTypeAttr) || 'undefined', - parentId: el.getAttribute(SETTINGS.parentAttr), - data: util.extractEmbeddedData(el) - }; - - // If a parent id has not been - // stated, or the parentId matches - // the html attribute parent id, - // add this child to the array. - if (!parentId || parentId === child.parentId) children.push(child); - - // Cache this child - cache.push(child); - cache[child.parentId] = cache[child.parentId] || []; - cache[child.parentId].push(child); - } - - return children; + node: function() { + var el = document.createElement('div'); + el.innerHTML = this.html(); + return el.firstElementChild; }, - /** - * Purges any cached children from html, - * so that when `childrenFromHtml` is next - * run it will search for new elements. - * - * @return void - */ - - _purgeChildrenFromHtmlCache: function() { - delete this._globals.childrenFromHtml; + inject: function(dest) { + var el = this.el(); + dest.innerHTML = ''; + dest.appendChild(el); } - }); - View.extend = function(module, protoProps, staticProps) { - FruitMachine.Views[module] = DefaultView.extend(protoProps, staticProps); + + View.register = function(type, modules) { + mixin(Modules, modules); + }; + + // Helpers + // ------- + + // Helper function to correctly set up the prototype chain, for subclasses. + // Similar to `goog.inherits`, but uses a hash of prototype properties and + // class properties to be extended. + View.inherit = function(protoProps, staticProps) { + var parent = this; + var child; + + // The constructor function for the new subclass is either defined by you + // (the "constructor" property in your `extend` definition), or defaulted + // by us to simply call the parent's constructor. + if (protoProps && has.call(protoProps, 'constructor')) { + child = protoProps.constructor; + } else { + child = function(){ return parent.apply(this, arguments); }; + } + + // Add static properties to the constructor function, if supplied. + mixin(child, parent, staticProps); + + // Set the prototype chain to inherit from `parent`, without calling + // `parent`'s constructor function. + var Surrogate = function(){ this.constructor = child; }; + Surrogate.prototype = parent.prototype; + child.prototype = new Surrogate(); + + // Add prototype properties (instance properties) to the subclass, + // if supplied. + if (protoProps) mixin(child.prototype, protoProps); + + // Set a convenience property in case the parent's prototype is needed + // later. + child.__super__ = parent.prototype; + + return child; }; // We add the 'extend' static method to the FruitMachine base // class. This allows you to extend the default View class // to add custom insteractions and logic to more complex modules. // Redefining any of the View.prototype methods will overwrite them. - DefaultView.extend = util.inherits; -}(this)); + View.extend = function(type, props) { + if ('string' === typeof type) { + return Modules[type] = View.inherit(props); + } else if ('object' === typeof type) { + return View.inherit(type); + } + }; + + // Current Version + View.VERSION = '0.0.1'; + + return module.exports; +}(this)); \ No newline at end of file
155
Basic new version created
630
.js
js
mit
ftlabs/fruitmachine
10067079
<NME> loadjs.min.js <BEF> loadjs=function(){var n=function(){},e={},t={},r={};function c(n,e){if(n){var c=r[n];if(t[n]=e,c)for(;c.length;)c[0](n,e),c.splice(0,1)}}function i(e,t){e.call&&(e={success:e}),t.length?(e.error||n)(t):(e.success||n)(e)}function o(e,t,r,c){var i,s,u=document,f=r.async,a=(r.numRetries||0)+1,h=r.before||n;c=c||0,/(^css!|\.css$)/.test(e)?(i=!0,(s=u.createElement("link")).rel="stylesheet",s.href=e.replace(/^css!/,"")):((s=u.createElement("script")).src=e,s.async=void 0===f||f),s.onload=s.onerror=s.onbeforeload=function(n){var u=n.type[0];if(i&&"hideFocus"in s)try{s.sheet.cssText.length||(u="e")}catch(n){u="e"}if("e"==u&&(c+=1)<a)return o(e,t,r,c);t(e,u,n.defaultPrevented)},!1!==h(e,s)&&u.head.appendChild(s)}function s(n,t,r){var s,u;if(t&&t.trim&&(s=t),u=(s?r:t)||{},s){if(s in e)throw"LoadJS";e[s]=!0}!function(n,e,t){var r,c,i=(n=n.push?n:[n]).length,s=i,u=[];for(r=function(n,t,r){if("e"==t&&u.push(n),"b"==t){if(!r)return;u.push(n)}--i||e(u)},c=0;c<s;c++)o(n[c],r,t)}(n,function(n){i(u,n),c(s,n)},u)}return s.ready=function(n,e){return function(n,e){var c,i,o,s=[],u=(n=n.push?n:[n]).length,f=u;for(c=function(n,t){t.length&&s.push(n),--f||e(s)};u--;)i=n[u],(o=t[i])?c(i,o):(r[i]=r[i]||[]).push(c)}(n,function(n){i(e,n)}),s},s.done=function(n){c(n,[])},s.reset=function(){e={},t={},r={}},s.isDefined=function(n){return n in e},s}(); <MSG> fixed error in README example <DFF> @@ -1,1 +1,1 @@ -loadjs=function(){var n=function(){},e={},t={},r={};function c(n,e){if(n){var c=r[n];if(t[n]=e,c)for(;c.length;)c[0](n,e),c.splice(0,1)}}function i(e,t){e.call&&(e={success:e}),t.length?(e.error||n)(t):(e.success||n)(e)}function o(e,t,r,c){var i,s,u=document,f=r.async,a=(r.numRetries||0)+1,h=r.before||n;c=c||0,/(^css!|\.css$)/.test(e)?(i=!0,(s=u.createElement("link")).rel="stylesheet",s.href=e.replace(/^css!/,"")):((s=u.createElement("script")).src=e,s.async=void 0===f||f),s.onload=s.onerror=s.onbeforeload=function(n){var u=n.type[0];if(i&&"hideFocus"in s)try{s.sheet.cssText.length||(u="e")}catch(n){u="e"}if("e"==u&&(c+=1)<a)return o(e,t,r,c);t(e,u,n.defaultPrevented)},!1!==h(e,s)&&u.head.appendChild(s)}function s(n,t,r){var s,u;if(t&&t.trim&&(s=t),u=(s?r:t)||{},s){if(s in e)throw"LoadJS";e[s]=!0}!function(n,e,t){var r,c,i=(n=n.push?n:[n]).length,s=i,u=[];for(r=function(n,t,r){if("e"==t&&u.push(n),"b"==t){if(!r)return;u.push(n)}--i||e(u)},c=0;c<s;c++)o(n[c],r,t)}(n,function(n){i(u,n),c(s,n)},u)}return s.ready=function(n,e){return function(n,e){var c,i,o,s=[],u=(n=n.push?n:[n]).length,f=u;for(c=function(n,t){t.length&&s.push(n),--f||e(s)};u--;)i=n[u],(o=t[i])?c(i,o):(r[i]=r[i]||[]).push(c)}(n,function(n){i(e,n)}),s},s.done=function(n){c(n,[])},s.reset=function(){e={},t={},r={}},s.isDefined=function(n){return n in e},s}(); \ No newline at end of file +loadjs=function(){var a=function(){},i={},u={},f={};function o(n,e){if(n){var t=f[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function s(n,e){n.call&&(n={success:n}),e.length?(n.error||a)(e):(n.success||a)(n)}function h(t,r,c,i){var o,s,n=document,e=c.async,u=(c.numRetries||0)+1,f=c.before||a;i=i||0,/(^css!|\.css$)/.test(t)?(o=!0,(s=n.createElement("link")).rel="stylesheet",s.href=t.replace(/^css!/,"")):((s=n.createElement("script")).src=t,s.async=void 0===e||e),!(s.onload=s.onerror=s.onbeforeload=function(n){var e=n.type[0];if(o&&"hideFocus"in s)try{s.sheet.cssText.length||(e="e")}catch(n){e="e"}if("e"==e&&(i+=1)<u)return h(t,r,c,i);r(t,e,n.defaultPrevented)})!==f(t,s)&&n.head.appendChild(s)}function t(n,e,t){var r,c;if(e&&e.trim&&(r=e),c=(r?t:e)||{},r){if(r in i)throw"LoadJS";i[r]=!0}!function(n,r,e){var t,c,i=(n=n.push?n:[n]).length,o=i,s=[];for(t=function(n,e,t){if("e"==e&&s.push(n),"b"==e){if(!t)return;s.push(n)}--i||r(s)},c=0;c<o;c++)h(n[c],t,e)}(n,function(n){s(c,n),o(r,n)},c)}return t.ready=function(n,e){return function(n,t){n=n.push?n:[n];var e,r,c,i=[],o=n.length,s=o;for(e=function(n,e){e.length&&i.push(n),--s||t(i)};o--;)r=n[o],(c=u[r])?e(r,c):(f[r]=f[r]||[]).push(e)}(n,function(n){s(e,n)}),t},t.done=function(n){o(n,[])},t.reset=function(){i={},u={},f={}},t.isDefined=function(n){return n in i},t}(); \ No newline at end of file
1
fixed error in README example
1
.js
min
mit
muicss/loadjs
10067080
<NME> loadjs.min.js <BEF> loadjs=function(){var n=function(){},e={},t={},r={};function c(n,e){if(n){var c=r[n];if(t[n]=e,c)for(;c.length;)c[0](n,e),c.splice(0,1)}}function i(e,t){e.call&&(e={success:e}),t.length?(e.error||n)(t):(e.success||n)(e)}function o(e,t,r,c){var i,s,u=document,f=r.async,a=(r.numRetries||0)+1,h=r.before||n;c=c||0,/(^css!|\.css$)/.test(e)?(i=!0,(s=u.createElement("link")).rel="stylesheet",s.href=e.replace(/^css!/,"")):((s=u.createElement("script")).src=e,s.async=void 0===f||f),s.onload=s.onerror=s.onbeforeload=function(n){var u=n.type[0];if(i&&"hideFocus"in s)try{s.sheet.cssText.length||(u="e")}catch(n){u="e"}if("e"==u&&(c+=1)<a)return o(e,t,r,c);t(e,u,n.defaultPrevented)},!1!==h(e,s)&&u.head.appendChild(s)}function s(n,t,r){var s,u;if(t&&t.trim&&(s=t),u=(s?r:t)||{},s){if(s in e)throw"LoadJS";e[s]=!0}!function(n,e,t){var r,c,i=(n=n.push?n:[n]).length,s=i,u=[];for(r=function(n,t,r){if("e"==t&&u.push(n),"b"==t){if(!r)return;u.push(n)}--i||e(u)},c=0;c<s;c++)o(n[c],r,t)}(n,function(n){i(u,n),c(s,n)},u)}return s.ready=function(n,e){return function(n,e){var c,i,o,s=[],u=(n=n.push?n:[n]).length,f=u;for(c=function(n,t){t.length&&s.push(n),--f||e(s)};u--;)i=n[u],(o=t[i])?c(i,o):(r[i]=r[i]||[]).push(c)}(n,function(n){i(e,n)}),s},s.done=function(n){c(n,[])},s.reset=function(){e={},t={},r={}},s.isDefined=function(n){return n in e},s}(); <MSG> fixed error in README example <DFF> @@ -1,1 +1,1 @@ -loadjs=function(){var n=function(){},e={},t={},r={};function c(n,e){if(n){var c=r[n];if(t[n]=e,c)for(;c.length;)c[0](n,e),c.splice(0,1)}}function i(e,t){e.call&&(e={success:e}),t.length?(e.error||n)(t):(e.success||n)(e)}function o(e,t,r,c){var i,s,u=document,f=r.async,a=(r.numRetries||0)+1,h=r.before||n;c=c||0,/(^css!|\.css$)/.test(e)?(i=!0,(s=u.createElement("link")).rel="stylesheet",s.href=e.replace(/^css!/,"")):((s=u.createElement("script")).src=e,s.async=void 0===f||f),s.onload=s.onerror=s.onbeforeload=function(n){var u=n.type[0];if(i&&"hideFocus"in s)try{s.sheet.cssText.length||(u="e")}catch(n){u="e"}if("e"==u&&(c+=1)<a)return o(e,t,r,c);t(e,u,n.defaultPrevented)},!1!==h(e,s)&&u.head.appendChild(s)}function s(n,t,r){var s,u;if(t&&t.trim&&(s=t),u=(s?r:t)||{},s){if(s in e)throw"LoadJS";e[s]=!0}!function(n,e,t){var r,c,i=(n=n.push?n:[n]).length,s=i,u=[];for(r=function(n,t,r){if("e"==t&&u.push(n),"b"==t){if(!r)return;u.push(n)}--i||e(u)},c=0;c<s;c++)o(n[c],r,t)}(n,function(n){i(u,n),c(s,n)},u)}return s.ready=function(n,e){return function(n,e){var c,i,o,s=[],u=(n=n.push?n:[n]).length,f=u;for(c=function(n,t){t.length&&s.push(n),--f||e(s)};u--;)i=n[u],(o=t[i])?c(i,o):(r[i]=r[i]||[]).push(c)}(n,function(n){i(e,n)}),s},s.done=function(n){c(n,[])},s.reset=function(){e={},t={},r={}},s.isDefined=function(n){return n in e},s}(); \ No newline at end of file +loadjs=function(){var a=function(){},i={},u={},f={};function o(n,e){if(n){var t=f[n];if(u[n]=e,t)for(;t.length;)t[0](n,e),t.splice(0,1)}}function s(n,e){n.call&&(n={success:n}),e.length?(n.error||a)(e):(n.success||a)(n)}function h(t,r,c,i){var o,s,n=document,e=c.async,u=(c.numRetries||0)+1,f=c.before||a;i=i||0,/(^css!|\.css$)/.test(t)?(o=!0,(s=n.createElement("link")).rel="stylesheet",s.href=t.replace(/^css!/,"")):((s=n.createElement("script")).src=t,s.async=void 0===e||e),!(s.onload=s.onerror=s.onbeforeload=function(n){var e=n.type[0];if(o&&"hideFocus"in s)try{s.sheet.cssText.length||(e="e")}catch(n){e="e"}if("e"==e&&(i+=1)<u)return h(t,r,c,i);r(t,e,n.defaultPrevented)})!==f(t,s)&&n.head.appendChild(s)}function t(n,e,t){var r,c;if(e&&e.trim&&(r=e),c=(r?t:e)||{},r){if(r in i)throw"LoadJS";i[r]=!0}!function(n,r,e){var t,c,i=(n=n.push?n:[n]).length,o=i,s=[];for(t=function(n,e,t){if("e"==e&&s.push(n),"b"==e){if(!t)return;s.push(n)}--i||r(s)},c=0;c<o;c++)h(n[c],t,e)}(n,function(n){s(c,n),o(r,n)},c)}return t.ready=function(n,e){return function(n,t){n=n.push?n:[n];var e,r,c,i=[],o=n.length,s=o;for(e=function(n,e){e.length&&i.push(n),--s||t(i)};o--;)r=n[o],(c=u[r])?e(r,c):(f[r]=f[r]||[]).push(e)}(n,function(n){s(e,n)}),t},t.done=function(n){o(n,[])},t.reset=function(){i={},u={},f={}},t.isDefined=function(n){return n in i},t}(); \ No newline at end of file
1
fixed error in README example
1
.js
min
mit
muicss/loadjs
10067081
<NME> loadjs.js <BEF> loadjs = (function () { /** * Global dependencies. * @global {Object} document - DOM */ var devnull = function() {}, bundleIdCache = {}, bundleResultCache = {}, bundleCallbackQueue = {}; /** * Subscribe to bundle load event. * @param {string[]} bundleIds - Bundle ids * @param {Function} callbackFn - The callback function */ function subscribe(bundleIds, callbackFn) { // listify bundleIds = bundleIds.push ? bundleIds : [bundleIds]; var depsNotFound = [], i = bundleIds.length, numWaiting = i, fn, bundleId, r, q; // define callback function fn = function (bundleId, pathsNotFound) { if (pathsNotFound.length) depsNotFound.push(bundleId); numWaiting--; if (!numWaiting) callbackFn(depsNotFound); }; // register callback while (i--) { bundleId = bundleIds[i]; // execute callback if in result cache r = bundleResultCache[bundleId]; if (r) { fn(bundleId, r); continue; } // add to callback queue q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || []; q.push(fn); } } /** * Publish bundle load event. * @param {string} bundleId - Bundle id * @param {string[]} pathsNotFound - List of files not found */ function publish(bundleId, pathsNotFound) { // exit if id isn't defined if (!bundleId) return; var q = bundleCallbackQueue[bundleId]; // cache result bundleResultCache[bundleId] = pathsNotFound; // exit if queue is empty if (!q) return; // empty callback queue while (q.length) { q[0](bundleId, pathsNotFound); q.splice(0, 1); } } /** * Execute callbacks. * @param {Object or Function} args - The callback args * @param {string[]} depsNotFound - List of dependencies not found */ function executeCallbacks(args, depsNotFound) { // accept function as argument if (args.call) args = {success: args}; // success and error callbacks if (depsNotFound.length) (args.error || devnull)(depsNotFound); else (args.success || devnull)(args); } /** * Load individual file. * @param {string} path - The file path * @param {Function} callbackFn - The callback function */ function loadFile(path, callbackFn, args, numTries) { var doc = document, async = args.async, maxTries = (args.numRetries || 0) + 1, beforeCallbackFn = args.before || devnull, pathname = path.replace(/[\?|#].*$/, ''), pathStripped = path.replace(/^(css|img)!/, ''), isLegacyIECss, e; numTries = numTries || 0; if (/(^css!|\.css$)/.test(pathname)) { // css e = doc.createElement('link'); e.rel = 'stylesheet'; e.href = pathStripped; // tag IE9+ isLegacyIECss = 'hideFocus' in e; // use preload in IE Edge (to detect load errors) if (isLegacyIECss && e.relList) { isLegacyIECss = 0; e.rel = 'preload'; e.as = 'style'; } } else if (/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(pathname)) { // image e = doc.createElement('img'); e.src = pathStripped; } else { // javascript e = doc.createElement('script'); e.src = path; e.async = async === undefined ? true : async; } e.onload = e.onerror = e.onbeforeload = function (ev) { var result = ev.type[0]; // treat empty stylesheets as failures to get around lack of onerror // support in IE9-11 if (isLegacyIECss) { try { if (!e.sheet.cssText.length) result = 'e'; } catch (x) { // sheets objects created from load errors don't allow access to // `cssText` (unless error is Code:18 SecurityError) if (x.code != 18) result = 'e'; } } // start downloads loadScripts(paths, function(pathsNotFound) { if (pathsNotFound.length) (failFn || devnull)(pathsNotFound); else (successFn || devnull)(); // exit function and try again if (numTries < maxTries) { return loadFile(path, callbackFn, args, numTries); } } else if (e.rel == 'preload' && e.as == 'style') { // activate preloaded stylesheets return e.rel = 'stylesheet'; // jshint ignore:line } // execute callback callbackFn(path, result, ev.defaultPrevented); }; // add to document (unless callback returns `false`) if (beforeCallbackFn(path, e) !== false) doc.head.appendChild(e); } /** * Load multiple files. * @param {string[]} paths - The file paths * @param {Function} callbackFn - The callback function */ function loadFiles(paths, callbackFn, args) { // listify paths paths = paths.push ? paths : [paths]; var numWaiting = paths.length, x = numWaiting, pathsNotFound = [], fn, i; // define callback function fn = function(path, result, defaultPrevented) { // handle error if (result == 'e') pathsNotFound.push(path); // handle beforeload event. If defaultPrevented then that means the load // will be blocked (ex. Ghostery/ABP on Safari) if (result == 'b') { if (defaultPrevented) pathsNotFound.push(path); else return; } numWaiting--; if (!numWaiting) callbackFn(pathsNotFound); }; // load scripts for (i=0; i < x; i++) loadFile(paths[i], fn, args); } /** * Initiate script load and register bundle. * @param {(string|string[])} paths - The file paths * @param {(string|Function|Object)} [arg1] - The (1) bundleId or (2) success * callback or (3) object literal with success/error arguments, numRetries, * etc. * @param {(Function|Object)} [arg2] - The (1) success callback or (2) object * literal with success/error arguments, numRetries, etc. */ function loadjs(paths, arg1, arg2) { var bundleId, args; // bundleId (if string) if (arg1 && arg1.trim) bundleId = arg1; // args (default is {}) args = (bundleId ? arg2 : arg1) || {}; // throw error if bundle is already defined if (bundleId) { if (bundleId in bundleIdCache) { throw "LoadJS"; } else { bundleIdCache[bundleId] = true; } } function loadFn(resolve, reject) { loadFiles(paths, function (pathsNotFound) { // execute callbacks executeCallbacks(args, pathsNotFound); // resolve Promise if (resolve) { executeCallbacks({success: resolve, error: reject}, pathsNotFound); } // publish bundle load event publish(bundleId, pathsNotFound); }, args); } if (args.returnPromise) return new Promise(loadFn); else loadFn(); } /** * Execute callbacks when dependencies have been satisfied. * @param {(string|string[])} deps - List of bundle ids * @param {Object} args - success/error arguments */ loadjs.ready = function ready(deps, args) { // subscribe to bundle load event subscribe(deps, function (depsNotFound) { // execute callbacks executeCallbacks(args, depsNotFound); }); return loadjs; }; /** * Manually satisfy bundle dependencies. * @param {string} bundleId - The bundle id */ loadjs.done = function done(bundleId) { publish(bundleId, []); }; /** * Reset loadjs dependencies statuses */ loadjs.reset = function reset() { bundleIdCache = {}; bundleResultCache = {}; bundleCallbackQueue = {}; }; /** * Determine if bundle has already been defined * @param String} bundleId - The bundle id */ loadjs.isDefined = function isDefined(bundleId) { return bundleId in bundleIdCache; }; // export return loadjs; })(); <MSG> build distribution files <DFF> @@ -151,7 +151,7 @@ } } - // start downloads + // load scripts loadScripts(paths, function(pathsNotFound) { if (pathsNotFound.length) (failFn || devnull)(pathsNotFound); else (successFn || devnull)();
1
build distribution files
1
.js
js
mit
muicss/loadjs
10067082
<NME> loadjs.js <BEF> loadjs = (function () { /** * Global dependencies. * @global {Object} document - DOM */ var devnull = function() {}, bundleIdCache = {}, bundleResultCache = {}, bundleCallbackQueue = {}; /** * Subscribe to bundle load event. * @param {string[]} bundleIds - Bundle ids * @param {Function} callbackFn - The callback function */ function subscribe(bundleIds, callbackFn) { // listify bundleIds = bundleIds.push ? bundleIds : [bundleIds]; var depsNotFound = [], i = bundleIds.length, numWaiting = i, fn, bundleId, r, q; // define callback function fn = function (bundleId, pathsNotFound) { if (pathsNotFound.length) depsNotFound.push(bundleId); numWaiting--; if (!numWaiting) callbackFn(depsNotFound); }; // register callback while (i--) { bundleId = bundleIds[i]; // execute callback if in result cache r = bundleResultCache[bundleId]; if (r) { fn(bundleId, r); continue; } // add to callback queue q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || []; q.push(fn); } } /** * Publish bundle load event. * @param {string} bundleId - Bundle id * @param {string[]} pathsNotFound - List of files not found */ function publish(bundleId, pathsNotFound) { // exit if id isn't defined if (!bundleId) return; var q = bundleCallbackQueue[bundleId]; // cache result bundleResultCache[bundleId] = pathsNotFound; // exit if queue is empty if (!q) return; // empty callback queue while (q.length) { q[0](bundleId, pathsNotFound); q.splice(0, 1); } } /** * Execute callbacks. * @param {Object or Function} args - The callback args * @param {string[]} depsNotFound - List of dependencies not found */ function executeCallbacks(args, depsNotFound) { // accept function as argument if (args.call) args = {success: args}; // success and error callbacks if (depsNotFound.length) (args.error || devnull)(depsNotFound); else (args.success || devnull)(args); } /** * Load individual file. * @param {string} path - The file path * @param {Function} callbackFn - The callback function */ function loadFile(path, callbackFn, args, numTries) { var doc = document, async = args.async, maxTries = (args.numRetries || 0) + 1, beforeCallbackFn = args.before || devnull, pathname = path.replace(/[\?|#].*$/, ''), pathStripped = path.replace(/^(css|img)!/, ''), isLegacyIECss, e; numTries = numTries || 0; if (/(^css!|\.css$)/.test(pathname)) { // css e = doc.createElement('link'); e.rel = 'stylesheet'; e.href = pathStripped; // tag IE9+ isLegacyIECss = 'hideFocus' in e; // use preload in IE Edge (to detect load errors) if (isLegacyIECss && e.relList) { isLegacyIECss = 0; e.rel = 'preload'; e.as = 'style'; } } else if (/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(pathname)) { // image e = doc.createElement('img'); e.src = pathStripped; } else { // javascript e = doc.createElement('script'); e.src = path; e.async = async === undefined ? true : async; } e.onload = e.onerror = e.onbeforeload = function (ev) { var result = ev.type[0]; // treat empty stylesheets as failures to get around lack of onerror // support in IE9-11 if (isLegacyIECss) { try { if (!e.sheet.cssText.length) result = 'e'; } catch (x) { // sheets objects created from load errors don't allow access to // `cssText` (unless error is Code:18 SecurityError) if (x.code != 18) result = 'e'; } } // start downloads loadScripts(paths, function(pathsNotFound) { if (pathsNotFound.length) (failFn || devnull)(pathsNotFound); else (successFn || devnull)(); // exit function and try again if (numTries < maxTries) { return loadFile(path, callbackFn, args, numTries); } } else if (e.rel == 'preload' && e.as == 'style') { // activate preloaded stylesheets return e.rel = 'stylesheet'; // jshint ignore:line } // execute callback callbackFn(path, result, ev.defaultPrevented); }; // add to document (unless callback returns `false`) if (beforeCallbackFn(path, e) !== false) doc.head.appendChild(e); } /** * Load multiple files. * @param {string[]} paths - The file paths * @param {Function} callbackFn - The callback function */ function loadFiles(paths, callbackFn, args) { // listify paths paths = paths.push ? paths : [paths]; var numWaiting = paths.length, x = numWaiting, pathsNotFound = [], fn, i; // define callback function fn = function(path, result, defaultPrevented) { // handle error if (result == 'e') pathsNotFound.push(path); // handle beforeload event. If defaultPrevented then that means the load // will be blocked (ex. Ghostery/ABP on Safari) if (result == 'b') { if (defaultPrevented) pathsNotFound.push(path); else return; } numWaiting--; if (!numWaiting) callbackFn(pathsNotFound); }; // load scripts for (i=0; i < x; i++) loadFile(paths[i], fn, args); } /** * Initiate script load and register bundle. * @param {(string|string[])} paths - The file paths * @param {(string|Function|Object)} [arg1] - The (1) bundleId or (2) success * callback or (3) object literal with success/error arguments, numRetries, * etc. * @param {(Function|Object)} [arg2] - The (1) success callback or (2) object * literal with success/error arguments, numRetries, etc. */ function loadjs(paths, arg1, arg2) { var bundleId, args; // bundleId (if string) if (arg1 && arg1.trim) bundleId = arg1; // args (default is {}) args = (bundleId ? arg2 : arg1) || {}; // throw error if bundle is already defined if (bundleId) { if (bundleId in bundleIdCache) { throw "LoadJS"; } else { bundleIdCache[bundleId] = true; } } function loadFn(resolve, reject) { loadFiles(paths, function (pathsNotFound) { // execute callbacks executeCallbacks(args, pathsNotFound); // resolve Promise if (resolve) { executeCallbacks({success: resolve, error: reject}, pathsNotFound); } // publish bundle load event publish(bundleId, pathsNotFound); }, args); } if (args.returnPromise) return new Promise(loadFn); else loadFn(); } /** * Execute callbacks when dependencies have been satisfied. * @param {(string|string[])} deps - List of bundle ids * @param {Object} args - success/error arguments */ loadjs.ready = function ready(deps, args) { // subscribe to bundle load event subscribe(deps, function (depsNotFound) { // execute callbacks executeCallbacks(args, depsNotFound); }); return loadjs; }; /** * Manually satisfy bundle dependencies. * @param {string} bundleId - The bundle id */ loadjs.done = function done(bundleId) { publish(bundleId, []); }; /** * Reset loadjs dependencies statuses */ loadjs.reset = function reset() { bundleIdCache = {}; bundleResultCache = {}; bundleCallbackQueue = {}; }; /** * Determine if bundle has already been defined * @param String} bundleId - The bundle id */ loadjs.isDefined = function isDefined(bundleId) { return bundleId in bundleIdCache; }; // export return loadjs; })(); <MSG> build distribution files <DFF> @@ -151,7 +151,7 @@ } } - // start downloads + // load scripts loadScripts(paths, function(pathsNotFound) { if (pathsNotFound.length) (failFn || devnull)(pathsNotFound); else (successFn || devnull)();
1
build distribution files
1
.js
js
mit
muicss/loadjs
10067083
<NME> npm-debug.log <BEF> ADDFILE <MSG> Serverside example with API changes <DFF> @@ -0,0 +1,2410 @@ +0 info it worked if it ends with ok +1 verbose cli [ 'node', '/usr/local/bin/npm', 'install', '-g', 'browserify' ] +2 info using [email protected] +3 info using [email protected] +4 verbose read json /usr/local/lib/package.json +5 verbose read json /usr/local/lib/package.json +6 verbose cache add [ 'browserify', null ] +7 verbose cache add name=undefined spec="browserify" args=["browserify",null] +8 verbose parsed url { pathname: 'browserify', +8 verbose parsed url path: 'browserify', +8 verbose parsed url href: 'browserify' } +9 silly lockFile 84c1c54e-browserify browserify +10 verbose lock browserify /Users/wilsonpage/.npm/84c1c54e-browserify.lock +11 silly lockFile 84c1c54e-browserify browserify +12 verbose addNamed [ 'browserify', '' ] +13 verbose addNamed [ null, '' ] +14 silly lockFile 80140245-browserify browserify@ +15 verbose lock browserify@ /Users/wilsonpage/.npm/80140245-browserify.lock +16 silly addNameRange { name: 'browserify', range: '', hasData: false } +17 verbose url raw browserify +18 verbose url resolving [ 'https://registry.npmjs.org/', './browserify' ] +19 verbose url resolved https://registry.npmjs.org/browserify +20 info trying registry request attempt 1 at 16:13:25 +21 verbose etag "899R1W8XNWSIDYL830UTYNK3T" +22 http GET https://registry.npmjs.org/browserify +23 http 304 https://registry.npmjs.org/browserify +24 silly registry.get cb [ 304, +24 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +24 silly registry.get etag: '"899R1W8XNWSIDYL830UTYNK3T"', +24 silly registry.get date: 'Tue, 29 Jan 2013 16:11:45 GMT', +24 silly registry.get 'content-length': '0' } ] +25 verbose etag browserify from cache +26 silly addNameRange number 2 { name: 'browserify', range: '', hasData: true } +27 silly addNameRange versions [ 'browserify', +27 silly addNameRange [ '0.0.1', +27 silly addNameRange '0.0.2', +27 silly addNameRange '0.0.3', +27 silly addNameRange '0.0.4', +27 silly addNameRange '0.0.5', +27 silly addNameRange '0.1.0', +27 silly addNameRange '0.1.1', +27 silly addNameRange '0.1.2', +27 silly addNameRange '0.1.3', +27 silly addNameRange '0.1.4', +27 silly addNameRange '0.1.5', +27 silly addNameRange '0.2.0', +27 silly addNameRange '0.2.1', +27 silly addNameRange '0.2.2', +27 silly addNameRange '0.2.3', +27 silly addNameRange '0.2.4', +27 silly addNameRange '0.2.5', +27 silly addNameRange '0.2.6', +27 silly addNameRange '0.2.7', +27 silly addNameRange '0.2.8', +27 silly addNameRange '0.2.9', +27 silly addNameRange '0.2.10', +27 silly addNameRange '0.2.11', +27 silly addNameRange '0.3.0', +27 silly addNameRange '0.3.1', +27 silly addNameRange '0.3.2', +27 silly addNameRange '0.3.3', +27 silly addNameRange '0.3.4', +27 silly addNameRange '0.3.5', +27 silly addNameRange '0.3.6', +27 silly addNameRange '0.3.7', +27 silly addNameRange '0.4.0', +27 silly addNameRange '0.4.1', +27 silly addNameRange '0.4.2', +27 silly addNameRange '0.4.3', +27 silly addNameRange '0.4.4', +27 silly addNameRange '0.4.5', +27 silly addNameRange '0.4.6', +27 silly addNameRange '0.4.7', +27 silly addNameRange '0.4.8', +27 silly addNameRange '0.4.9', +27 silly addNameRange '0.4.10', +27 silly addNameRange '0.4.11', +27 silly addNameRange '0.4.12', +27 silly addNameRange '0.4.13', +27 silly addNameRange '0.4.14', +27 silly addNameRange '0.4.15', +27 silly addNameRange '0.5.0', +27 silly addNameRange '0.5.1', +27 silly addNameRange '0.5.2', +27 silly addNameRange '1.0.0', +27 silly addNameRange '1.1.0', +27 silly addNameRange '1.1.1', +27 silly addNameRange '1.1.2', +27 silly addNameRange '1.1.3', +27 silly addNameRange '1.1.4', +27 silly addNameRange '1.2.0', +27 silly addNameRange '1.2.1', +27 silly addNameRange '1.2.2', +27 silly addNameRange '1.2.3', +27 silly addNameRange '1.2.4', +27 silly addNameRange '1.2.5', +27 silly addNameRange '1.2.6', +27 silly addNameRange '1.2.7', +27 silly addNameRange '1.2.8', +27 silly addNameRange '1.2.9', +27 silly addNameRange '1.3.0', +27 silly addNameRange '1.4.0', +27 silly addNameRange '1.4.1', +27 silly addNameRange '1.4.2', +27 silly addNameRange '1.4.3', +27 silly addNameRange '1.4.4', +27 silly addNameRange '1.4.5', +27 silly addNameRange '1.4.6', +27 silly addNameRange '1.4.7', +27 silly addNameRange '1.4.8', +27 silly addNameRange '1.5.0', +27 silly addNameRange '1.6.0', +27 silly addNameRange '1.6.1', +27 silly addNameRange '1.7.0', +27 silly addNameRange '1.7.1', +27 silly addNameRange '1.7.2', +27 silly addNameRange '1.7.3', +27 silly addNameRange '1.7.4', +27 silly addNameRange '1.7.5', +27 silly addNameRange '1.7.6', +27 silly addNameRange '1.7.7', +27 silly addNameRange '1.8.0', +27 silly addNameRange '1.8.1', +27 silly addNameRange '1.8.2', +27 silly addNameRange '1.8.3', +27 silly addNameRange '1.9.0', +27 silly addNameRange '1.9.1', +27 silly addNameRange '1.9.2', +27 silly addNameRange '1.9.3', +27 silly addNameRange '1.9.4', +27 silly addNameRange '1.10.0', +27 silly addNameRange '1.10.1', +27 silly addNameRange '1.10.2', +27 silly addNameRange '1.10.3', +27 silly addNameRange '1.10.4', +27 silly addNameRange '1.10.5', +27 silly addNameRange '1.10.6', +27 silly addNameRange '1.10.7', +27 silly addNameRange '1.10.8', +27 silly addNameRange '1.10.9', +27 silly addNameRange '1.10.11', +27 silly addNameRange '1.10.12', +27 silly addNameRange '1.10.13', +27 silly addNameRange '1.10.14', +27 silly addNameRange '1.10.15', +27 silly addNameRange '1.10.16', +27 silly addNameRange '1.10.17', +27 silly addNameRange '1.11.0', +27 silly addNameRange '1.11.1', +27 silly addNameRange '1.12.0', +27 silly addNameRange '1.12.1', +27 silly addNameRange '1.12.2', +27 silly addNameRange '1.12.3', +27 silly addNameRange '1.13.0', +27 silly addNameRange '1.13.1', +27 silly addNameRange '1.13.2', +27 silly addNameRange '1.13.3', +27 silly addNameRange '1.13.4', +27 silly addNameRange '1.13.5', +27 silly addNameRange '1.13.6', +27 silly addNameRange '1.13.8', +27 silly addNameRange '1.13.9', +27 silly addNameRange '1.13.10', +27 silly addNameRange '1.14.0', +27 silly addNameRange '1.14.1', +27 silly addNameRange '1.14.2', +27 silly addNameRange '1.14.3', +27 silly addNameRange '1.14.4', +27 silly addNameRange '1.14.5', +27 silly addNameRange '1.15.0', +27 silly addNameRange '1.15.1', +27 silly addNameRange '1.15.2', +27 silly addNameRange '1.15.3', +27 silly addNameRange '1.15.4', +27 silly addNameRange '1.15.5', +27 silly addNameRange '1.15.6', +27 silly addNameRange '1.16.0', +27 silly addNameRange '1.16.1', +27 silly addNameRange '1.16.2', +27 silly addNameRange '1.16.3', +27 silly addNameRange '1.16.4', +27 silly addNameRange '1.16.5', +27 silly addNameRange '1.16.6', +27 silly addNameRange '1.16.7', +27 silly addNameRange '1.16.8', +27 silly addNameRange '1.17.0', +27 silly addNameRange '1.17.1', +27 silly addNameRange '1.17.2', +27 silly addNameRange '1.17.3' ] ] +28 verbose addNamed [ 'browserify', '1.17.3' ] +29 verbose addNamed [ '1.17.3', '1.17.3' ] +30 silly lockFile 2c130a86-browserify-1-17-3 [email protected] +31 verbose lock [email protected] /Users/wilsonpage/.npm/2c130a86-browserify-1-17-3.lock +32 verbose read json /Users/wilsonpage/.npm/browserify/1.17.3/package/package.json +33 silly lockFile 2c130a86-browserify-1-17-3 [email protected] +34 silly lockFile 80140245-browserify browserify@ +35 silly resolved [ { name: 'browserify', +35 silly resolved version: '1.17.3', +35 silly resolved description: 'browser-side require() the node way', +35 silly resolved main: 'index.js', +35 silly resolved bin: { browserify: 'bin/cmd.js' }, +35 silly resolved directories: { example: 'example', test: 'test' }, +35 silly resolved repository: +35 silly resolved { type: 'git', +35 silly resolved url: 'http://github.com/substack/node-browserify.git' }, +35 silly resolved keywords: +35 silly resolved [ 'browser', +35 silly resolved 'require', +35 silly resolved 'middleware', +35 silly resolved 'bundle', +35 silly resolved 'npm', +35 silly resolved 'coffee', +35 silly resolved 'javascript' ], +35 silly resolved dependencies: +35 silly resolved { detective: '~0.2.0', +35 silly resolved 'buffer-browserify': '~0.0.1', +35 silly resolved 'console-browserify': '~0.1.0', +35 silly resolved deputy: '~0.0.3', +35 silly resolved 'syntax-error': '~0.0.0', +35 silly resolved resolve: '~0.2.0', +35 silly resolved nub: '~0.0.0', +35 silly resolved commondir: '~0.0.1', +35 silly resolved 'coffee-script': '1.x.x', +35 silly resolved optimist: '~0.3.4', +35 silly resolved 'http-browserify': '~0.1.1', +35 silly resolved 'vm-browserify': '~0.0.0', +35 silly resolved 'crypto-browserify': '~0' }, +35 silly resolved devDependencies: +35 silly resolved { tap: '~0.2.5', +35 silly resolved connect: '1.8.5', +35 silly resolved hashish: '>=0.0.2 <0.1', +35 silly resolved traverse: '>=0.3.8 <0.4', +35 silly resolved backbone: '~0.9.2', +35 silly resolved dnode: '~0.9.11', +35 silly resolved jade: '0.20.0', +35 silly resolved seq: '0.3.3', +35 silly resolved 'jquery-browserify': '*', +35 silly resolved lazy: '1.0.x', +35 silly resolved ecstatic: '~0.1.4', +35 silly resolved mkdirp: '~0.3.3' }, +35 silly resolved author: +35 silly resolved { name: 'James Halliday', +35 silly resolved email: '[email protected]', +35 silly resolved url: 'http://substack.net' }, +35 silly resolved scripts: { test: 'node node_modules/tap/bin/tap.js test/*.js' }, +35 silly resolved license: 'MIT/X11', +35 silly resolved engine: { node: '>=0.6.0' }, +35 silly resolved readme: 'browserify\n==========\n\nMake node-style require() work in the browser with a server-side build step,\nas if by magic!\n\n[![build status](https://secure.travis-ci.org/substack/node-browserify.png)](http://travis-ci.org/substack/node-browserify)\n\n![browserify!](http://substack.net/images/browserify/browserify.png)\n\nexample\n=======\n\nJust write an `entry.js` to start with some `require()`s in it:\n\n````javascript\n// use relative requires\nvar foo = require(\'./foo\');\nvar bar = require(\'../lib/bar\');\n\n// or use modules installed by npm into node_modules/\nvar gamma = require(\'gamma\');\n\nvar elem = document.getElementById(\'result\');\nvar x = foo(100) + bar(\'baz\');\nelem.textContent = gamma(x);\n````\n\nNow just use the `browserify` command to build a bundle starting at `entry.js`:\n\n```\n$ browserify entry.js -o bundle.js\n```\n\nAll of the modules that `entry.js` needs are included in the final bundle from a\nrecursive walk using [detective](https://github.com/substack/node-detective).\n\nTo use the bundle, just toss a `<script src="bundle.js"></script>` into your\nhtml!\n\nusage\n=====\n\n````\nUsage: browserify [entry files] {OPTIONS}\n\nOptions:\n --outfile, -o Write the browserify bundle to this file.\n If unspecified, browserify prints to stdout. \n --require, -r A module name or file to bundle.require()\n Optionally use a colon separator to set the target. \n --entry, -e An entry point of your app \n --exports Export these core objects, comma-separated list\n with any of: require, process. If unspecified, the\n export behavior will be inferred.\n \n --ignore, -i Ignore a file \n --alias, -a Register an alias with a colon separator: "to:from"\n Example: --alias \'jquery:jquery-browserify\' \n --cache, -c Turn on caching at $HOME/.config/browserling/cache.json or use\n a file for caching.\n [default: true]\n --debug, -d Switch on debugging mode with //@ sourceURL=...s. [boolean]\n --plugin, -p Use a plugin.\n Example: --plugin aliasify \n --prelude Include the code that defines require() in this bundle.\n [boolean] [default: true]\n --watch, -w Watch for changes. The script will stay open and write updates\n to the output every time any of the bundled files change.\n This option only works in tandem with -o. \n --verbose, -v Write out how many bytes were written in -o mode. This is\n especially useful with --watch. \n --help, -h Show this message \n\n````\n\ncompatibility\n=============\n\nMany [npm](http://npmjs.org) modules that don\'t do IO will just work after being\nbrowserified. Others take more work.\n\n[coffee script](http://coffeescript.org/) should pretty much just work.\nJust do `browserify entry.coffee` or `require(\'./foo.coffee\')`.\n\nMany node built-in modules have been wrapped to work in the browser.\nAll you need to do is `require()` them like in node.\n\n* events\n* path\n* [vm](https://github.com/substack/vm-browserify)\n* [http](https://github.com/substack/http-browserify)\n* [crypto](https://github.com/dominictarr/crypto-browserify)\n* assert\n* url\n* buffer\n* buffer_ieee754\n* util\n* querystring\n* stream\n\nprocess\n-------\n\nBrowserify makes available a faux `process` object to modules with these\nattributes:\n\n* nextTick(fn) - uses [the postMessage trick](http://dbaron.org/log/20100309-faster-timeouts)\n for a faster `setTimeout(fn, 0)` if it can\n* title - set to \'browser\' for browser code, \'node\' in regular node code\n* browser - `true`, good for testing if you\'re in a browser or in node\n\nBy default the process object is only available inside of files wrapped by\nbrowserify. To expose it, use `--exports=process`\n\n__dirname\n---------\n\nThe faux directory name, scrubbed of true directory information so as not to\nexpose your filesystem organization.\n\n__filename\n----------\n\nThe faux file path, scrubbed of true path information so as not to expose your\nfilesystem organization.\n\npackage.json\n============\n\nIn order to resolve main files for projects, the package.json "main" field is\nread.\n\nIf a package.json has a "browserify" field, you can override the standard "main"\nbehavior with something special just for browsers.\n\nSee [dnode\'s\npackage.json](https://github.com/substack/dnode/blob/9e24b97cf2ce931fbf6d7beb3731086b46bca887/package.json#L40)\nfor an example of using the "browserify" field.\n\nmore\n====\n\n* [browserify recipes](https://github.com/substack/node-browserify/blob/master/doc/recipes.markdown#recipes)\n* [browserify api reference](https://github.com/substack/node-browserify/blob/master/doc/methods.markdown#methods)\n* [browserify cdn](http://browserify.nodejitsu.com/)\n\ninstall\n=======\n\nWith [npm](http://npmjs.org) do:\n\n```\nnpm install -g browserify\n```\n\ntest\n====\n\nTo run the node tests with tap, do:\n\n```\nnpm test\n```\n\nTo run the [testling](http://testling.com) tests,\ncreate a [browserling](http://browserling.com) account then:\n\n```\ncd testling\n./test.sh\n```\n', +35 silly resolved readmeFilename: 'README.markdown', +35 silly resolved _id: '[email protected]', +35 silly resolved _from: 'browserify@' } ] +36 info install [email protected] into /usr/local/lib +37 info installOne [email protected] +38 verbose from cache /Users/wilsonpage/.npm/browserify/1.17.3/package/package.json +39 info /usr/local/lib/node_modules/browserify unbuild +40 verbose read json /usr/local/lib/node_modules/browserify/package.json +41 verbose tar unpack /Users/wilsonpage/.npm/browserify/1.17.3/package.tgz +42 silly lockFile 361ec04d-ocal-lib-node-modules-browserify /usr/local/lib/node_modules/browserify +43 verbose lock /usr/local/lib/node_modules/browserify /Users/wilsonpage/.npm/361ec04d-ocal-lib-node-modules-browserify.lock +44 silly gunzTarPerm modes [ '755', '644' ] +45 silly gunzTarPerm extractEntry package.json +46 silly gunzTarPerm extractEntry LICENSE +47 silly gunzTarPerm extractEntry index.js +48 silly gunzTarPerm extractEntry doc/methods.markdown +49 silly gunzTarPerm extractEntry doc/recipes.markdown +50 silly gunzTarPerm extractEntry example/debug/browserify.js +51 silly gunzTarPerm extractEntry example/debug/server.js +52 silly gunzTarPerm extractEntry example/debug/build.sh +53 silly gunzTarPerm extractEntry example/debug/index.html +54 silly gunzTarPerm extractEntry example/debug/js/entry.js +55 silly gunzTarPerm extractEntry example/debug/js/thrower.js +56 silly gunzTarPerm extractEntry example/simple-build/browserify.js +57 silly gunzTarPerm extractEntry example/simple-build/server.js +58 silly gunzTarPerm extractEntry example/simple-build/build.sh +59 silly gunzTarPerm extractEntry example/simple-build/index.html +60 silly gunzTarPerm extractEntry example/simple-build/js/bar.js +61 silly gunzTarPerm extractEntry example/simple-build/js/entry.js +62 silly gunzTarPerm extractEntry example/simple-build/js/foo.js +63 silly gunzTarPerm extractEntry example/test/b.js +64 silly gunzTarPerm extractEntry example/test/bar.js +65 silly gunzTarPerm extractEntry example/test/foo.js +66 silly gunzTarPerm extractEntry example/test/m.js +67 silly gunzTarPerm extractEntry example/test/n.js +68 silly gunzTarPerm extractEntry example/using-http/bundle.js +69 silly gunzTarPerm extractEntry example/using-http/entry.js +70 silly gunzTarPerm extractEntry example/using-http/server.js +71 silly gunzTarPerm extractEntry example/using-http/index.html +72 silly gunzTarPerm extractEntry .travis.yml +73 silly gunzTarPerm extractEntry lib/watch.js +74 silly gunzTarPerm extractEntry lib/wrap.js +75 silly gunzTarPerm extractEntry lib/wrappers.js +76 silly gunzTarPerm extractEntry bin/cmd.js +77 silly gunzTarPerm extractEntry builtins/__browserify_process.js +78 silly gunzTarPerm extractEntry builtins/https.js +79 silly gunzTarPerm extractEntry builtins/net.js +80 silly gunzTarPerm extractEntry builtins/path.js +81 silly gunzTarPerm extractEntry builtins/fs.js +82 silly gunzTarPerm extractEntry builtins/stream.js +83 silly gunzTarPerm extractEntry builtins/string_decoder.js +84 silly gunzTarPerm extractEntry builtins/sys.js +85 silly gunzTarPerm extractEntry builtins/timers.js +86 silly gunzTarPerm extractEntry builtins/tls.js +87 silly gunzTarPerm extractEntry builtins/events.js +88 silly gunzTarPerm extractEntry builtins/tty.js +89 silly gunzTarPerm extractEntry builtins/child_process.js +90 silly gunzTarPerm extractEntry builtins/url.js +91 silly gunzTarPerm extractEntry builtins/assert.js +92 silly gunzTarPerm extractEntry builtins/util.js +93 silly gunzTarPerm extractEntry builtins/querystring.js +94 silly gunzTarPerm extractEntry README.markdown +95 silly gunzTarPerm extractEntry test/alias.js +96 silly gunzTarPerm extractEntry test/dnode.js +97 silly gunzTarPerm extractEntry test/subdep.js +98 silly gunzTarPerm extractEntry test/dollar.js +99 silly gunzTarPerm extractEntry test/crypto.js +100 silly gunzTarPerm extractEntry test/entry.js +101 silly gunzTarPerm extractEntry test/retarget.js +102 silly gunzTarPerm extractEntry test/error_code.js +103 silly gunzTarPerm extractEntry test/require_cache.js +104 silly gunzTarPerm extractEntry test/export.js +105 silly gunzTarPerm extractEntry test/comment.js +106 silly gunzTarPerm extractEntry test/multi_ignore.js +107 silly gunzTarPerm extractEntry test/util.js +108 silly gunzTarPerm extractEntry test/backbone.js +109 silly gunzTarPerm extractEntry test/coffee.js +110 silly gunzTarPerm extractEntry test/multi_entry.js +111 silly gunzTarPerm extractEntry test/watch.js +112 silly gunzTarPerm extractEntry test/global.js +113 silly gunzTarPerm extractEntry test/cache.js +114 silly gunzTarPerm extractEntry test/jade.js +115 silly gunzTarPerm extractEntry test/bundle.js +116 silly gunzTarPerm extractEntry test/module.js +117 silly gunzTarPerm extractEntry test/buffer.js +118 silly gunzTarPerm extractEntry test/json.js +119 silly gunzTarPerm extractEntry test/bin.js +120 silly gunzTarPerm extractEntry test/maxlisteners.js +121 silly gunzTarPerm extractEntry test/seq.js +122 silly gunzTarPerm extractEntry test/wrap.js +123 silly gunzTarPerm extractEntry test/field.js +124 silly gunzTarPerm extractEntry test/json/main.js +125 silly gunzTarPerm extractEntry test/json/beep.json +126 silly gunzTarPerm extractEntry test/global/main.js +127 silly gunzTarPerm extractEntry test/field/miss.js +128 silly gunzTarPerm extractEntry test/field/object.js +129 silly gunzTarPerm extractEntry test/field/string.js +130 silly gunzTarPerm extractEntry test/field/sub.js +131 silly gunzTarPerm extractEntry test/field/node_modules/z-miss/package.json +132 silly gunzTarPerm extractEntry test/field/node_modules/z-miss/browser.js +133 silly gunzTarPerm extractEntry test/field/node_modules/z-miss/main.js +134 silly gunzTarPerm extractEntry test/field/node_modules/z-object/package.json +135 silly gunzTarPerm extractEntry test/field/node_modules/z-object/browser.js +136 silly gunzTarPerm extractEntry test/field/node_modules/z-object/main.js +137 silly gunzTarPerm extractEntry test/field/node_modules/z-string/package.json +138 silly gunzTarPerm extractEntry test/field/node_modules/z-string/browser.js +139 silly gunzTarPerm extractEntry test/field/node_modules/z-string/main.js +140 silly gunzTarPerm extractEntry test/field/node_modules/z-sub/package.json +141 silly gunzTarPerm extractEntry test/field/node_modules/z-sub/main.js +142 silly gunzTarPerm extractEntry test/field/node_modules/z-sub/browser/a.js +143 silly gunzTarPerm extractEntry test/field/node_modules/z-sub/browser/b.js +144 silly gunzTarPerm extractEntry test/wrap/a.js +145 silly gunzTarPerm extractEntry test/wrap/c.js +146 silly gunzTarPerm extractEntry test/wrap/skipme.js +147 silly gunzTarPerm extractEntry test/wrap/x.js +148 silly gunzTarPerm extractEntry test/wrap/node_modules/b/package.json +149 silly gunzTarPerm extractEntry test/wrap/node_modules/b/main.js +150 silly gunzTarPerm extractEntry test/wrap/node_modules/skipmetoo/index.js +151 silly gunzTarPerm extractEntry test/export/entry.js +152 silly gunzTarPerm extractEntry test/error_code/src.js +153 silly gunzTarPerm extractEntry test/multi_entry/a.js +154 silly gunzTarPerm extractEntry test/multi_entry/b.js +155 silly gunzTarPerm extractEntry test/multi_entry/c.js +156 silly gunzTarPerm extractEntry test/subdep/package.json +157 silly gunzTarPerm extractEntry test/subdep/index.js +158 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/package.json +159 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/b.js +160 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/ignore_me.js +161 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/node_modules/a/package.json +162 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/node_modules/a/index.js +163 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/node_modules/c/package.json +164 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/node_modules/c/index.js +165 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/node_modules/f/index.js +166 silly gunzTarPerm extractEntry test/subdep/node_modules/qq/node_modules/z/index.js +167 silly gunzTarPerm extractEntry test/dollar/dollar/index.js +168 silly gunzTarPerm extractEntry test/comment/main.js +169 silly gunzTarPerm extractEntry test/watch/a.js +170 silly gunzTarPerm extractEntry test/coffee/bar.js +171 silly gunzTarPerm extractEntry test/coffee/baz.coffee +172 silly gunzTarPerm extractEntry test/coffee/entry.coffee +173 silly gunzTarPerm extractEntry test/coffee/foo.coffee +174 silly gunzTarPerm extractEntry test/coffee/index.coffee +175 silly gunzTarPerm extractEntry test/coffee/nested/nested.coffee +176 silly gunzTarPerm extractEntry test/entry/main.js +177 silly gunzTarPerm extractEntry test/entry/one.js +178 silly gunzTarPerm extractEntry test/entry/two.js +179 silly gunzTarPerm extractEntry test/node_modules/beep/index.js +180 silly gunzTarPerm extractEntry testling/tick.js +181 silly gunzTarPerm extractEntry testling/timers.js +182 silly gunzTarPerm extractEntry testling/util.js +183 silly gunzTarPerm extractEntry testling/README.markdown +184 silly gunzTarPerm extractEntry testling/test.sh +185 silly gunzTarPerm extractEntry v2.markdown +186 silly gunzTarPerm extractEntry wrappers/alias.js +187 silly gunzTarPerm extractEntry wrappers/body.js +188 silly gunzTarPerm extractEntry wrappers/body_debug.js +189 silly gunzTarPerm extractEntry wrappers/entry.js +190 silly gunzTarPerm extractEntry wrappers/entry_debug.js +191 silly gunzTarPerm extractEntry wrappers/package.js +192 silly gunzTarPerm extractEntry wrappers/prelude.js +193 verbose read json /usr/local/lib/node_modules/browserify/package.json +194 silly lockFile 361ec04d-ocal-lib-node-modules-browserify /usr/local/lib/node_modules/browserify +195 info preinstall [email protected] +196 verbose from cache /usr/local/lib/node_modules/browserify/package.json +197 verbose readDependencies using package.json deps +198 verbose from cache /usr/local/lib/node_modules/browserify/package.json +199 verbose readDependencies using package.json deps +200 verbose cache add [ 'detective@~0.2.0', null ] +201 verbose cache add name=undefined spec="detective@~0.2.0" args=["detective@~0.2.0",null] +202 verbose parsed url { pathname: 'detective@~0.2.0', +202 verbose parsed url path: 'detective@~0.2.0', +202 verbose parsed url href: 'detective@~0.2.0' } +203 verbose cache add name="detective" spec="~0.2.0" args=["detective","~0.2.0"] +204 verbose parsed url { pathname: '~0.2.0', path: '~0.2.0', href: '~0.2.0' } +205 verbose addNamed [ 'detective', '~0.2.0' ] +206 verbose addNamed [ null, '>=0.2.0- <0.3.0-' ] +207 silly lockFile 7bc3123d-detective-0-2-0 detective@~0.2.0 +208 verbose lock detective@~0.2.0 /Users/wilsonpage/.npm/7bc3123d-detective-0-2-0.lock +209 verbose cache add [ 'buffer-browserify@~0.0.1', null ] +210 verbose cache add name=undefined spec="buffer-browserify@~0.0.1" args=["buffer-browserify@~0.0.1",null] +211 verbose parsed url { pathname: 'buffer-browserify@~0.0.1', +211 verbose parsed url path: 'buffer-browserify@~0.0.1', +211 verbose parsed url href: 'buffer-browserify@~0.0.1' } +212 verbose cache add name="buffer-browserify" spec="~0.0.1" args=["buffer-browserify","~0.0.1"] +213 verbose parsed url { pathname: '~0.0.1', path: '~0.0.1', href: '~0.0.1' } +214 verbose addNamed [ 'buffer-browserify', '~0.0.1' ] +215 verbose addNamed [ null, '>=0.0.1- <0.1.0-' ] +216 silly lockFile 079b8dc8-buffer-browserify-0-0-1 buffer-browserify@~0.0.1 +217 verbose lock buffer-browserify@~0.0.1 /Users/wilsonpage/.npm/079b8dc8-buffer-browserify-0-0-1.lock +218 silly addNameRange { name: 'detective', range: '>=0.2.0- <0.3.0-', hasData: false } +219 silly addNameRange { name: 'buffer-browserify', +219 silly addNameRange range: '>=0.0.1- <0.1.0-', +219 silly addNameRange hasData: false } +220 verbose url raw detective +221 verbose url resolving [ 'https://registry.npmjs.org/', './detective' ] +222 verbose url resolved https://registry.npmjs.org/detective +223 info trying registry request attempt 1 at 16:13:26 +224 verbose etag "CS22IULIINICISVA17X1DZX9H" +225 http GET https://registry.npmjs.org/detective +226 verbose url raw buffer-browserify +227 verbose url resolving [ 'https://registry.npmjs.org/', './buffer-browserify' ] +228 verbose url resolved https://registry.npmjs.org/buffer-browserify +229 info trying registry request attempt 1 at 16:13:26 +230 verbose etag "4QNNANHHHCTJCSSXMTEBKT9PH" +231 http GET https://registry.npmjs.org/buffer-browserify +232 verbose cache add [ 'console-browserify@~0.1.0', null ] +233 verbose cache add name=undefined spec="console-browserify@~0.1.0" args=["console-browserify@~0.1.0",null] +234 verbose parsed url { pathname: 'console-browserify@~0.1.0', +234 verbose parsed url path: 'console-browserify@~0.1.0', +234 verbose parsed url href: 'console-browserify@~0.1.0' } +235 verbose cache add name="console-browserify" spec="~0.1.0" args=["console-browserify","~0.1.0"] +236 verbose parsed url { pathname: '~0.1.0', path: '~0.1.0', href: '~0.1.0' } +237 verbose addNamed [ 'console-browserify', '~0.1.0' ] +238 verbose addNamed [ null, '>=0.1.0- <0.2.0-' ] +239 silly lockFile abfcf364-console-browserify-0-1-0 console-browserify@~0.1.0 +240 verbose lock console-browserify@~0.1.0 /Users/wilsonpage/.npm/abfcf364-console-browserify-0-1-0.lock +241 verbose cache add [ 'deputy@~0.0.3', null ] +242 verbose cache add name=undefined spec="deputy@~0.0.3" args=["deputy@~0.0.3",null] +243 verbose parsed url { pathname: 'deputy@~0.0.3', +243 verbose parsed url path: 'deputy@~0.0.3', +243 verbose parsed url href: 'deputy@~0.0.3' } +244 verbose cache add name="deputy" spec="~0.0.3" args=["deputy","~0.0.3"] +245 verbose parsed url { pathname: '~0.0.3', path: '~0.0.3', href: '~0.0.3' } +246 verbose addNamed [ 'deputy', '~0.0.3' ] +247 verbose addNamed [ null, '>=0.0.3- <0.1.0-' ] +248 silly lockFile f65dca98-deputy-0-0-3 deputy@~0.0.3 +249 verbose lock deputy@~0.0.3 /Users/wilsonpage/.npm/f65dca98-deputy-0-0-3.lock +250 verbose cache add [ 'syntax-error@~0.0.0', null ] +251 verbose cache add name=undefined spec="syntax-error@~0.0.0" args=["syntax-error@~0.0.0",null] +252 verbose parsed url { pathname: 'syntax-error@~0.0.0', +252 verbose parsed url path: 'syntax-error@~0.0.0', +252 verbose parsed url href: 'syntax-error@~0.0.0' } +253 verbose cache add name="syntax-error" spec="~0.0.0" args=["syntax-error","~0.0.0"] +254 verbose parsed url { pathname: '~0.0.0', path: '~0.0.0', href: '~0.0.0' } +255 verbose addNamed [ 'syntax-error', '~0.0.0' ] +256 verbose addNamed [ null, '>=0.0.0- <0.1.0-' ] +257 silly lockFile 541c7056-syntax-error-0-0-0 syntax-error@~0.0.0 +258 verbose lock syntax-error@~0.0.0 /Users/wilsonpage/.npm/541c7056-syntax-error-0-0-0.lock +259 verbose cache add [ 'resolve@~0.2.0', null ] +260 verbose cache add name=undefined spec="resolve@~0.2.0" args=["resolve@~0.2.0",null] +261 verbose parsed url { pathname: 'resolve@~0.2.0', +261 verbose parsed url path: 'resolve@~0.2.0', +261 verbose parsed url href: 'resolve@~0.2.0' } +262 verbose cache add name="resolve" spec="~0.2.0" args=["resolve","~0.2.0"] +263 verbose parsed url { pathname: '~0.2.0', path: '~0.2.0', href: '~0.2.0' } +264 verbose addNamed [ 'resolve', '~0.2.0' ] +265 verbose addNamed [ null, '>=0.2.0- <0.3.0-' ] +266 silly lockFile eb1ed680-resolve-0-2-0 resolve@~0.2.0 +267 verbose lock resolve@~0.2.0 /Users/wilsonpage/.npm/eb1ed680-resolve-0-2-0.lock +268 verbose cache add [ 'nub@~0.0.0', null ] +269 verbose cache add name=undefined spec="nub@~0.0.0" args=["nub@~0.0.0",null] +270 verbose parsed url { pathname: 'nub@~0.0.0', +270 verbose parsed url path: 'nub@~0.0.0', +270 verbose parsed url href: 'nub@~0.0.0' } +271 verbose cache add name="nub" spec="~0.0.0" args=["nub","~0.0.0"] +272 verbose parsed url { pathname: '~0.0.0', path: '~0.0.0', href: '~0.0.0' } +273 verbose addNamed [ 'nub', '~0.0.0' ] +274 verbose addNamed [ null, '>=0.0.0- <0.1.0-' ] +275 silly lockFile fe411909-nub-0-0-0 nub@~0.0.0 +276 verbose lock nub@~0.0.0 /Users/wilsonpage/.npm/fe411909-nub-0-0-0.lock +277 verbose cache add [ 'commondir@~0.0.1', null ] +278 verbose cache add name=undefined spec="commondir@~0.0.1" args=["commondir@~0.0.1",null] +279 verbose parsed url { pathname: 'commondir@~0.0.1', +279 verbose parsed url path: 'commondir@~0.0.1', +279 verbose parsed url href: 'commondir@~0.0.1' } +280 verbose cache add name="commondir" spec="~0.0.1" args=["commondir","~0.0.1"] +281 verbose parsed url { pathname: '~0.0.1', path: '~0.0.1', href: '~0.0.1' } +282 verbose addNamed [ 'commondir', '~0.0.1' ] +283 verbose addNamed [ null, '>=0.0.1- <0.1.0-' ] +284 silly lockFile d18c18a5-commondir-0-0-1 commondir@~0.0.1 +285 verbose lock commondir@~0.0.1 /Users/wilsonpage/.npm/d18c18a5-commondir-0-0-1.lock +286 verbose cache add [ '[email protected]', null ] +287 verbose cache add name=undefined spec="[email protected]" args=["[email protected]",null] +288 verbose parsed url { pathname: '[email protected]', +288 verbose parsed url path: '[email protected]', +288 verbose parsed url href: '[email protected]' } +289 verbose cache add name="coffee-script" spec="1.x.x" args=["coffee-script","1.x.x"] +290 verbose parsed url { pathname: '1.x.x', path: '1.x.x', href: '1.x.x' } +291 verbose addNamed [ 'coffee-script', '1.x.x' ] +292 verbose addNamed [ null, '>=1.0.0- <2.0.0-' ] +293 silly lockFile edf96972-coffee-script-1-x-x [email protected] +294 verbose lock [email protected] /Users/wilsonpage/.npm/edf96972-coffee-script-1-x-x.lock +295 verbose cache add [ 'optimist@~0.3.4', null ] +296 verbose cache add name=undefined spec="optimist@~0.3.4" args=["optimist@~0.3.4",null] +297 verbose parsed url { pathname: 'optimist@~0.3.4', +297 verbose parsed url path: 'optimist@~0.3.4', +297 verbose parsed url href: 'optimist@~0.3.4' } +298 verbose cache add name="optimist" spec="~0.3.4" args=["optimist","~0.3.4"] +299 verbose parsed url { pathname: '~0.3.4', path: '~0.3.4', href: '~0.3.4' } +300 verbose addNamed [ 'optimist', '~0.3.4' ] +301 verbose addNamed [ null, '>=0.3.4- <0.4.0-' ] +302 silly lockFile 094c60bd-optimist-0-3-4 optimist@~0.3.4 +303 verbose lock optimist@~0.3.4 /Users/wilsonpage/.npm/094c60bd-optimist-0-3-4.lock +304 verbose cache add [ 'http-browserify@~0.1.1', null ] +305 verbose cache add name=undefined spec="http-browserify@~0.1.1" args=["http-browserify@~0.1.1",null] +306 verbose parsed url { pathname: 'http-browserify@~0.1.1', +306 verbose parsed url path: 'http-browserify@~0.1.1', +306 verbose parsed url href: 'http-browserify@~0.1.1' } +307 verbose cache add name="http-browserify" spec="~0.1.1" args=["http-browserify","~0.1.1"] +308 verbose parsed url { pathname: '~0.1.1', path: '~0.1.1', href: '~0.1.1' } +309 verbose addNamed [ 'http-browserify', '~0.1.1' ] +310 verbose addNamed [ null, '>=0.1.1- <0.2.0-' ] +311 silly lockFile 83e61da6-http-browserify-0-1-1 http-browserify@~0.1.1 +312 verbose lock http-browserify@~0.1.1 /Users/wilsonpage/.npm/83e61da6-http-browserify-0-1-1.lock +313 verbose cache add [ 'vm-browserify@~0.0.0', null ] +314 verbose cache add name=undefined spec="vm-browserify@~0.0.0" args=["vm-browserify@~0.0.0",null] +315 verbose parsed url { pathname: 'vm-browserify@~0.0.0', +315 verbose parsed url path: 'vm-browserify@~0.0.0', +315 verbose parsed url href: 'vm-browserify@~0.0.0' } +316 verbose cache add name="vm-browserify" spec="~0.0.0" args=["vm-browserify","~0.0.0"] +317 verbose parsed url { pathname: '~0.0.0', path: '~0.0.0', href: '~0.0.0' } +318 verbose addNamed [ 'vm-browserify', '~0.0.0' ] +319 verbose addNamed [ null, '>=0.0.0- <0.1.0-' ] +320 silly lockFile 29145f01-vm-browserify-0-0-0 vm-browserify@~0.0.0 +321 verbose lock vm-browserify@~0.0.0 /Users/wilsonpage/.npm/29145f01-vm-browserify-0-0-0.lock +322 verbose cache add [ 'crypto-browserify@~0', null ] +323 verbose cache add name=undefined spec="crypto-browserify@~0" args=["crypto-browserify@~0",null] +324 verbose parsed url { pathname: 'crypto-browserify@~0', +324 verbose parsed url path: 'crypto-browserify@~0', +324 verbose parsed url href: 'crypto-browserify@~0' } +325 verbose cache add name="crypto-browserify" spec="~0" args=["crypto-browserify","~0"] +326 verbose parsed url { pathname: '~0', path: '~0', href: '~0' } +327 verbose addNamed [ 'crypto-browserify', '~0' ] +328 verbose addNamed [ null, '>=0.0.0- <1.0.0-' ] +329 silly lockFile e9cc4b31-crypto-browserify-0 crypto-browserify@~0 +330 verbose lock crypto-browserify@~0 /Users/wilsonpage/.npm/e9cc4b31-crypto-browserify-0.lock +331 silly addNameRange { name: 'console-browserify', +331 silly addNameRange range: '>=0.1.0- <0.2.0-', +331 silly addNameRange hasData: false } +332 silly addNameRange { name: 'deputy', range: '>=0.0.3- <0.1.0-', hasData: false } +333 silly addNameRange { name: 'syntax-error', +333 silly addNameRange range: '>=0.0.0- <0.1.0-', +333 silly addNameRange hasData: false } +334 silly addNameRange { name: 'resolve', range: '>=0.2.0- <0.3.0-', hasData: false } +335 silly addNameRange { name: 'nub', range: '>=0.0.0- <0.1.0-', hasData: false } +336 silly addNameRange { name: 'commondir', range: '>=0.0.1- <0.1.0-', hasData: false } +337 silly addNameRange { name: 'coffee-script', +337 silly addNameRange range: '>=1.0.0- <2.0.0-', +337 silly addNameRange hasData: false } +338 silly addNameRange { name: 'optimist', range: '>=0.3.4- <0.4.0-', hasData: false } +339 silly addNameRange { name: 'http-browserify', +339 silly addNameRange range: '>=0.1.1- <0.2.0-', +339 silly addNameRange hasData: false } +340 silly addNameRange { name: 'vm-browserify', +340 silly addNameRange range: '>=0.0.0- <0.1.0-', +340 silly addNameRange hasData: false } +341 silly addNameRange { name: 'crypto-browserify', +341 silly addNameRange range: '>=0.0.0- <1.0.0-', +341 silly addNameRange hasData: false } +342 verbose url raw console-browserify +343 verbose url resolving [ 'https://registry.npmjs.org/', './console-browserify' ] +344 verbose url resolved https://registry.npmjs.org/console-browserify +345 info trying registry request attempt 1 at 16:13:26 +346 verbose etag "8NQSFR1VJGC9HB5C7AJIIZELT" +347 http GET https://registry.npmjs.org/console-browserify +348 verbose url raw deputy +349 verbose url resolving [ 'https://registry.npmjs.org/', './deputy' ] +350 verbose url resolved https://registry.npmjs.org/deputy +351 info trying registry request attempt 1 at 16:13:26 +352 verbose etag "4AOH7BGC316WGXVN9EL31OZ93" +353 http GET https://registry.npmjs.org/deputy +354 verbose url raw syntax-error +355 verbose url resolving [ 'https://registry.npmjs.org/', './syntax-error' ] +356 verbose url resolved https://registry.npmjs.org/syntax-error +357 info trying registry request attempt 1 at 16:13:26 +358 verbose etag "4T9O90M0FDSNQV970DTCW6MZ9" +359 http GET https://registry.npmjs.org/syntax-error +360 verbose url raw resolve +361 verbose url resolving [ 'https://registry.npmjs.org/', './resolve' ] +362 verbose url resolved https://registry.npmjs.org/resolve +363 info trying registry request attempt 1 at 16:13:26 +364 verbose etag "1PRD1ZSWQFUUV9QIHA7G137QL" +365 http GET https://registry.npmjs.org/resolve +366 verbose url raw nub +367 verbose url resolving [ 'https://registry.npmjs.org/', './nub' ] +368 verbose url resolved https://registry.npmjs.org/nub +369 info trying registry request attempt 1 at 16:13:26 +370 verbose etag "13K3EU4M2PX1SLZHKRRYKF3RR" +371 http GET https://registry.npmjs.org/nub +372 verbose url raw commondir +373 verbose url resolving [ 'https://registry.npmjs.org/', './commondir' ] +374 verbose url resolved https://registry.npmjs.org/commondir +375 info trying registry request attempt 1 at 16:13:26 +376 verbose etag "CBLBPLAJ0K8OBJ8W72IANIRND" +377 http GET https://registry.npmjs.org/commondir +378 verbose url raw coffee-script +379 verbose url resolving [ 'https://registry.npmjs.org/', './coffee-script' ] +380 verbose url resolved https://registry.npmjs.org/coffee-script +381 info trying registry request attempt 1 at 16:13:26 +382 verbose etag "5DVQS1LWDXJKMR2BFTU1OGKFH" +383 http GET https://registry.npmjs.org/coffee-script +384 verbose url raw optimist +385 verbose url resolving [ 'https://registry.npmjs.org/', './optimist' ] +386 verbose url resolved https://registry.npmjs.org/optimist +387 info trying registry request attempt 1 at 16:13:26 +388 verbose etag "EH1DT6319Y8YFU4ST3I7HOF8V" +389 http GET https://registry.npmjs.org/optimist +390 verbose url raw http-browserify +391 verbose url resolving [ 'https://registry.npmjs.org/', './http-browserify' ] +392 verbose url resolved https://registry.npmjs.org/http-browserify +393 info trying registry request attempt 1 at 16:13:26 +394 verbose etag "3ZSAXT2SH4DEHT45GPONPV899" +395 http GET https://registry.npmjs.org/http-browserify +396 verbose url raw vm-browserify +397 verbose url resolving [ 'https://registry.npmjs.org/', './vm-browserify' ] +398 verbose url resolved https://registry.npmjs.org/vm-browserify +399 info trying registry request attempt 1 at 16:13:26 +400 verbose etag "2XG3HQ3T4VY572CS9AFY94WQU" +401 http GET https://registry.npmjs.org/vm-browserify +402 verbose url raw crypto-browserify +403 verbose url resolving [ 'https://registry.npmjs.org/', './crypto-browserify' ] +404 verbose url resolved https://registry.npmjs.org/crypto-browserify +405 info trying registry request attempt 1 at 16:13:26 +406 verbose etag "1MSPD2DY9YO38O07CEG61QQT0" +407 http GET https://registry.npmjs.org/crypto-browserify +408 http 304 https://registry.npmjs.org/detective +409 silly registry.get cb [ 304, +409 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +409 silly registry.get etag: '"CS22IULIINICISVA17X1DZX9H"', +409 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +409 silly registry.get 'content-length': '0' } ] +410 verbose etag detective from cache +411 http 304 https://registry.npmjs.org/buffer-browserify +412 silly registry.get cb [ 304, +412 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +412 silly registry.get etag: '"4QNNANHHHCTJCSSXMTEBKT9PH"', +412 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +412 silly registry.get 'content-length': '0' } ] +413 verbose etag buffer-browserify from cache +414 silly addNameRange number 2 { name: 'detective', range: '>=0.2.0- <0.3.0-', hasData: true } +415 silly addNameRange versions [ 'detective', +415 silly addNameRange [ '0.0.0', +415 silly addNameRange '0.0.1', +415 silly addNameRange '0.0.2', +415 silly addNameRange '0.0.3', +415 silly addNameRange '0.0.4', +415 silly addNameRange '0.1.0', +415 silly addNameRange '0.1.1', +415 silly addNameRange '0.2.0', +415 silly addNameRange '0.2.1' ] ] +416 verbose addNamed [ 'detective', '0.2.1' ] +417 verbose addNamed [ '0.2.1', '0.2.1' ] +418 silly lockFile 1ea47442-detective-0-2-1 [email protected] +419 verbose lock [email protected] /Users/wilsonpage/.npm/1ea47442-detective-0-2-1.lock +420 silly addNameRange number 2 { name: 'buffer-browserify', +420 silly addNameRange range: '>=0.0.1- <0.1.0-', +420 silly addNameRange hasData: true } +421 silly addNameRange versions [ 'buffer-browserify', [ '0.0.1', '0.0.2', '0.0.3', '0.0.4' ] ] +422 verbose addNamed [ 'buffer-browserify', '0.0.4' ] +423 verbose addNamed [ '0.0.4', '0.0.4' ] +424 silly lockFile c0fe6422-buffer-browserify-0-0-4 [email protected] +425 verbose lock [email protected] /Users/wilsonpage/.npm/c0fe6422-buffer-browserify-0-0-4.lock +426 verbose read json /Users/wilsonpage/.npm/detective/0.2.1/package/package.json +427 verbose read json /Users/wilsonpage/.npm/buffer-browserify/0.0.4/package/package.json +428 silly lockFile 1ea47442-detective-0-2-1 [email protected] +429 silly lockFile c0fe6422-buffer-browserify-0-0-4 [email protected] +430 silly lockFile 7bc3123d-detective-0-2-0 detective@~0.2.0 +431 silly lockFile 079b8dc8-buffer-browserify-0-0-1 buffer-browserify@~0.0.1 +432 http 304 https://registry.npmjs.org/console-browserify +433 silly registry.get cb [ 304, +433 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +433 silly registry.get etag: '"8NQSFR1VJGC9HB5C7AJIIZELT"', +433 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +433 silly registry.get 'content-length': '0' } ] +434 verbose etag console-browserify from cache +435 silly addNameRange number 2 { name: 'console-browserify', +435 silly addNameRange range: '>=0.1.0- <0.2.0-', +435 silly addNameRange hasData: true } +436 silly addNameRange versions [ 'console-browserify', [ '0.1.0', '0.1.1', '0.1.2', '0.1.3' ] ] +437 verbose addNamed [ 'console-browserify', '0.1.3' ] +438 verbose addNamed [ '0.1.3', '0.1.3' ] +439 silly lockFile f52d299a-console-browserify-0-1-3 [email protected] +440 verbose lock [email protected] /Users/wilsonpage/.npm/f52d299a-console-browserify-0-1-3.lock +441 verbose read json /Users/wilsonpage/.npm/console-browserify/0.1.3/package/package.json +442 silly lockFile f52d299a-console-browserify-0-1-3 [email protected] +443 silly lockFile abfcf364-console-browserify-0-1-0 console-browserify@~0.1.0 +444 http 304 https://registry.npmjs.org/syntax-error +445 silly registry.get cb [ 304, +445 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +445 silly registry.get etag: '"4T9O90M0FDSNQV970DTCW6MZ9"', +445 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +445 silly registry.get 'content-length': '0' } ] +446 verbose etag syntax-error from cache +447 silly addNameRange number 2 { name: 'syntax-error', +447 silly addNameRange range: '>=0.0.0- <0.1.0-', +447 silly addNameRange hasData: true } +448 silly addNameRange versions [ 'syntax-error', [ '0.0.0' ] ] +449 verbose addNamed [ 'syntax-error', '0.0.0' ] +450 verbose addNamed [ '0.0.0', '0.0.0' ] +451 silly lockFile 8693c57b-syntax-error-0-0-0 [email protected] +452 verbose lock [email protected] /Users/wilsonpage/.npm/8693c57b-syntax-error-0-0-0.lock +453 verbose read json /Users/wilsonpage/.npm/syntax-error/0.0.0/package/package.json +454 silly lockFile 8693c57b-syntax-error-0-0-0 [email protected] +455 silly lockFile 541c7056-syntax-error-0-0-0 syntax-error@~0.0.0 +456 http 304 https://registry.npmjs.org/deputy +457 silly registry.get cb [ 304, +457 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +457 silly registry.get etag: '"4AOH7BGC316WGXVN9EL31OZ93"', +457 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +457 silly registry.get 'content-length': '0' } ] +458 verbose etag deputy from cache +459 silly addNameRange number 2 { name: 'deputy', range: '>=0.0.3- <0.1.0-', hasData: true } +460 silly addNameRange versions [ 'deputy', [ '0.0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4' ] ] +461 verbose addNamed [ 'deputy', '0.0.4' ] +462 verbose addNamed [ '0.0.4', '0.0.4' ] +463 silly lockFile 12bc9d79-deputy-0-0-4 [email protected] +464 verbose lock [email protected] /Users/wilsonpage/.npm/12bc9d79-deputy-0-0-4.lock +465 verbose read json /Users/wilsonpage/.npm/deputy/0.0.4/package/package.json +466 silly lockFile 12bc9d79-deputy-0-0-4 [email protected] +467 silly lockFile f65dca98-deputy-0-0-3 deputy@~0.0.3 +468 http 304 https://registry.npmjs.org/resolve +469 silly registry.get cb [ 304, +469 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +469 silly registry.get etag: '"1PRD1ZSWQFUUV9QIHA7G137QL"', +469 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +469 silly registry.get 'content-length': '0' } ] +470 verbose etag resolve from cache +471 http 304 https://registry.npmjs.org/nub +472 silly registry.get cb [ 304, +472 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +472 silly registry.get etag: '"13K3EU4M2PX1SLZHKRRYKF3RR"', +472 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +472 silly registry.get 'content-length': '0' } ] +473 verbose etag nub from cache +474 http 304 https://registry.npmjs.org/commondir +475 silly registry.get cb [ 304, +475 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +475 silly registry.get etag: '"CBLBPLAJ0K8OBJ8W72IANIRND"', +475 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +475 silly registry.get 'content-length': '0' } ] +476 verbose etag commondir from cache +477 silly addNameRange number 2 { name: 'nub', range: '>=0.0.0- <0.1.0-', hasData: true } +478 silly addNameRange versions [ 'nub', [ '0.0.0' ] ] +479 verbose addNamed [ 'nub', '0.0.0' ] +480 verbose addNamed [ '0.0.0', '0.0.0' ] +481 silly lockFile 34fd82fb-nub-0-0-0 [email protected] +482 verbose lock [email protected] /Users/wilsonpage/.npm/34fd82fb-nub-0-0-0.lock +483 silly addNameRange number 2 { name: 'commondir', range: '>=0.0.1- <0.1.0-', hasData: true } +484 silly addNameRange versions [ 'commondir', [ '0.0.0', '0.0.1' ] ] +485 verbose addNamed [ 'commondir', '0.0.1' ] +486 verbose addNamed [ '0.0.1', '0.0.1' ] +487 silly lockFile 56818eda-commondir-0-0-1 [email protected] +488 verbose lock [email protected] /Users/wilsonpage/.npm/56818eda-commondir-0-0-1.lock +489 verbose read json /Users/wilsonpage/.npm/nub/0.0.0/package/package.json +490 silly addNameRange number 2 { name: 'resolve', range: '>=0.2.0- <0.3.0-', hasData: true } +491 silly addNameRange versions [ 'resolve', +491 silly addNameRange [ '0.0.0', +491 silly addNameRange '0.0.1', +491 silly addNameRange '0.0.2', +491 silly addNameRange '0.0.3', +491 silly addNameRange '0.0.4', +491 silly addNameRange '0.1.0', +491 silly addNameRange '0.1.2', +491 silly addNameRange '0.1.3', +491 silly addNameRange '0.2.0', +491 silly addNameRange '0.2.1', +491 silly addNameRange '0.2.2', +491 silly addNameRange '0.2.3' ] ] +492 verbose addNamed [ 'resolve', '0.2.3' ] +493 verbose addNamed [ '0.2.3', '0.2.3' ] +494 silly lockFile 677ab067-resolve-0-2-3 [email protected] +495 verbose lock [email protected] /Users/wilsonpage/.npm/677ab067-resolve-0-2-3.lock +496 verbose read json /Users/wilsonpage/.npm/commondir/0.0.1/package/package.json +497 verbose read json /Users/wilsonpage/.npm/resolve/0.2.3/package/package.json +498 silly lockFile 34fd82fb-nub-0-0-0 [email protected] +499 silly lockFile fe411909-nub-0-0-0 nub@~0.0.0 +500 silly lockFile 56818eda-commondir-0-0-1 [email protected] +501 http 304 https://registry.npmjs.org/coffee-script +502 silly registry.get cb [ 304, +502 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +502 silly registry.get etag: '"5DVQS1LWDXJKMR2BFTU1OGKFH"', +502 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +502 silly registry.get 'content-length': '0' } ] +503 verbose etag coffee-script from cache +504 silly lockFile 677ab067-resolve-0-2-3 [email protected] +505 silly lockFile d18c18a5-commondir-0-0-1 commondir@~0.0.1 +506 silly lockFile eb1ed680-resolve-0-2-0 resolve@~0.2.0 +507 silly addNameRange number 2 { name: 'coffee-script', +507 silly addNameRange range: '>=1.0.0- <2.0.0-', +507 silly addNameRange hasData: true } +508 silly addNameRange versions [ 'coffee-script', +508 silly addNameRange [ '0.7.0', +508 silly addNameRange '0.7.1', +508 silly addNameRange '0.7.2', +508 silly addNameRange '0.9.0', +508 silly addNameRange '0.9.1', +508 silly addNameRange '0.9.2', +508 silly addNameRange '0.9.3', +508 silly addNameRange '0.9.4', +508 silly addNameRange '0.9.5', +508 silly addNameRange '0.9.6', +508 silly addNameRange '1.0.0', +508 silly addNameRange '1.0.1', +508 silly addNameRange '1.1.0', +508 silly addNameRange '1.1.1', +508 silly addNameRange '1.1.2', +508 silly addNameRange '1.1.3', +508 silly addNameRange '1.2.0', +508 silly addNameRange '1.3.0', +508 silly addNameRange '1.3.1', +508 silly addNameRange '1.3.2', +508 silly addNameRange '1.3.3', +508 silly addNameRange '1.4.0' ] ] +509 verbose addNamed [ 'coffee-script', '1.4.0' ] +510 verbose addNamed [ '1.4.0', '1.4.0' ] +511 silly lockFile 0c6dfe35-coffee-script-1-4-0 [email protected] +512 verbose lock [email protected] /Users/wilsonpage/.npm/0c6dfe35-coffee-script-1-4-0.lock +513 verbose read json /Users/wilsonpage/.npm/coffee-script/1.4.0/package/package.json +514 silly lockFile 0c6dfe35-coffee-script-1-4-0 [email protected] +515 silly lockFile edf96972-coffee-script-1-x-x [email protected] +516 http 304 https://registry.npmjs.org/optimist +517 silly registry.get cb [ 304, +517 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +517 silly registry.get etag: '"EH1DT6319Y8YFU4ST3I7HOF8V"', +517 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +517 silly registry.get 'content-length': '0' } ] +518 verbose etag optimist from cache +519 silly addNameRange number 2 { name: 'optimist', range: '>=0.3.4- <0.4.0-', hasData: true } +520 silly addNameRange versions [ 'optimist', +520 silly addNameRange [ '0.0.1', +520 silly addNameRange '0.0.2', +520 silly addNameRange '0.0.4', +520 silly addNameRange '0.0.5', +520 silly addNameRange '0.0.6', +520 silly addNameRange '0.0.7', +520 silly addNameRange '0.1.0', +520 silly addNameRange '0.1.1', +520 silly addNameRange '0.1.2', +520 silly addNameRange '0.1.3', +520 silly addNameRange '0.1.4', +520 silly addNameRange '0.1.5', +520 silly addNameRange '0.1.6', +520 silly addNameRange '0.1.7', +520 silly addNameRange '0.1.8', +520 silly addNameRange '0.1.9', +520 silly addNameRange '0.0.3', +520 silly addNameRange '0.2.0', +520 silly addNameRange '0.2.1', +520 silly addNameRange '0.2.2', +520 silly addNameRange '0.2.3', +520 silly addNameRange '0.2.4', +520 silly addNameRange '0.2.5', +520 silly addNameRange '0.2.6', +520 silly addNameRange '0.2.7', +520 silly addNameRange '0.2.8', +520 silly addNameRange '0.3.0', +520 silly addNameRange '0.3.1', +520 silly addNameRange '0.3.3', +520 silly addNameRange '0.3.4', +520 silly addNameRange '0.3.5' ] ] +521 verbose addNamed [ 'optimist', '0.3.5' ] +522 verbose addNamed [ '0.3.5', '0.3.5' ] +523 silly lockFile 72e2da2d-optimist-0-3-5 [email protected] +524 verbose lock [email protected] /Users/wilsonpage/.npm/72e2da2d-optimist-0-3-5.lock +525 verbose read json /Users/wilsonpage/.npm/optimist/0.3.5/package/package.json +526 silly lockFile 72e2da2d-optimist-0-3-5 [email protected] +527 silly lockFile 094c60bd-optimist-0-3-4 optimist@~0.3.4 +528 http 304 https://registry.npmjs.org/http-browserify +529 silly registry.get cb [ 304, +529 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +529 silly registry.get etag: '"3ZSAXT2SH4DEHT45GPONPV899"', +529 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +529 silly registry.get 'content-length': '0' } ] +530 verbose etag http-browserify from cache +531 silly addNameRange number 2 { name: 'http-browserify', +531 silly addNameRange range: '>=0.1.1- <0.2.0-', +531 silly addNameRange hasData: true } +532 silly addNameRange versions [ 'http-browserify', +532 silly addNameRange [ '0.0.0', +532 silly addNameRange '0.0.1', +532 silly addNameRange '0.0.2', +532 silly addNameRange '0.0.3', +532 silly addNameRange '0.1.0', +532 silly addNameRange '0.1.1', +532 silly addNameRange '0.1.2', +532 silly addNameRange '0.1.3', +532 silly addNameRange '0.1.4', +532 silly addNameRange '0.1.5', +532 silly addNameRange '0.1.6' ] ] +533 verbose addNamed [ 'http-browserify', '0.1.6' ] +534 verbose addNamed [ '0.1.6', '0.1.6' ] +535 silly lockFile a3526272-http-browserify-0-1-6 [email protected] +536 verbose lock [email protected] /Users/wilsonpage/.npm/a3526272-http-browserify-0-1-6.lock +537 verbose read json /Users/wilsonpage/.npm/http-browserify/0.1.6/package/package.json +538 silly lockFile a3526272-http-browserify-0-1-6 [email protected] +539 http 304 https://registry.npmjs.org/crypto-browserify +540 silly registry.get cb [ 304, +540 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +540 silly registry.get etag: '"1MSPD2DY9YO38O07CEG61QQT0"', +540 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +540 silly registry.get 'content-length': '0' } ] +541 verbose etag crypto-browserify from cache +542 silly lockFile 83e61da6-http-browserify-0-1-1 http-browserify@~0.1.1 +543 silly addNameRange number 2 { name: 'crypto-browserify', +543 silly addNameRange range: '>=0.0.0- <1.0.0-', +543 silly addNameRange hasData: true } +544 silly addNameRange versions [ 'crypto-browserify', +544 silly addNameRange [ '0.0.0', '0.0.1', '0.1.0', '0.1.1', '0.1.2', '0.2.0', '0.2.1' ] ] +545 verbose addNamed [ 'crypto-browserify', '0.2.1' ] +546 verbose addNamed [ '0.2.1', '0.2.1' ] +547 silly lockFile fd6b21c3-crypto-browserify-0-2-1 [email protected] +548 verbose lock [email protected] /Users/wilsonpage/.npm/fd6b21c3-crypto-browserify-0-2-1.lock +549 verbose read json /Users/wilsonpage/.npm/crypto-browserify/0.2.1/package/package.json +550 http 304 https://registry.npmjs.org/vm-browserify +551 silly registry.get cb [ 304, +551 silly registry.get { server: 'CouchDB/1.2.1 (Erlang OTP/R15B)', +551 silly registry.get etag: '"2XG3HQ3T4VY572CS9AFY94WQU"', +551 silly registry.get date: 'Tue, 29 Jan 2013 16:11:46 GMT', +551 silly registry.get 'content-length': '0' } ] +552 verbose etag vm-browserify from cache +553 silly lockFile fd6b21c3-crypto-browserify-0-2-1 [email protected] +554 silly lockFile e9cc4b31-crypto-browserify-0 crypto-browserify@~0 +555 silly addNameRange number 2 { name: 'vm-browserify', +555 silly addNameRange range: '>=0.0.0- <0.1.0-', +555 silly addNameRange hasData: true } +556 silly addNameRange versions [ 'vm-browserify', [ '0.0.0', '0.0.1' ] ] +557 verbose addNamed [ 'vm-browserify', '0.0.1' ] +558 verbose addNamed [ '0.0.1', '0.0.1' ] +559 silly lockFile 1b64966c-vm-browserify-0-0-1 [email protected] +560 verbose lock [email protected] /Users/wilsonpage/.npm/1b64966c-vm-browserify-0-0-1.lock +561 verbose read json /Users/wilsonpage/.npm/vm-browserify/0.0.1/package/package.json +562 silly lockFile 1b64966c-vm-browserify-0-0-1 [email protected] +563 silly lockFile 29145f01-vm-browserify-0-0-0 vm-browserify@~0.0.0 +564 silly resolved [ { name: 'detective', +564 silly resolved description: 'Find all calls to require() no matter how crazily nested using a proper walk of the AST', +564 silly resolved version: '0.2.1', +564 silly resolved repository: +564 silly resolved { type: 'git', +564 silly resolved url: 'git://github.com/substack/node-detective.git' }, +564 silly resolved main: 'index.js', +564 silly resolved keywords: [ 'require', 'source', 'analyze', 'ast' ], +564 silly resolved directories: { lib: '.', example: 'example', test: 'test' }, +564 silly resolved scripts: { test: 'tap test/*.js' }, +564 silly resolved dependencies: { esprima: '~0.9.9' }, +564 silly resolved devDependencies: { tap: '~0.2.6' }, +564 silly resolved engines: { node: '>=0.6.0' }, +564 silly resolved license: 'MIT', +564 silly resolved author: +564 silly resolved { name: 'James Halliday', +564 silly resolved email: '[email protected]', +564 silly resolved url: 'http://substack.net' }, +564 silly resolved readme: 'detective\n=========\n\nFind all calls to require() no matter how crazily nested using a proper walk of\nthe AST.\n\n[![build status](https://secure.travis-ci.org/substack/node-detective.png)](http://travis-ci.org/substack/node-detective)\n\nexample\n=======\n\nstrings\n-------\n\nstrings_src.js:\n\n````javascript\nvar a = require(\'a\');\nvar b = require(\'b\');\nvar c = require(\'c\');\n````\n\nstrings.js:\n\n````javascript\nvar detective = require(\'detective\');\nvar fs = require(\'fs\');\n\nvar src = fs.readFileSync(__dirname + \'/strings_src.js\');\nvar requires = detective(src);\nconsole.dir(requires);\n````\n\noutput:\n\n $ node examples/strings.js\n [ \'a\', \'b\', \'c\' ]\n\nmethods\n=======\n\nvar detective = require(\'detective\');\n\ndetective(src, opts)\n--------------------\n\nGive some source body `src`, return an array of all the require()s with string\narguments.\n\nThe options parameter `opts` is passed along to `detective.find()`.\n\ndetective.find(src, opts)\n-------------------------\n\nGive some source body `src`, return an object with "strings" and "expressions"\narrays for each of the require() calls.\n\nThe "expressions" array will contain the stringified expressions.\n\nOptionally you can specify a different function besides `"require"` to analyze\nwith `opts.word`.\n\ninstallation\n============\n\n npm install detective\n', +564 silly resolved readmeFilename: 'README.markdown', +564 silly resolved _id: '[email protected]', +564 silly resolved _from: 'detective@~0.2.0' }, +564 silly resolved { name: 'buffer-browserify', +564 silly resolved version: '0.0.4', +564 silly resolved description: 'buffer module compatibility for browserify', +564 silly resolved main: 'index.js', +564 silly resolved browserify: 'index.js', +564 silly resolved directories: { test: 'test' }, +564 silly resolved dependencies: { 'base64-js': '0.0.2' }, +564 silly resolved devDependencies: { tap: '0.2.x' }, +564 silly resolved repository: +564 silly resolved { type: 'git', +564 silly resolved url: 'http://github.com/toots/buffer-browserify.git' }, +564 silly resolved keywords: [ 'buffer', 'browserify', 'compatible', 'meatless', 'browser' ], +564 silly resolved author: { name: 'Romain Beauxis', email: '[email protected]' }, +564 silly resolved scripts: { test: 'node node_modules/tap/bin/tap.js test/*.js' }, +564 silly resolved license: 'MIT/X11', +564 silly resolved engine: { node: '>=0.6' }, +564 silly resolved readme: 'buffer-browserify\n===============\n\nThe buffer module from [node.js](http://nodejs.org/),\nbut for browsers.\n\nWhen you `require(\'buffer\')` in\n[browserify](http://github.com/substack/node-browserify),\nthis module will be loaded.\n\nIt will also be loaded if you use the global `Buffer` variable.\n', +564 silly resolved readmeFilename: 'README.md', +564 silly resolved _id: '[email protected]', +564 silly resolved _from: 'buffer-browserify@~0.0.1' }, +564 silly resolved { name: 'console-browserify', +564 silly resolved version: '0.1.3', +564 silly resolved description: 'Emulate console for all the browsers', +564 silly resolved keywords: [], +564 silly resolved author: { name: 'Raynos', email: '[email protected]' }, +564 silly resolved repository: +564 silly resolved { type: 'git', +564 silly resolved url: 'git://github.com/Raynos/console-browserify.git' }, +564 silly resolved main: 'index', +564 silly resolved homepage: 'https://github.com/Raynos/console-browserify', +564 silly resolved contributors: [ [Object] ], +564 silly resolved bugs: +564 silly resolved { url: 'https://github.com/Raynos/console-browserify/issues', +564 silly resolved email: '[email protected]' }, +564 silly resolved dependencies: { 'date-now': '~0.1.1' }, +564 silly resolved devDependencies: +564 silly resolved { tape: '~0.2.2', +564 silly resolved browserify: 'https://github.com/raynos/node-browserify/tarball/master', +564 silly resolved testem: '~0.2.55' }, +564 silly resolved licenses: [ [Object] ], +564 silly resolved scripts: +564 silly resolved { test: 'node ./test', +564 silly resolved build: 'browserify test/index.js -o test/static/bundle.js', +564 silly resolved testem: 'testem', +564 silly resolved postinstall: 'npm dedup' }, +564 silly resolved testling: { files: 'test/index.js', browsers: [Object] }, +564 silly resolved readme: '# console-browserify\n\n[![build status][1]][2]\n\n[![browser support][3]][4]\n\nEmulate console for all the browsers\n\n## Example\n\n```js\nvar console = require("console-browserify")\n\nconsole.log("hello world!")\n```\n\n## Installation\n\n`npm install console-browserify`\n\n## Contributors\n\n - Raynos\n\n## MIT Licenced\n\n\n\n [1]: https://secure.travis-ci.org/Raynos/console-browserify.png\n [2]: http://travis-ci.org/Raynos/console-browserify\n [3]: http://ci.testling.com/Raynos/console-browserify.png\n [4]: http://ci.testling.com/Raynos/console-browserify\n', +564 silly resolved readmeFilename: 'README.md', +564 silly resolved _id: '[email protected]', +564 silly resolved _from: 'console-browserify@~0.1.0' }, +564 silly resolved { name: 'syntax-error', +564 silly resolved version: '0.0.0', +564 silly resolved description: 'detect and report syntax errors in source code strings', +564 silly resolved main: 'index.js', +564 silly resolved bin: {}, +564 silly resolved directories: { example: 'example', test: 'test' }, +564 silly resolved dependencies: { esprima: '~0.9.9' }, +564 silly resolved devDependencies: { tap: '~0.3.0' }, +564 silly resolved scripts: { test: 'tap test/*.js' }, +564 silly resolved repository: +564 silly resolved { type: 'git', +564 silly resolved url: 'git://github.com/substack/node-syntax-error.git' }, +564 silly resolved homepage: 'https://github.com/substack/node-syntax-error', +564 silly resolved keywords: [ 'syntax', 'error', 'esprima', 'stack', 'line', 'column' ], +564 silly resolved author: +564 silly resolved { name: 'James Halliday', +564 silly resolved email: '[email protected]', +564 silly resolved url: 'http://substack.net' }, +564 silly resolved license: 'MIT', +564 silly resolved engine: { node: '>=0.6' }, +564 silly resolved readme: '# syntax-error\n\nDetect and report syntax errors in source code strings.\n\n[![build status](https://secure.travis-ci.org/substack/node-syntax-error.png)](http://travis-ci.org/substack/node-syntax-error)\n\nWhen you type `node src.js` you get a friendly error report about exactly where\nthe syntax error is. This module lets you check for syntax errors and report\nthem in a similarly friendly format that wrapping a try/catch around\n`Function()` or `vm.runInNewContext()` doesn\'t get you.\n\n# example\n\n``` js\nvar fs = require(\'fs\');\nvar check = require(\'syntax-error\');\n\nvar file = __dirname + \'/src.js\';\nvar src = fs.readFileSync(file);\n\nvar err = check(src, file);\nif (err) {\n console.error(\'ERROR DETECTED\' + Array(62).join(\'!\'));\n console.error(err);\n console.error(Array(76).join(\'-\'));\n}\n```\n\n***\n\n```\n$ node check.js\nERROR DETECTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n/home/substack/projects/node-syntax-error/example/src.js:5\n if (Array.isArray(x) res.push.apply(res, x);\n ^\nParseError: Unexpected identifier\n---------------------------------------------------------------------------\n```\n\n# methods\n\n``` js\nvar check = require(\'syntax-error\')\n```\n\n## var err = check(src, file)\n\nCheck the source code string `src` for syntax errors.\nOptionally you can specify a filename `file` that will show up in the output.\n\nIf `src` has a syntax error, return an error object `err` that can be printed or\nstringified.\n\nIf there are no syntax errors in `src`, return `undefined`.\n\n## err.toString()\n\nReturn the long string description with a source snippet and a `^` under\npointing exactly where the error was detected.\n\n# attributes\n\n## err.message\n\nshort string description of the error type\n\n## err.line\n\nline number of the error in the original source (indexing starts at 1)\n\n## err.column\n\ncolumn number of the error in the original source (indexing starts at 1)\n\n# install\n\nWith [npm](http://npmjs.org) do:\n\n```\nnpm install syntax-error\n```\n\n# license\n\nMIT\n', +564 silly resolved readmeFilename: 'readme.markdown', +564 silly resolved _id: '[email protected]', +564 silly resolved _from: 'syntax-error@~0.0.0' }, +564 silly resolved { name: 'deputy', +564 silly resolved description: 'caching layer for detective', +564 silly resolved version: '0.0.4', +564 silly resolved repository: +564 silly resolved { type: 'git', +564 silly resolved url: 'git://github.com/substack/node-deputy.git' }, +564 silly resolved main: 'index.js', +564 silly resolved keywords: [ 'detective', 'require', 'cache' ], +564 silly resolved directories: { lib: '.', example: 'example', test: 'test' }, +564 silly resolved scripts: { test: 'tap test/*.js' }, +564 silly resolved dependencies: { mkdirp: '~0.3.3', detective: '~0.2.0' }, +564 silly resolved devDependencies: { tap: '0.0.x' }, +564 silly resolved engines: { node: '>=0.4.0' }, +564 silly resolved license: 'MIT', +564 silly resolved author: +564 silly resolved { name: 'James Halliday', +564 silly resolved email: '[email protected]', +564 silly resolved url: 'http://substack.net' }, +564 silly resolved readme: 'deputy\n======\n\nThis module is a caching layer around\n[node-detective](http://github.com/substack/node-detective).\n\n[![build status](https://secure.travis-ci.org/substack/node-deputy.png)](http://travis-ci.org/substack/node-deputy)\n\nexample\n=======\n\ncache.js\n--------\n\n``` js\nvar deputy = require(\'deputy\');\nvar detective = deputy(process.env.HOME + \'/.config/deputy.json\');\n\nvar deps = detective.find(\'require("a"); require("b")\');\nconsole.dir(deps);\n```\n\noutput:\n\n```\n$ node cache.js \n{ strings: [ \'a\', \'b\' ], expressions: [] }\n$ cat ~/.config/deputy.json \n{"55952d490bd28e3e256f0b036ced834d":{"strings":["a","b"],"expressions":[]}}\n```\n\nmethods\n=======\n\n``` js\nvar deputy = require(\'deputy\')\n```\n\nvar detective = deputy(cacheFile)\n---------------------------------\n\nReturn a new [detective](http://github.com/substack/node-detective)\nobject using `cacheFile` for caching.\n\ninstall\n=======\n\nWith [npm](http://npmjs.org) do:\n\n npm install deputy\n\nlicense\n=======\n\nMIT/X11\n', +564 silly resolved readmeFilename: 'README.markdown', +564 silly resolved _id: '[email protected]', +564 silly resolved _from: 'deputy@~0.0.3' }, +564 silly resolved { name: 'nub', +564 silly resolved version: '0.0.0', +564 silly resolved description: 'Uniqueness functions', +564 silly resolved main: 'index.js', +564 silly resolved directories: { lib: '.', example: 'example', test: 'test' }, +564 silly resolved dependencies: {}, +564 silly resolved devDependencies: { expresso: '0.7.x' }, +564 silly resolved scripts: { test: 'expresso' }, +564 silly resolved repository: { type: 'git', url: 'http://github.com/substack/node-nub.git' }, +564 silly resolved keywords: [ 'unique', 'uniq', 'uniqBy', 'nub', 'nubBy' ], +564 silly resolved author: +564 silly resolved { name: 'James Halliday', +564 silly resolved email: '[email protected]', +564 silly resolved url: 'http://substack.net' }, +564 silly resolved license: 'MIT/X11', +564 silly resolved engine: { node: '>=0.4' }, +564 silly resolved readme: 'nub\n===\n\nReturn all the unique elements of an array. You can specify your own uniqueness\ncomparison function with `nub.by` too.\n\nThese work like haskell\'s `nub` and `nubBy` functions in Data.List.\n\nmethods\n=======\n\nnub(xs)\n-------\n\nReturn a new array with all the uniqe elements in `xs`.\n\nUniqueness is calculated `===` style so the types matter.\n\nnub.by(xs, cmp)\n---------------\n\nUse `cmp(x,y)` function to compare elements instead of the default.\n`cmp` should return whether the two elements are equal as a boolean.\n', +564 silly resolved readmeFilename: 'README.markdown', +564 silly resolved _id: '[email protected]', +564 silly resolved _from: 'nub@~0.0.0' }, +564 silly resolved { name: 'commondir', +564 silly resolved version: '0.0.1', +564 silly resolved description: 'Compute the closest common parent for file paths', +564 silly resolved main: 'index.js', +564 silly resolved directories: { lib: '.', example: 'example', test: 'test' }, +564 silly resolved dependencies: {}, +564 silly resolved devDependencies: { expresso: '0.7.x' }, +564 silly resolved scripts: { test: 'expresso' }, +564 silly resolved repository: +564 silly resolved { type: 'git', +564 silly resolved url: 'http://github.com/substack/node-commondir.git' }, +564 silly resolved keywords: [ 'common', 'path', 'directory', 'file', 'parent', 'root' ], +564 silly resolved author: +564 silly resolved { name: 'James Halliday', +564 silly resolved email: '[email protected]', +564 silly resolved url: 'http://substack.net' }, +564 silly resolved license: 'MIT/X11', +564 silly resolved engine: { node: '>=0.4' }, +564 silly resolved readme: 'commondir\n=========\n\nCompute the closest common parent directory among an array of directories.\n\nexample\n=======\n\ndir\n---\n\n > var commondir = require(\'commondir\');\n > commondir([ \'/x/y/z\', \'/x/y\', \'/x/y/w/q\' ])\n \'/x/y\'\n\nbase\n----\n\n > var commondir = require(\'commondir\')\n > commondir(\'/foo/bar\', [ \'../baz\', \'../../foo/quux\', \'./bizzy\' ])\n \'/foo\'\n\nmethods\n=======\n\nvar commondir = require(\'commondir\');\n\ncommondir(absolutePaths)\n------------------------\n\nCompute the closest common parent directory for an array `absolutePaths`.\n\ncommondir(basedir, relativePaths)\n---------------------------------\n\nCompute the closest common parent directory for an array `relativePaths` which\nwill be resolved for each `dir` in `relativePaths` according to:\n`path.resolve(basedir, dir)`.\n\ninstallation\n============\n\nUsing [npm](http://npmjs.org), just do:\n\n npm install commondir\n', +564 silly resolved readmeFilename: 'README.markdown', +564 silly resolved _id: '[email protected]', +564 silly resolved _from: 'commondir@~0.0.1' }, +564 silly resolved { name: 'resolve', +564 silly resolved description: 'A more hookable require.resolve() implementation', +564 silly resolved version: '0.2.3', +564 silly resolved repository: +564 silly resolved { type: 'git', +564 silly resolved url: 'git://github.com/substack/node-resolve.git' }, +564 silly resolved main: 'index.js', +564 silly resolved keywords: [ 'resolve', 'require', 'node', 'module' ], +564 silly resolved directories: { lib: '.', example: 'example', test: 'test' }, +564 silly resolved scripts: { test: 'tap test/*.js' }, +564 silly resolved dependencies: {}, +564 silly resolved devDependencies: { tap: '~0.2.4' }, +564 silly resolved engines: { node: '>=0.4.0' }, +564 silly resolved license: 'MIT', +564 silly resolved author: +564 silly resolved { name: 'James Halliday', +564 silly resolved email: '[email protected]', +564 silly resolved url: 'http://substack.net' }, +564 silly resolved readme: 'resolve\n=======\n\nImplements the [node `require.resolve()`\nalgorithm](http://nodejs.org/docs/v0.4.8/api/all.html#all_Together...)\nexcept you can pass in the file to compute paths relatively to along with your\nown `require.paths` without updating the global copy (which doesn\'t even work in\nnode `>=0.5`).\n\n[![build status](https://secure.travis-ci.org/substack/node-resolve.png)](http://travis-ci.org/substack/node-resolve)\n\nmethods\n=======\n\nvar resolve = require(\'resolve\');\n\nresolve.sync(pkg, opts)\n-----------------------\n\nSynchronously search for the package/filename string `pkg`\naccording to the [`require.resolve()`\nalgorithm](http://nodejs.org/docs/v0.4.8/api/all.html#all_Together...)\nfor `X=pkg` and `Y=opts.basedir`.\n\nDefault values for `opts`:\n\n````javascript\n{\n paths : [],\n basedir : __dirname,\n extensions : [ \'.js\' ],\n readFileSync : fs.readFileSync,\n isFile : function (file) {\n return path.existSync(file) && fs.statSync(file).isFile()\n }\n}\n````\n\nOptionally you can specify a `opts.packageFilter` function to map the contents\nof `JSON.parse()`\'d package.json files.\n\nIf nothing is found, all of the directories in `opts.paths` are searched.\n\nresolve.isCore(pkg)\n-------------------\n\nReturn whether a package is in core.\n', +564 silly resolved readmeFilename: 'README.markdown', +564 silly resolved _id: '[email protected]', +564 silly resolved _from: 'resolve@~0.2.0' }, +564 silly resolved { name: 'coffee-script', +564 silly resolved description: 'Unfancy JavaScript', +564 silly resolved keywords: [ 'javascript', 'language', 'coffeescript', 'compiler' ], +564 silly resolved author: { name: 'Jeremy Ashkenas' }, +564 silly resolved version: '1.4.0', +564 silly resolved licenses: [ [Object] ], +564 silly resolved engines: { node: '>=0.4.0' }, +564 silly resolved directories: { lib: './lib/coffee-script' }, +564 silly resolved main: './lib/coffee-script/coffee-script', +564 silly resolved bin: { coffee: './bin/coffee', cake: './bin/cake' }, +564 silly resolved scripts: { test: 'node ./bin/cake test' }, +564 silly resolved homepage: 'http://coffeescript.org', +564 silly resolved bugs: 'https://github.com/jashkenas/coffee-script/issues', +564 silly resolved repository: +564 silly resolved { type: 'git', +564 silly resolved url: 'git://github.com/jashkenas/coffee-script.git' }, +564 silly resolved devDependencies: { 'uglify-js': '>=1.0.0', jison: '>=0.2.0' }, +564 silly resolved readme: '\n {\n } } {\n { { } }\n } }{ {\n { }{ } } _____ __ __\n ( }{ }{ { ) / ____| / _|/ _|\n .- { { } { }} -. | | ___ | |_| |_ ___ ___\n ( ( } { } { } } ) | | / _ \\| _| _/ _ \\/ _ \\\n |`-..________ ..-\'| | |___| (_) | | | || __/ __/\n | | \\_____\\___/|_| |_| \\___|\\___|\n | ;--.\n | (__ \\ _____ _ _\n | | ) ) / ____| (_) | |\n | |/ / | (___ ___ _ __ _ _ __ | |_\n | ( / \\___ \\ / __| \'__| | \'_ \\| __|\n | |/ ____) | (__| | | | |_) | |_\n | | |_____/ \\___|_| |_| .__/ \\__|\n `-.._________..-\' | |\n |_|\n\n\n CoffeeScript is a little language that compiles into JavaScript.\n\n Install Node.js, and then the CoffeeScript compiler:\n sudo bin/cake install\n\n Or, if you have the Node Package Manager installed:\n npm install -g coffee-script\n (Leave
2,410
Serverside example with API changes
0
.log
log
mit
ftlabs/fruitmachine
10067084
<NME> fruitmachine.js <BEF> /*jslint browser:true, node:true*/ /** * FruitMachine * * Renders layouts/modules from a basic layout definition. * If views require custom interactions devs can extend * the basic functionality. * * @version 0.3.3 * @copyright The Financial Times Limited [All Rights Reserved] * @author Wilson Page <[email protected]> */ 'use strict'; /** * Module Dependencies */ var mod = require('./module'); var define = require('./define'); var utils = require('utils'); var events = require('evt'); /** * Creates a fruitmachine * * Options: * * - `Model` A model constructor to use (must have `.toJSON()`) * * @param {Object} options */ module.exports = function(options) { /** * Shortcut method for * creating lazy views. * * @param {Object} options * @return {Module} */ function fm(options) { var Module = fm.modules[options.module]; if (Module) { return new Module(options); } throw new Error("Unable to find module '" + options.module + "'"); } fm.create = module.exports; fm.Model = options.Model; fm.Events = events; fm.Module = mod(fm); fm.define = define(fm); fm.util = utils; fm.modules = {}; fm.config = { templateIterator: 'children', templateInstance: 'child' }; // Mixin events and return return events(fm); }; * by id, or if called with no * arguments, returns this view's id. * * @param {String|undefined} id * @return {View|String} * @api public /** * Returns the first descendent * View with the passed module type. * * @param {String} key * @return {View} * Returns a list of descendent * Views that match the module * type given (Similar to * Element.querySelector();). * * @param {String} key * @return {Array} * for each of the view's * children. * * @param {Function} fn * @return {[type]} */ * * Fires a `render` event on the view. * * @return {[type]} [description] */ View.prototype.render = function() { var html = this.toHTML(); * current layout context and removed * from the DOM. * * @api public */ View.prototype.destroy = function(options) { * @param {String|Object|null} key * @param {*} value * @return {*} */ View.prototype.data = function(key, value) { <MSG> Added more docs <DFF> @@ -427,6 +427,14 @@ * by id, or if called with no * arguments, returns this view's id. * + * Example: + * + * myView.id(); + * //=> 'my_view_id' + * + * myView.id('my_other_views_id'); + * //=> View + * * @param {String|undefined} id * @return {View|String} * @api public @@ -445,6 +453,16 @@ /** * Returns the first descendent * View with the passed module type. + * If called with no arguments the + * View's own module type is returned. + * + * Example: + * + * // Assuming 'myView' has 3 descendent + * // views with the module type 'apple' + * + * myView.modules('apple'); + * //=> View * * @param {String} key * @return {View} @@ -464,7 +482,15 @@ * Returns a list of descendent * Views that match the module * type given (Similar to - * Element.querySelector();). + * Element.querySelectorAll();). + * + * Example: + * + * // Assuming 'myView' has 3 descendent + * // views with the module type 'apple' + * + * myView.modules('apple'); + * //=> [ View, View, View ] * * @param {String} key * @return {Array} @@ -538,6 +564,12 @@ * for each of the view's * children. * + * Example: + * + * myView.each(function(child) { + * // Do stuff with each child view... + * }); + * * @param {Function} fn * @return {[type]} */ @@ -626,7 +658,7 @@ * * Fires a `render` event on the view. * - * @return {[type]} [description] + * @return {View} */ View.prototype.render = function() { var html = this.toHTML(); @@ -735,6 +767,9 @@ * current layout context and removed * from the DOM. * + * Your custom `onDestroy` method is + * called and a `destroy` event is fired. + * * @api public */ View.prototype.destroy = function(options) { @@ -964,6 +999,7 @@ * @param {String|Object|null} key * @param {*} value * @return {*} + * @api public */ View.prototype.data = function(key, value) {
38
Added more docs
2
.js
js
mit
ftlabs/fruitmachine
10067085
<NME> module.toHTML.js <BEF> describe('View#toHTML()', function() { var viewToTest; beforeEach(function() { viewToTest = helpers.createView(); assert.isTrue('string' === typeof html); }, "Should print the child html into the corresponding slot": function() { var apple = new Apple({ slot: 1 }); var layout = new Layout({ test("Should print the child html into the corresponding slot", function() { var apple = new Apple({ slot: 1 }); var layout = new Layout({ children: [apple] }); var appleHtml = apple.toHTML(); var layoutHtml = layout.toHTML(); expect(layoutHtml.indexOf(appleHtml)).toBeGreaterThan(-1); }); test("Should print the child html by id if no slot is found (backwards compatable)", function() { var apple = new Apple({ id: 1 }); var layout = new Layout({ children: [apple] }); var appleHtml = apple.toHTML(); var layoutHtml = layout.toHTML(); expect(layoutHtml.indexOf(appleHtml)).toBeGreaterThan(-1); }); test("Should fallback to printing children by id if no slot is present", function() { var layout = new Layout({ children: [ { module: 'apple', id: 1 } ] }); }, "tearDown": helpers.destroyView }); }); afterEach(function() { helpers.destroyView(); viewToTest = null; }); }); <MSG> Add `before tohtml` event <DFF> @@ -7,6 +7,14 @@ buster.testCase('View#toHTML()', { assert.isTrue('string' === typeof html); }, + "Should fire `before tohtml event`": function() { + var spy = this.spy(); + this.view.on('before tohtml', spy); + var html = this.view.toHTML(); + assert.isTrue('string' === typeof html); + assert.called(spy); + }, + "Should print the child html into the corresponding slot": function() { var apple = new Apple({ slot: 1 }); var layout = new Layout({ @@ -47,4 +55,4 @@ buster.testCase('View#toHTML()', { }, "tearDown": helpers.destroyView -}); \ No newline at end of file +});
9
Add `before tohtml` event
1
.js
toHTML
mit
ftlabs/fruitmachine
10067086
<NME> README.md <BEF> # LoadJS <img src="https://www.muicss.com/static/images/loadjs.svg" width="250px"> LoadJS is a tiny async loader for modern browsers (899 bytes). [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs?type=dev) [![CDNJS](https://img.shields.io/cdnjs/v/loadjs.svg)](https://cdnjs.com/libraries/loadjs) ## Introduction LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript, CSS and image files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code of [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) in your &lt;html&gt; (possibly in the &lt;head&gt; tag) and then use the `loadjs` global to manage JavaScript dependencies after pageload. LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 899 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle and execute code when it loads loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); </script> ``` You can also use more advanced syntax for more options: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle with advanced options loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: function(path, scriptEl) { /* execute code before fetch */ }, async: true, // load files synchronously or asynchronously (default: true) numRetries: 3 // see caveats about using numRetries with async:false (default: 0), returnPromise: false // return Promise object (default: false) }); loadjs.ready('foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(depsNotFound) { /* foobar bundle load failed */ }, }); </script> ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js) (for development) * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js) (for production) It's also available from these public CDNs: * UNPKG * [https://unpkg.com/[email protected]/dist/loadjs.js](https://unpkg.com/[email protected]/dist/loadjs.js) (for development) * [https://unpkg.com/[email protected]/dist/loadjs.min.js](https://unpkg.com/[email protected]/dist/loadjs.min.js) (for production) * CDNJS * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js) (for development) * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js) (for production) You can also use it as a CJS or AMD module: ```bash $ npm install --save loadjs ``` ```javascript var loadjs = require('loadjs'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` ## Browser Support * IE9+ (`async: false` support only works in IE10+) * Opera 12+ * Safari 5+ * Chrome * Firefox * iOS 6+ * Android 4.4+ LoadJS also detects script load failures from AdBlock Plus and Ghostery in: // foo.js & bar.js & thunkor.js & thunky.js loaded }, function(depsNotFound) { if (depsNotFound.indexOf('foo') === -1) {}; // foo failed if (depsNotFound.indexOf('bar') === -1) {}; // bar failed if (depsNotFound.indexOf('thunk') === -1) {}; // thunk failed }); ```javascript loadjs('/path/to/foo.js', function() { /* foo.js loaded */ }); ``` 1. Fetch files in parallel and load them asynchronously ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() { /* foo.js and bar.js loaded */ }); ``` 1. Fetch JavaScript, CSS and image files ```javascript loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() { /* foo.css, bar.png and thunk.js loaded */ }); ``` 1. Force treat file as CSS stylesheet ```javascript loadjs(['css!/path/to/cssfile.custom'], function() { /* cssfile.custom loaded as stylesheet */ }); ``` 1. Force treat file as image ```javascript loadjs(['img!/path/to/image.custom'], function() { /* image.custom loaded */ }); ``` 1. Add a bundle id ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Use .ready() to define bundles and callbacks separately ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Use multiple bundles in .ready() dependency lists ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs(['/path/to/bar1.js', '/path/to/bar2.js'], 'bar'); loadjs.ready(['foo', 'bar'], function() { /* foo.js & bar1.js & bar2.js loaded */ }); ``` 1. Chain .ready() together ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs .ready('foo', function() { /* foo.js loaded */ }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Use Promises to register callbacks ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true}) .then(function() { /* foo.js & bar.js loaded */ }) .catch(function(pathsNotFound) { /* at least one didn't load */ }); ``` 1. Check if bundle has already been defined ```javascript if (!loadjs.isDefined('foobar')) { loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() { /* foo.js and bar.js loaded in series */ }, async: false }); ``` 1. Add an error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ } }); ``` 1. Retry files before calling the error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ }, numRetries: 3 }); // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries ``` 1. Execute a callback before script tags are embedded ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { /* called for each script node before being embedded */ if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; } }); ``` 1. Bypass LoadJS default DOM insertion mechanism (DOM `<head>`) ```javascript loadjs(['/path/to/foo.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { document.body.appendChild(scriptEl); /* return `false` to bypass default DOM insertion mechanism */ return false; } }); ``` 1. Use bundle ids in error callback ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs(['/path/to/thunkor.js', '/path/to/thunky.js'], 'thunk'); // wait for multiple depdendencies loadjs.ready(['foo', 'bar', 'thunk'], { success: function() { // foo.js & bar.js & thunkor.js & thunky.js loaded }, error: function(depsNotFound) { if (depsNotFound.indexOf('foo') > -1) {}; // foo failed if (depsNotFound.indexOf('bar') > -1) {}; // bar failed if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed } }); ``` 1. Use .done() for more control ```javascript loadjs.ready(['dependency1', 'dependency2'], function() { /* run code after dependencies have been met */ }); function fn1() { loadjs.done('dependency1'); } function fn2() { loadjs.done('dependency2'); } ``` 1. Reset dependency trackers ```javascript loadjs.reset(); ``` 1. Implement a require-like dependency manager ```javascript var bundles = { 'bundleA': ['/file1.js', '/file2.js'], 'bundleB': ['/file3.js', '/file4.js'] }; function require(bundleIds, callbackFn) { bundleIds.forEach(function(bundleId) { if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId); }); loadjs.ready(bundleIds, callbackFn); } require(['bundleA'], function() { /* bundleA loaded */ }); require(['bundleB'], function() { /* bundleB loaded */ }); require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ }); ``` ## Directory structure <pre> loadjs/ β”œβ”€β”€ dist β”‚Β Β  β”œβ”€β”€ loadjs.js β”‚Β Β  β”œβ”€β”€ loadjs.min.js β”‚Β Β  └── loadjs.umd.js β”œβ”€β”€ examples β”œβ”€β”€ gulpfile.js β”œβ”€β”€ LICENSE.txt β”œβ”€β”€ package.json β”œβ”€β”€ README.md β”œβ”€β”€ src β”‚Β Β  └── loadjs.js β”œβ”€β”€ test └── umd-templates </pre> ## Development Quickstart 1. Install dependencies * [nodejs](http://nodejs.org/) * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository ```bash $ git clone [email protected]:muicss/loadjs.git $ cd loadjs ``` 1. Install node dependencies using npm ```bash $ npm install ``` 1. Build examples ```bash $ npm run build-examples ``` To view the examples you can use any static file server. To use the `nodejs` http-server module: ```bash $ npm install http-server $ npm run http-server -- -p 3000 ``` Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files ```bash $ npm run build-dist ``` The files will be located in the `dist` directory. 1. Run tests To run the browser tests first build the `loadjs` library: ```bash $ npm run build-tests ``` Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files ```bash $ npm run build-all ``` <MSG> Update README.md <DFF> @@ -91,9 +91,9 @@ loadjs.ready(['foo', 'bar', 'thunk'], // foo.js & bar.js & thunkor.js & thunky.js loaded }, function(depsNotFound) { - if (depsNotFound.indexOf('foo') === -1) {}; // foo failed - if (depsNotFound.indexOf('bar') === -1) {}; // bar failed - if (depsNotFound.indexOf('thunk') === -1) {}; // thunk failed + if (depsNotFound.indexOf('foo') > -1) {}; // foo failed + if (depsNotFound.indexOf('bar') > -1) {}; // bar failed + if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed });
3
Update README.md
3
.md
md
mit
muicss/loadjs
10067087
<NME> README.md <BEF> # LoadJS <img src="https://www.muicss.com/static/images/loadjs.svg" width="250px"> LoadJS is a tiny async loader for modern browsers (899 bytes). [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs?type=dev) [![CDNJS](https://img.shields.io/cdnjs/v/loadjs.svg)](https://cdnjs.com/libraries/loadjs) ## Introduction LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript, CSS and image files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code of [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) in your &lt;html&gt; (possibly in the &lt;head&gt; tag) and then use the `loadjs` global to manage JavaScript dependencies after pageload. LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 899 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle and execute code when it loads loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); </script> ``` You can also use more advanced syntax for more options: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle with advanced options loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: function(path, scriptEl) { /* execute code before fetch */ }, async: true, // load files synchronously or asynchronously (default: true) numRetries: 3 // see caveats about using numRetries with async:false (default: 0), returnPromise: false // return Promise object (default: false) }); loadjs.ready('foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(depsNotFound) { /* foobar bundle load failed */ }, }); </script> ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js) (for development) * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js) (for production) It's also available from these public CDNs: * UNPKG * [https://unpkg.com/[email protected]/dist/loadjs.js](https://unpkg.com/[email protected]/dist/loadjs.js) (for development) * [https://unpkg.com/[email protected]/dist/loadjs.min.js](https://unpkg.com/[email protected]/dist/loadjs.min.js) (for production) * CDNJS * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js) (for development) * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js) (for production) You can also use it as a CJS or AMD module: ```bash $ npm install --save loadjs ``` ```javascript var loadjs = require('loadjs'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` ## Browser Support * IE9+ (`async: false` support only works in IE10+) * Opera 12+ * Safari 5+ * Chrome * Firefox * iOS 6+ * Android 4.4+ LoadJS also detects script load failures from AdBlock Plus and Ghostery in: // foo.js & bar.js & thunkor.js & thunky.js loaded }, function(depsNotFound) { if (depsNotFound.indexOf('foo') === -1) {}; // foo failed if (depsNotFound.indexOf('bar') === -1) {}; // bar failed if (depsNotFound.indexOf('thunk') === -1) {}; // thunk failed }); ```javascript loadjs('/path/to/foo.js', function() { /* foo.js loaded */ }); ``` 1. Fetch files in parallel and load them asynchronously ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() { /* foo.js and bar.js loaded */ }); ``` 1. Fetch JavaScript, CSS and image files ```javascript loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() { /* foo.css, bar.png and thunk.js loaded */ }); ``` 1. Force treat file as CSS stylesheet ```javascript loadjs(['css!/path/to/cssfile.custom'], function() { /* cssfile.custom loaded as stylesheet */ }); ``` 1. Force treat file as image ```javascript loadjs(['img!/path/to/image.custom'], function() { /* image.custom loaded */ }); ``` 1. Add a bundle id ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Use .ready() to define bundles and callbacks separately ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` 1. Use multiple bundles in .ready() dependency lists ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs(['/path/to/bar1.js', '/path/to/bar2.js'], 'bar'); loadjs.ready(['foo', 'bar'], function() { /* foo.js & bar1.js & bar2.js loaded */ }); ``` 1. Chain .ready() together ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs .ready('foo', function() { /* foo.js loaded */ }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Use Promises to register callbacks ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true}) .then(function() { /* foo.js & bar.js loaded */ }) .catch(function(pathsNotFound) { /* at least one didn't load */ }); ``` 1. Check if bundle has already been defined ```javascript if (!loadjs.isDefined('foobar')) { loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() { /* foo.js and bar.js loaded in series */ }, async: false }); ``` 1. Add an error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ } }); ``` 1. Retry files before calling the error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ }, numRetries: 3 }); // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries ``` 1. Execute a callback before script tags are embedded ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { /* called for each script node before being embedded */ if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; } }); ``` 1. Bypass LoadJS default DOM insertion mechanism (DOM `<head>`) ```javascript loadjs(['/path/to/foo.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { document.body.appendChild(scriptEl); /* return `false` to bypass default DOM insertion mechanism */ return false; } }); ``` 1. Use bundle ids in error callback ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs(['/path/to/thunkor.js', '/path/to/thunky.js'], 'thunk'); // wait for multiple depdendencies loadjs.ready(['foo', 'bar', 'thunk'], { success: function() { // foo.js & bar.js & thunkor.js & thunky.js loaded }, error: function(depsNotFound) { if (depsNotFound.indexOf('foo') > -1) {}; // foo failed if (depsNotFound.indexOf('bar') > -1) {}; // bar failed if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed } }); ``` 1. Use .done() for more control ```javascript loadjs.ready(['dependency1', 'dependency2'], function() { /* run code after dependencies have been met */ }); function fn1() { loadjs.done('dependency1'); } function fn2() { loadjs.done('dependency2'); } ``` 1. Reset dependency trackers ```javascript loadjs.reset(); ``` 1. Implement a require-like dependency manager ```javascript var bundles = { 'bundleA': ['/file1.js', '/file2.js'], 'bundleB': ['/file3.js', '/file4.js'] }; function require(bundleIds, callbackFn) { bundleIds.forEach(function(bundleId) { if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId); }); loadjs.ready(bundleIds, callbackFn); } require(['bundleA'], function() { /* bundleA loaded */ }); require(['bundleB'], function() { /* bundleB loaded */ }); require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ }); ``` ## Directory structure <pre> loadjs/ β”œβ”€β”€ dist β”‚Β Β  β”œβ”€β”€ loadjs.js β”‚Β Β  β”œβ”€β”€ loadjs.min.js β”‚Β Β  └── loadjs.umd.js β”œβ”€β”€ examples β”œβ”€β”€ gulpfile.js β”œβ”€β”€ LICENSE.txt β”œβ”€β”€ package.json β”œβ”€β”€ README.md β”œβ”€β”€ src β”‚Β Β  └── loadjs.js β”œβ”€β”€ test └── umd-templates </pre> ## Development Quickstart 1. Install dependencies * [nodejs](http://nodejs.org/) * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository ```bash $ git clone [email protected]:muicss/loadjs.git $ cd loadjs ``` 1. Install node dependencies using npm ```bash $ npm install ``` 1. Build examples ```bash $ npm run build-examples ``` To view the examples you can use any static file server. To use the `nodejs` http-server module: ```bash $ npm install http-server $ npm run http-server -- -p 3000 ``` Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files ```bash $ npm run build-dist ``` The files will be located in the `dist` directory. 1. Run tests To run the browser tests first build the `loadjs` library: ```bash $ npm run build-tests ``` Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files ```bash $ npm run build-all ``` <MSG> Update README.md <DFF> @@ -91,9 +91,9 @@ loadjs.ready(['foo', 'bar', 'thunk'], // foo.js & bar.js & thunkor.js & thunky.js loaded }, function(depsNotFound) { - if (depsNotFound.indexOf('foo') === -1) {}; // foo failed - if (depsNotFound.indexOf('bar') === -1) {}; // bar failed - if (depsNotFound.indexOf('thunk') === -1) {}; // thunk failed + if (depsNotFound.indexOf('foo') > -1) {}; // foo failed + if (depsNotFound.indexOf('bar') > -1) {}; // bar failed + if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed });
3
Update README.md
3
.md
md
mit
muicss/loadjs
10067088
<NME> tests.js <BEF> /** * loadjs tests * @module test/tests.js */ var pathsLoaded = null, // file register testEl = null, assert = chai.assert, expect = chai.expect; describe('LoadJS tests', function() { beforeEach(function() { // reset register pathsLoaded = {}; // reset loadjs dependencies loadjs.reset(); }); // ========================================================================== // JavaScript file loading tests // ========================================================================== describe('JavaScript file loading tests', function() { it('should call success callback on valid path', function(done) { loadjs(['assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); done(); } }); }); it('should call error callback on invalid path', function(done) { loadjs(['assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should call before callback before embedding into document', function(done) { var scriptTags = []; loadjs(['assets/file1.js', 'assets/file2.js'], { before: function(path, el) { scriptTags.push({ path: path, el: el }); // add cross origin script for file2 if (path === 'assets/file2.js') { el.crossOrigin = 'anonymous'; } }, success: function() { assert.equal(scriptTags[0].path, 'assets/file1.js'); assert.equal(scriptTags[1].path, 'assets/file2.js'); assert.equal(scriptTags[0].el.crossOrigin, undefined); assert.equal(scriptTags[1].el.crossOrigin, 'anonymous'); done(); } }); }); it('should bypass insertion if before returns `false`', function(done) { loadjs(['assets/file1.js'], { before: function(path, el) { // append to body (instead of head) document.body.appendChild(el); // return `false` to bypass default DOM insertion return false; }, success: function() { assert.equal(pathsLoaded['file1.js'], true); // verify that file was added to body var els = document.body.querySelectorAll('script'), el; for (var i=0; i < els.length; i++) { el = els[i]; if (el.src.indexOf('assets/file1.js') !== -1) done(); } } }); }); it('should call success callback on two valid paths', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should call error callback on one invalid path', function(done) { loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, error: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should support async false', function(done) { this.timeout(5000); var numCompleted = 0, numTests = 20, paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; // run tests sequentially var testFn = function(paths) { // add cache busters var pathsUncached = paths.slice(0); pathsUncached[0] += '?_=' + Math.random(); pathsUncached[1] += '?_=' + Math.random(); loadjs(pathsUncached, { success: function() { var f1 = paths[0].replace('assets/', ''); var f2 = paths[1].replace('assets/', ''); // check load order assert.isTrue(pathsLoaded[f1]); assert.isFalse(pathsLoaded[f2]); // increment tests numCompleted += 1; if (numCompleted === numTests) { // exit done(); } else { // reset register pathsLoaded = {}; // run test again paths.reverse(); testFn(paths); } }, async: false }); }; // run tests testFn(paths); }); it('should support multiple tries', function(done) { loadjs('assets/file-numretries.js', { error: function() { // check number of scripts in document var selector = 'script[src="assets/file-numretries.js"]', scripts = document.querySelectorAll(selector); if (scripts.length === 2) done(); }, numRetries: 1 }); }); // Un-'x' this for testing ad blocked scripts. // Ghostery: Disallow "Google Adservices" // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a // custom filter under Options // xit('it should report ad blocked scripts as missing', function(done) { var s1 = 'https://www.googletagservices.com/tag/js/gpt.js', s2 = 'https://munchkin.marketo.net/munchkin-beta.js'; loadjs([s1, s2, 'assets/file1.js'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 2); assert.equal(pathsNotFound[0], s1); assert.equal(pathsNotFound[1], s2); done(); } }); }); }); // ========================================================================== // CSS file loading tests // ========================================================================== describe('CSS file loading tests', function() { before(function() { // add test div to body for css tests testEl = document.createElement('div'); testEl.className = 'test-div mui-container'; testEl.style.display = 'inline-block'; document.body.appendChild(testEl); }); afterEach(function() { var els = document.getElementsByTagName('link'), i = els.length, el; // iteratete through stylesheets while (i--) { el = els[i]; // remove test stylesheets if (el.href.indexOf('mocha.css') === -1) { el.parentNode.removeChild(el); } } }); it('should load one file', function(done) { loadjs(['assets/file1.css'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should load multiple files', function(done) { loadjs(['assets/file1.css', 'assets/file2.css'], { success: function() { assert.equal(testEl.offsetWidth, 200); done(); } }); }); it('should call error callback on one invalid path', function(done) { loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(testEl.offsetWidth, 100); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css'); done(); } }); }); it('should support mix of css and js', function(done) { loadjs(['assets/file1.css', 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should support forced "css!" files', function(done) { loadjs(['css!assets/file1.css'], { success: function() { // loop through files var els = document.getElementsByTagName('link'), i = els.length, el; while (i--) { if (els[i].href.indexOf('file1.css') !== -1) done(); } } }); }); it('supports urls with query arguments', function(done) { loadjs(['assets/file1.css?x=x'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('supports urls with anchor tags', function(done) { loadjs(['assets/file1.css#anchortag'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('supports urls with query arguments and anchor tags', function(done) { loadjs(['assets/file1.css?x=x#anchortag'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should load external css files', function(done) { this.timeout(0); loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui.min.css'], { success: function() { var styleObj = getComputedStyle(testEl); assert.equal(styleObj.getPropertyValue('padding-left'), '15px'); done(); }); // ========================================================================== // API tests // ========================================================================== loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('should support forced "img!" files', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error callback on one invalid path', function(done) { var src1 = 'assets/flash.png?' + Math.random(), src2 = 'assets/flash-doesntexist.png?' + Math.random(); loadjs(['img!' + src1, 'img!' + src2], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assertLoaded(src1); assertNotLoaded(src2); done(); } }); }); it('should support mix of img and js', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src, 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assertLoaded(src); done(); } }); }); it('should load external img files', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/mui-logo.png?'; src += Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error on missing external file', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/'; src += 'mui-logo-doesntexist.png?' + Math.random(); loadjs(['img!' + src], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assertNotLoaded(src); done(); } }); }); }); // ========================================================================== // API tests // ========================================================================== describe('API tests', function() { it('should throw an error if bundle is already defined', function() { // define bundle loadjs(['assets/file1.js'], 'bundle'); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'bundle'); }; expect(fn).to.throw("LoadJS"); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should chain loadjs object', function(done) { function bothDone() { if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } // define bundles loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs .ready('bundle1', { success: function() { assert.equal(pathsLoaded['file1.js'], true); bothDone(); }}) .ready('bundle2', { success: function() { assert.equal(pathsLoaded['file2.js'], true); bothDone(); } }); }); it('should handle multiple dependencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should error on missing depdendencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file-doesntexist.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { throw "Executed success callback"; }, error: function(depsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(depsNotFound.length, 1); assert.equal(depsNotFound[0], 'bundle2'); done(); } }); }); it('should execute callbacks on .done()', function(done) { // add handler loadjs.ready('plugin', { success: function() { done(); } }); // execute done loadjs.done('plugin'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin'); // add handler loadjs.ready('plugin', { success: function() { done(); } }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); // use 1 second delay to let files load setTimeout(function() { loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }, 1000); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); // use 1 second delay setTimeout(function() { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); }, 1000); }); it('should reset dependencies statuses', function() { loadjs(['assets/file1.js'], 'cleared'); loadjs.reset(); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'cleared'); }; expect(fn).not.to.throw("LoadJS"); }); it('should indicate if bundle has already been defined', function() { loadjs(['assets/file1/js'], 'bundle1'); assert.equal(loadjs.isDefined('bundle1'), true); assert.equal(loadjs.isDefined('bundleXX'), false); }); it('should accept success callback functions to loadjs()', function(done) { loadjs('assets/file1.js', function() { done(); }); }); it('should accept success callback functions to .ready()', function(done) { loadjs.done('plugin'); loadjs.ready('plugin', function() { done(); }); }); it('should return Promise object if returnPromise is true', function() { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); // verify that response object is a Promise assert.equal(prom instanceof Promise, true); }); it('Promise object should support resolutions', function(done) { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); prom.then(function() { assert.equal(pathsLoaded['file1.js'], true); done(); }); }); it('Promise object should support rejections', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom.then( function(){}, function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } ); }); it('Promise object should support catches', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom .catch(function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); }); }); it('supports Promises and success callbacks', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; var prom = loadjs('assets/file1.js', { success: completedFn, returnPromise: true }); prom.then(completedFn); }); it('supports Promises and bundle ready events', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; loadjs('assets/file1.js', 'bundle1', {returnPromise: true}) .then(completedFn); loadjs.ready('bundle1', completedFn); }); }); }); <MSG> added support for loading imgs <DFF> @@ -349,6 +349,124 @@ describe('LoadJS tests', function() { }); + // ========================================================================== + // Image file loading tests + // ========================================================================== + + describe('Image file loading tests', function() { + + function assertLoaded(src) { + var i = new Image(); + i.src = src; + assert.equal(i.naturalWidth > 0, true); + } + + + function assertNotLoaded(src) { + var i = new Image(); + i.src = src; + assert.equal(i.naturalWidth, 0) + } + + + it('should load one file', function(done) { + loadjs(['assets/flash.png'], { + success: function() { + assertLoaded('assets/flash.png'); + done(); + } + }); + }); + + + it('should load multiple files', function(done) { + loadjs(['assets/flash.png', 'assets/flash.jpg'], { + success: function() { + assertLoaded('assets/flash.png'); + assertLoaded('assets/flash.jpg'); + done(); + } + }); + }); + + + it('should support forced "img!" files', function(done) { + var src = 'assets/flash.png?' + Math.random(); + + loadjs(['img!' + src], { + success: function() { + assertLoaded(src); + done(); + } + }); + }); + + + it('should call error callback on one invalid path', function(done) { + var src1 = 'assets/flash.png?' + Math.random(), + src2 = 'assets/flash-doesntexist.png?' + Math.random(); + + loadjs(['img!' + src1, 'img!' + src2], { + success: function() { + throw new Error('Executed success callback'); + }, + error: function(pathsNotFound) { + assert.equal(pathsNotFound.length, 1); + assertLoaded(src1); + assertNotLoaded(src2); + done(); + } + }); + }); + + + it('should support mix of img and js', function(done) { + var src = 'assets/flash.png?' + Math.random(); + + loadjs(['img!' + src, 'assets/file1.js'], { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assertLoaded(src); + done(); + } + }); + }); + + + it('should load external img files', function(done) { + this.timeout(0); + + var src = 'https://www.muicss.com/static/images/mui-logo.png?'; + src += Math.random(); + + loadjs(['img!' + src], { + success: function() { + assertLoaded(src); + done(); + } + }); + }); + + + it('should call error on missing external file', function(done) { + this.timeout(0); + + var src = 'https://www.muicss.com/static/images/'; + src += 'mui-logo-doesntexist.png?' + Math.random(); + + loadjs(['img!' + src], { + success: function() { + throw new Error('Executed success callback'); + }, + error: function(pathsNotFound) { + assertNotLoaded(src); + done(); + } + }); + }); + }); + + // ========================================================================== // API tests // ==========================================================================
118
added support for loading imgs
0
.js
js
mit
muicss/loadjs
10067089
<NME> tests.js <BEF> /** * loadjs tests * @module test/tests.js */ var pathsLoaded = null, // file register testEl = null, assert = chai.assert, expect = chai.expect; describe('LoadJS tests', function() { beforeEach(function() { // reset register pathsLoaded = {}; // reset loadjs dependencies loadjs.reset(); }); // ========================================================================== // JavaScript file loading tests // ========================================================================== describe('JavaScript file loading tests', function() { it('should call success callback on valid path', function(done) { loadjs(['assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); done(); } }); }); it('should call error callback on invalid path', function(done) { loadjs(['assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should call before callback before embedding into document', function(done) { var scriptTags = []; loadjs(['assets/file1.js', 'assets/file2.js'], { before: function(path, el) { scriptTags.push({ path: path, el: el }); // add cross origin script for file2 if (path === 'assets/file2.js') { el.crossOrigin = 'anonymous'; } }, success: function() { assert.equal(scriptTags[0].path, 'assets/file1.js'); assert.equal(scriptTags[1].path, 'assets/file2.js'); assert.equal(scriptTags[0].el.crossOrigin, undefined); assert.equal(scriptTags[1].el.crossOrigin, 'anonymous'); done(); } }); }); it('should bypass insertion if before returns `false`', function(done) { loadjs(['assets/file1.js'], { before: function(path, el) { // append to body (instead of head) document.body.appendChild(el); // return `false` to bypass default DOM insertion return false; }, success: function() { assert.equal(pathsLoaded['file1.js'], true); // verify that file was added to body var els = document.body.querySelectorAll('script'), el; for (var i=0; i < els.length; i++) { el = els[i]; if (el.src.indexOf('assets/file1.js') !== -1) done(); } } }); }); it('should call success callback on two valid paths', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should call error callback on one invalid path', function(done) { loadjs(['assets/file1.js', 'assets/file-doesntexist.js'], { success: function() { throw "Executed success callback"; }, error: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } }); }); it('should support async false', function(done) { this.timeout(5000); var numCompleted = 0, numTests = 20, paths = ['assets/asyncfalse1.js', 'assets/asyncfalse2.js']; // run tests sequentially var testFn = function(paths) { // add cache busters var pathsUncached = paths.slice(0); pathsUncached[0] += '?_=' + Math.random(); pathsUncached[1] += '?_=' + Math.random(); loadjs(pathsUncached, { success: function() { var f1 = paths[0].replace('assets/', ''); var f2 = paths[1].replace('assets/', ''); // check load order assert.isTrue(pathsLoaded[f1]); assert.isFalse(pathsLoaded[f2]); // increment tests numCompleted += 1; if (numCompleted === numTests) { // exit done(); } else { // reset register pathsLoaded = {}; // run test again paths.reverse(); testFn(paths); } }, async: false }); }; // run tests testFn(paths); }); it('should support multiple tries', function(done) { loadjs('assets/file-numretries.js', { error: function() { // check number of scripts in document var selector = 'script[src="assets/file-numretries.js"]', scripts = document.querySelectorAll(selector); if (scripts.length === 2) done(); }, numRetries: 1 }); }); // Un-'x' this for testing ad blocked scripts. // Ghostery: Disallow "Google Adservices" // AdBlock Plus: Add "www.googletagservices.com/tag/js/gpt.js" as a // custom filter under Options // xit('it should report ad blocked scripts as missing', function(done) { var s1 = 'https://www.googletagservices.com/tag/js/gpt.js', s2 = 'https://munchkin.marketo.net/munchkin-beta.js'; loadjs([s1, s2, 'assets/file1.js'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsNotFound.length, 2); assert.equal(pathsNotFound[0], s1); assert.equal(pathsNotFound[1], s2); done(); } }); }); }); // ========================================================================== // CSS file loading tests // ========================================================================== describe('CSS file loading tests', function() { before(function() { // add test div to body for css tests testEl = document.createElement('div'); testEl.className = 'test-div mui-container'; testEl.style.display = 'inline-block'; document.body.appendChild(testEl); }); afterEach(function() { var els = document.getElementsByTagName('link'), i = els.length, el; // iteratete through stylesheets while (i--) { el = els[i]; // remove test stylesheets if (el.href.indexOf('mocha.css') === -1) { el.parentNode.removeChild(el); } } }); it('should load one file', function(done) { loadjs(['assets/file1.css'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should load multiple files', function(done) { loadjs(['assets/file1.css', 'assets/file2.css'], { success: function() { assert.equal(testEl.offsetWidth, 200); done(); } }); }); it('should call error callback on one invalid path', function(done) { loadjs(['assets/file1.css', 'assets/file-doesntexist.css'], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(testEl.offsetWidth, 100); assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.css'); done(); } }); }); it('should support mix of css and js', function(done) { loadjs(['assets/file1.css', 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should support forced "css!" files', function(done) { loadjs(['css!assets/file1.css'], { success: function() { // loop through files var els = document.getElementsByTagName('link'), i = els.length, el; while (i--) { if (els[i].href.indexOf('file1.css') !== -1) done(); } } }); }); it('supports urls with query arguments', function(done) { loadjs(['assets/file1.css?x=x'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('supports urls with anchor tags', function(done) { loadjs(['assets/file1.css#anchortag'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('supports urls with query arguments and anchor tags', function(done) { loadjs(['assets/file1.css?x=x#anchortag'], { success: function() { assert.equal(testEl.offsetWidth, 100); done(); } }); }); it('should load external css files', function(done) { this.timeout(0); loadjs(['//cdn.muicss.com/mui-0.6.8/css/mui.min.css'], { success: function() { var styleObj = getComputedStyle(testEl); assert.equal(styleObj.getPropertyValue('padding-left'), '15px'); done(); }); // ========================================================================== // API tests // ========================================================================== loadjs([src], { success: function() { assertLoaded(src); done(); } }); }); it('should support forced "img!" files', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error callback on one invalid path', function(done) { var src1 = 'assets/flash.png?' + Math.random(), src2 = 'assets/flash-doesntexist.png?' + Math.random(); loadjs(['img!' + src1, 'img!' + src2], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assertLoaded(src1); assertNotLoaded(src2); done(); } }); }); it('should support mix of img and js', function(done) { var src = 'assets/flash.png?' + Math.random(); loadjs(['img!' + src, 'assets/file1.js'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assertLoaded(src); done(); } }); }); it('should load external img files', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/mui-logo.png?'; src += Math.random(); loadjs(['img!' + src], { success: function() { assertLoaded(src); done(); } }); }); it('should call error on missing external file', function(done) { this.timeout(0); var src = 'https://www.muicss.com/static/images/'; src += 'mui-logo-doesntexist.png?' + Math.random(); loadjs(['img!' + src], { success: function() { throw new Error('Executed success callback'); }, error: function(pathsNotFound) { assertNotLoaded(src); done(); } }); }); }); // ========================================================================== // API tests // ========================================================================== describe('API tests', function() { it('should throw an error if bundle is already defined', function() { // define bundle loadjs(['assets/file1.js'], 'bundle'); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'bundle'); }; expect(fn).to.throw("LoadJS"); }); it('should create a bundle id and a callback inline', function(done) { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should chain loadjs object', function(done) { function bothDone() { if (pathsLoaded['file1.js'] && pathsLoaded['file2.js']) done(); } // define bundles loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs .ready('bundle1', { success: function() { assert.equal(pathsLoaded['file1.js'], true); bothDone(); }}) .ready('bundle2', { success: function() { assert.equal(pathsLoaded['file2.js'], true); bothDone(); } }); }); it('should handle multiple dependencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file2.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }); it('should error on missing depdendencies', function(done) { loadjs('assets/file1.js', 'bundle1'); loadjs('assets/file-doesntexist.js', 'bundle2'); loadjs.ready(['bundle1', 'bundle2'], { success: function() { throw "Executed success callback"; }, error: function(depsNotFound) { assert.equal(pathsLoaded['file1.js'], true); assert.equal(depsNotFound.length, 1); assert.equal(depsNotFound[0], 'bundle2'); done(); } }); }); it('should execute callbacks on .done()', function(done) { // add handler loadjs.ready('plugin', { success: function() { done(); } }); // execute done loadjs.done('plugin'); }); it('should execute callbacks created after .done()', function(done) { // execute done loadjs.done('plugin'); // add handler loadjs.ready('plugin', { success: function() { done(); } }); }); it('should define bundles', function(done) { // define bundle loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); // use 1 second delay to let files load setTimeout(function() { loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); }, 1000); }); it('should allow bundle callbacks before definitions', function(done) { // define callback loadjs.ready('bundle', { success: function() { assert.equal(pathsLoaded['file1.js'], true); assert.equal(pathsLoaded['file2.js'], true); done(); } }); // use 1 second delay setTimeout(function() { loadjs(['assets/file1.js', 'assets/file2.js'], 'bundle'); }, 1000); }); it('should reset dependencies statuses', function() { loadjs(['assets/file1.js'], 'cleared'); loadjs.reset(); // define bundle again var fn = function() { loadjs(['assets/file1.js'], 'cleared'); }; expect(fn).not.to.throw("LoadJS"); }); it('should indicate if bundle has already been defined', function() { loadjs(['assets/file1/js'], 'bundle1'); assert.equal(loadjs.isDefined('bundle1'), true); assert.equal(loadjs.isDefined('bundleXX'), false); }); it('should accept success callback functions to loadjs()', function(done) { loadjs('assets/file1.js', function() { done(); }); }); it('should accept success callback functions to .ready()', function(done) { loadjs.done('plugin'); loadjs.ready('plugin', function() { done(); }); }); it('should return Promise object if returnPromise is true', function() { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); // verify that response object is a Promise assert.equal(prom instanceof Promise, true); }); it('Promise object should support resolutions', function(done) { var prom = loadjs(['assets/file1.js'], {returnPromise: true}); prom.then(function() { assert.equal(pathsLoaded['file1.js'], true); done(); }); }); it('Promise object should support rejections', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom.then( function(){}, function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); } ); }); it('Promise object should support catches', function(done) { var prom = loadjs(['assets/file-doesntexist.js'], {returnPromise: true}); prom .catch(function(pathsNotFound) { assert.equal(pathsNotFound.length, 1); assert.equal(pathsNotFound[0], 'assets/file-doesntexist.js'); done(); }); }); it('supports Promises and success callbacks', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; var prom = loadjs('assets/file1.js', { success: completedFn, returnPromise: true }); prom.then(completedFn); }); it('supports Promises and bundle ready events', function(done) { var numCompleted = 0; function completedFn() { numCompleted += 1; if (numCompleted === 2) done(); }; loadjs('assets/file1.js', 'bundle1', {returnPromise: true}) .then(completedFn); loadjs.ready('bundle1', completedFn); }); }); }); <MSG> added support for loading imgs <DFF> @@ -349,6 +349,124 @@ describe('LoadJS tests', function() { }); + // ========================================================================== + // Image file loading tests + // ========================================================================== + + describe('Image file loading tests', function() { + + function assertLoaded(src) { + var i = new Image(); + i.src = src; + assert.equal(i.naturalWidth > 0, true); + } + + + function assertNotLoaded(src) { + var i = new Image(); + i.src = src; + assert.equal(i.naturalWidth, 0) + } + + + it('should load one file', function(done) { + loadjs(['assets/flash.png'], { + success: function() { + assertLoaded('assets/flash.png'); + done(); + } + }); + }); + + + it('should load multiple files', function(done) { + loadjs(['assets/flash.png', 'assets/flash.jpg'], { + success: function() { + assertLoaded('assets/flash.png'); + assertLoaded('assets/flash.jpg'); + done(); + } + }); + }); + + + it('should support forced "img!" files', function(done) { + var src = 'assets/flash.png?' + Math.random(); + + loadjs(['img!' + src], { + success: function() { + assertLoaded(src); + done(); + } + }); + }); + + + it('should call error callback on one invalid path', function(done) { + var src1 = 'assets/flash.png?' + Math.random(), + src2 = 'assets/flash-doesntexist.png?' + Math.random(); + + loadjs(['img!' + src1, 'img!' + src2], { + success: function() { + throw new Error('Executed success callback'); + }, + error: function(pathsNotFound) { + assert.equal(pathsNotFound.length, 1); + assertLoaded(src1); + assertNotLoaded(src2); + done(); + } + }); + }); + + + it('should support mix of img and js', function(done) { + var src = 'assets/flash.png?' + Math.random(); + + loadjs(['img!' + src, 'assets/file1.js'], { + success: function() { + assert.equal(pathsLoaded['file1.js'], true); + assertLoaded(src); + done(); + } + }); + }); + + + it('should load external img files', function(done) { + this.timeout(0); + + var src = 'https://www.muicss.com/static/images/mui-logo.png?'; + src += Math.random(); + + loadjs(['img!' + src], { + success: function() { + assertLoaded(src); + done(); + } + }); + }); + + + it('should call error on missing external file', function(done) { + this.timeout(0); + + var src = 'https://www.muicss.com/static/images/'; + src += 'mui-logo-doesntexist.png?' + Math.random(); + + loadjs(['img!' + src], { + success: function() { + throw new Error('Executed success callback'); + }, + error: function(pathsNotFound) { + assertNotLoaded(src); + done(); + } + }); + }); + }); + + // ========================================================================== // API tests // ==========================================================================
118
added support for loading imgs
0
.js
js
mit
muicss/loadjs
10067090
<NME> build.js <BEF> ;(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0](function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){ (function(global){global.Hogan = require('hogan.js/lib/template').Template; global.app = {}; var fruitmachine = require('../../../../lib/'); var routes = require('../routes'); app.view = fruitmachine(window.layout).setup(); })(window) },{"../../../../lib/":2,"../routes":3,"hogan.js/lib/template":4}],4:[function(require,module,exports){ /* * Copyright 2011 Twitter, Inc. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var Hogan = {}; (function (Hogan, useArrayBuffer) { Hogan.Template = function (renderFunc, text, compiler, options) { this.r = renderFunc || this.r; this.c = compiler; this.options = options; this.text = text || ''; this.buf = (useArrayBuffer) ? [] : ''; } Hogan.Template.prototype = { // render: replaced by generated code. r: function (context, partials, indent) { return ''; }, // variable escaping v: hoganEscape, // triple stache t: coerceToString, render: function render(context, partials, indent) { return this.ri([context], partials || {}, indent); }, // render internal -- a hook for overrides that catches partials too ri: function (context, partials, indent) { return this.r(context, partials, indent); }, // tries to find a partial in the curent scope and render it rp: function(name, context, partials, indent) { var partial = partials[name]; if (!partial) { return ''; } if (this.c && typeof partial == 'string') { partial = this.c.compile(partial, this.options); } return partial.ri(context, partials, indent); }, // render a section rs: function(context, partials, section) { var tail = context[context.length - 1]; if (!isArray(tail)) { section(context, partials, this); return; } for (var i = 0; i < tail.length; i++) { context.push(tail[i]); section(context, partials, this); context.pop(); } }, // maybe start a section s: function(val, ctx, partials, inverted, start, end, tags) { var pass; if (isArray(val) && val.length === 0) { return false; } if (typeof val == 'function') { val = this.ls(val, ctx, partials, inverted, start, end, tags); } pass = (val === '') || !!val; if (!inverted && pass && ctx) { ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]); } return pass; }, // find values with dotted names d: function(key, ctx, partials, returnFound) { var names = key.split('.'), val = this.f(names[0], ctx, partials, returnFound), cx = null; if (key === '.' && isArray(ctx[ctx.length - 2])) { return ctx[ctx.length - 1]; } for (var i = 1; i < names.length; i++) { if (val && typeof val == 'object' && names[i] in val) { cx = val; val = val[names[i]]; } else { val = ''; } } if (returnFound && !val) { return false; } if (!returnFound && typeof val == 'function') { ctx.push(cx); val = this.lv(val, ctx, partials); ctx.pop(); } return val; }, // find values with normal names f: function(key, ctx, partials, returnFound) { var val = false, v = null, found = false; for (var i = ctx.length - 1; i >= 0; i--) { v = ctx[i]; if (v && typeof v == 'object' && key in v) { val = v[key]; found = true; break; } } if (!found) { return (returnFound) ? false : ""; } if (!returnFound && typeof val == 'function') { val = this.lv(val, ctx, partials); } return val; }, // higher order templates ho: function(val, cx, partials, text, tags) { var compiler = this.c; var options = this.options; options.delimiters = tags; var text = val.call(cx, text); text = (text == null) ? String(text) : text.toString(); this.b(compiler.compile(text, options).render(cx, partials)); return false; }, // template result buffering b: (useArrayBuffer) ? function(s) { this.buf.push(s); } : function(s) { this.buf += s; }, fl: (useArrayBuffer) ? function() { var r = this.buf.join(''); this.buf = []; return r; } : function() { var r = this.buf; this.buf = ''; return r; }, // lambda replace section ls: function(val, ctx, partials, inverted, start, end, tags) { var cx = ctx[ctx.length - 1], t = null; if (!inverted && this.c && val.length > 0) { return this.ho(val, cx, partials, this.text.substring(start, end), tags); } t = val.call(cx); if (typeof t == 'function') { if (inverted) { return true; } else if (this.c) { return this.ho(t, cx, partials, this.text.substring(start, end), tags); } } return t; }, // lambda replace variable lv: function(val, ctx, partials) { var cx = ctx[ctx.length - 1]; var result = val.call(cx); if (typeof result == 'function') { result = coerceToString(result.call(cx)); if (this.c && ~result.indexOf("{\u007B")) { return this.c.compile(result, this.options).render(cx, partials); } } return coerceToString(result); } }; var rAmp = /&/g, rLt = /</g, rGt = />/g, rApos =/\'/g, rQuot = /\"/g, hChars =/[&<>\"\']/; function coerceToString(val) { return String((val === null || val === undefined) ? '' : val); } function hoganEscape(str) { str = coerceToString(str); return hChars.test(str) ? str .replace(rAmp,'&amp;') .replace(rLt,'&lt;') .replace(rGt,'&gt;') .replace(rApos,'&#39;') .replace(rQuot, '&quot;') : str; } var isArray = Array.isArray || function(a) { return Object.prototype.toString.call(a) === '[object Array]'; }; })(typeof exports !== 'undefined' ? exports : Hogan); },{}],2:[function(require,module,exports){ /*jslint browser:true, node:true*/ /** * FruitMachine Singleton * * Renders layouts/modules from a basic layout definition. * If views require custom interactions devs can extend * the basic functionality. * * @version 0.3.3 * @copyright The Financial Times Limited [All Rights Reserved] * @author Wilson Page <[email protected]> */ 'use strict'; /** * Module Dependencies */ var fruitMachine = require('./fruitmachine'); var Model = require('model'); /** * Exports */ module.exports = fruitMachine({ Model: Model }); },{"./fruitmachine":5,"model":6}],7:[function(require,module,exports){ /*jslint browser:true, node:true, laxbreak:true*/ 'use strict'; module.exports = function(fm) { /** * Defines a module. * * Options: * * - `name {String}` the name of the module * - `tag {String}` the tagName to use for the root element * - `classes {Array}` a list of classes to add to the root element * - `template {Function}` the template function to use when rendering * - `helpers {Array}` a lsit of helpers to apply to the module * - `initialize {Function}` custom logic to run when module instance created * - `setup {Function}` custom logic to run when `.setup()` is called (directly or indirectly) * - `teardown {Function}` custom logic to unbind/undo anything setup introduced (called on `.destroy()` and sometimes on `.setup()` to avoid double binding events) * - `destroy {Function}` logic to permanently destroy all references * * @param {Object|View} props * @return {View} * @public true */ return function(props) { var Module = ('object' === typeof props) ? fm.Module.extend(props) : props; // Allow modules to be named // via 'name:' or 'module:' var proto = Module.prototype; var name = proto.name || proto._module; // Store the module by module type // so that module can be referred to // by just a string in layout definitions if (name) fm.modules[name] = Module; return Module; }; }; },{}],8:[function(require,module,exports){ var content = document.querySelector('.js-app_content'); var View = require('./view'); var database = { title: 'This is the Home page' }; module.exports = function() { app.view = View(database); app.view .render() .inject(content); }; },{"./view":9}],10:[function(require,module,exports){ var content = document.querySelector('.js-app_content'); var View = require('./view'); var database = { title: 'This is the About page' }; module.exports = function() { app.view = View(database); app.view .render() .inject(content); }; },{"./view":11}],12:[function(require,module,exports){ var content = document.querySelector('.js-app_content'); var View = require('./view'); var database = { title: 'This is the Links page' }; module.exports = function() { app.view = View(database); app.view .render() .inject(content); }; },{"./view":13}],3:[function(require,module,exports){ var page = require('page'); var home = require('../page-home/client'); var about = require('../page-about/client'); var links = require('../page-links/client'); page('/', home); page('/about', about); page('/links', links); page({ dispatch: false }); },{"../page-home/client":8,"../page-about/client":10,"../page-links/client":12,"page":14}],5:[function(require,module,exports){ /*jslint browser:true, node:true*/ /** * FruitMachine * * Renders layouts/modules from a basic layout definition. * If views require custom interactions devs can extend * the basic functionality. * * @version 0.3.3 * @copyright The Financial Times Limited [All Rights Reserved] * @author Wilson Page <[email protected]> */ 'use strict'; /** * Module Dependencies */ var mod = require('./module'); var define = require('./define'); var utils = require('utils'); var events = require('event'); /** * Creates a fruitmachine * * Options: * * - `Model` A model constructor to use (must have `.toJSON()`) * * @param {Object} options */ module.exports = function(options) { /** * Shortcut method for * creating lazy views. * * @param {Object} options * @return {View} */ function fm(options) { var Module = fm.modules[options.module]; if (Module) return new Module(options); } fm.create = module.exports; fm.Model = options.Model; fm.Events = events; fm.Module = mod(fm); fm.define = define(fm); fm.util = utils; fm.modules = {}; fm.config = { templateIterator: 'children', templateInstance: 'child' }; // Mixin events and return return events(fm); }; },{"./define":7,"./module":15,"utils":16,"event":17}],14:[function(require,module,exports){ ;(function(){ /** * Perform initial dispatch. */ var dispatch = true; /** * Base path. */ var base = ''; /** * Running flag. */ var running; /** * Register `path` with callback `fn()`, * or route `path`, or `page.start()`. * * page(fn); * page('*', fn); * page('/user/:id', load, user); * page('/user/' + user.id, { some: 'thing' }); * page('/user/' + user.id); * page(); * * @param {String|Function} path * @param {Function} fn... * @api public */ function page(path, fn) { // <callback> if ('function' == typeof path) { return page('*', path); } // route <path> to <callback ...> if ('function' == typeof fn) { var route = new Route(path); for (var i = 1; i < arguments.length; ++i) { page.callbacks.push(route.middleware(arguments[i])); } // show <path> with [state] } else if ('string' == typeof path) { page.show(path, fn); // start [options] } else { page.start(path); } } /** * Callback functions. */ page.callbacks = []; /** * Get or set basepath to `path`. * * @param {String} path * @api public */ page.base = function(path){ if (0 == arguments.length) return base; base = path; }; /** * Bind with the given `options`. * * Options: * * - `click` bind to click events [true] * - `popstate` bind to popstate [true] * - `dispatch` perform initial dispatch [true] * * @param {Object} options * @api public */ page.start = function(options){ options = options || {}; if (running) return; running = true; if (false === options.dispatch) dispatch = false; if (false !== options.popstate) window.addEventListener('popstate', onpopstate, false); if (false !== options.click) window.addEventListener('click', onclick, false); if (!dispatch) return; page.replace(location.pathname + location.search, null, true, dispatch); }; /** * Unbind click and popstate event handlers. * * @api public */ page.stop = function(){ running = false; removeEventListener('click', onclick, false); removeEventListener('popstate', onpopstate, false); }; /** * Show `path` with optional `state` object. * * @param {String} path * @param {Object} state * @param {Boolean} dispatch * @return {Context} * @api public */ page.show = function(path, state, dispatch){ var ctx = new Context(path, state); if (false !== dispatch) page.dispatch(ctx); if (!ctx.unhandled) ctx.pushState(); return ctx; }; /** * Replace `path` with optional `state` object. * * @param {String} path * @param {Object} state * @return {Context} * @api public */ page.replace = function(path, state, init, dispatch){ var ctx = new Context(path, state); ctx.init = init; if (null == dispatch) dispatch = true; if (dispatch) page.dispatch(ctx); ctx.save(); return ctx; }; /** * Dispatch the given `ctx`. * * @param {Object} ctx * @api private */ page.dispatch = function(ctx){ var i = 0; function next() { var fn = page.callbacks[i++]; if (!fn) return unhandled(ctx); fn(ctx, next); } next(); }; /** * Unhandled `ctx`. When it's not the initial * popstate then redirect. If you wish to handle * 404s on your own use `page('*', callback)`. * * @param {Context} ctx * @api private */ function unhandled(ctx) { if (window.location.pathname + window.location.search == ctx.canonicalPath) return; page.stop(); ctx.unhandled = true; window.location = ctx.canonicalPath; } /** * Initialize a new "request" `Context` * with the given `path` and optional initial `state`. * * @param {String} path * @param {Object} state * @api public */ function Context(path, state) { if ('/' == path[0] && 0 != path.indexOf(base)) path = base + path; var i = path.indexOf('?'); this.canonicalPath = path; this.path = path.replace(base, '') || '/'; this.title = document.title; this.state = state || {}; this.state.path = path; this.querystring = ~i ? path.slice(i + 1) : ''; this.pathname = ~i ? path.slice(0, i) : path; this.params = []; } /** * Expose `Context`. */ page.Context = Context; /** * Push state. * * @api private */ Context.prototype.pushState = function(){ history.pushState(this.state, this.title, this.canonicalPath); }; /** * Save the context state. * * @api public */ Context.prototype.save = function(){ history.replaceState(this.state, this.title, this.canonicalPath); }; /** * Initialize `Route` with the given HTTP `path`, * and an array of `callbacks` and `options`. * * Options: * * - `sensitive` enable case-sensitive routes * - `strict` enable strict matching for trailing slashes * * @param {String} path * @param {Object} options. * @api private */ function Route(path, options) { options = options || {}; this.path = path; this.method = 'GET'; this.regexp = pathtoRegexp(path , this.keys = [] , options.sensitive , options.strict); } /** * Expose `Route`. */ page.Route = Route; /** * Return route middleware with * the given callback `fn()`. * * @param {Function} fn * @return {Function} * @api public */ Route.prototype.middleware = function(fn){ var self = this; return function(ctx, next){ if (self.match(ctx.path, ctx.params)) return fn(ctx, next); next(); } }; /** * Check if this route matches `path`, if so * populate `params`. * * @param {String} path * @param {Array} params * @return {Boolean} * @api private */ Route.prototype.match = function(path, params){ var keys = this.keys , qsIndex = path.indexOf('?') , pathname = ~qsIndex ? path.slice(0, qsIndex) : path , m = this.regexp.exec(pathname); if (!m) return false; for (var i = 1, len = m.length; i < len; ++i) { var key = keys[i - 1]; var val = 'string' == typeof m[i] ? decodeURIComponent(m[i]) : m[i]; if (key) { params[key.name] = undefined !== params[key.name] ? params[key.name] : val; } else { params.push(val); } } return true; }; /** * Normalize the given path string, * returning a regular expression. * * An empty array should be passed, * which will contain the placeholder * key names. For example "/user/:id" will * then contain ["id"]. * * @param {String|RegExp|Array} path * @param {Array} keys * @param {Boolean} sensitive * @param {Boolean} strict * @return {RegExp} * @api private */ function pathtoRegexp(path, keys, sensitive, strict) { if (path instanceof RegExp) return path; if (path instanceof Array) path = '(' + path.join('|') + ')'; path = path .concat(strict ? '' : '/?') .replace(/\/\(/g, '(?:/') .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){ keys.push({ name: key, optional: !! optional }); slash = slash || ''; return '' + (optional ? '' : slash) + '(?:' + (optional ? slash : '') + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')' + (optional || ''); }) .replace(/([\/.])/g, '\\$1') .replace(/\*/g, '(.*)'); return new RegExp('^' + path + '$', sensitive ? '' : 'i'); }; /** * Handle "populate" events. */ function onpopstate(e) { if (e.state) { var path = e.state.path; page.replace(path, e.state); } } /** * Handle "click" events. */ function onclick(e) { if (1 != which(e)) return; if (e.metaKey || e.ctrlKey || e.shiftKey) return; if (e.defaultPrevented) return; // ensure link var el = e.target; while (el && 'A' != el.nodeName) el = el.parentNode; if (!el || 'A' != el.nodeName) return; // ensure non-hash var href = el.href; var path = el.pathname + el.search; if (el.hash || '#' == el.getAttribute('href')) return; // check target if (el.target) return; // x-origin if (!sameOrigin(href)) return; // same page var orig = path; path = path.replace(base, ''); if (base && orig == path) return; e.preventDefault(); page.show(orig); } /** * Event button. */ function which(e) { e = e || window.event; return null == e.which ? e.button : e.which; } /** * Check if `href` is the same origin. */ function sameOrigin(href) { var origin = location.protocol + '//' + location.hostname; if (location.port) origin += ':' + location.port; return 0 == href.indexOf(origin); } /** * Expose `page`. */ if ('undefined' == typeof module) { window.page = page; } else { module.exports = page; } })(); },{}],16:[function(require,module,exports){ /*jshint browser:true, node:true*/ 'use strict'; exports.bind = function(method, context) { return function() { return method.apply(context, arguments); }; }; exports.isArray = function(arg) { return arg instanceof Array; }, exports.mixin = function(original, source) { for (var key in source) original[key] = source[key]; return original; }, exports.byId = function(id, el) { if (el) return el.querySelector('#' + id); }, /** * Inserts an item into an array. * Has the option to state an index. * * @param {*} item * @param {Array} array * @param {Number} index * @return void */ exports.insert = function(item, array, index) { if (typeof index !== 'undefined') { array.splice(index, 0, item); } else { array.push(item); } }, exports.toNode = function(html) { var el = document.createElement('div'); el.innerHTML = html; return el.removeChild(el.firstElementChild); }, // Determine if we have a DOM // in the current environment. exports.hasDom = function() { return typeof document !== 'undefined'; }; var i = 0; exports.uniqueId = function(prefix, suffix) { prefix = prefix || 'id'; suffix = suffix || 'a'; return [prefix, (++i) * Math.round(Math.random() * 100000), suffix].join('-'); }; exports.keys = function(object) { var keys = []; for (var key in object) keys.push(key); return keys; }; exports.isPlainObject = function(ob) { if (!ob) return false; var c = (ob.constructor || '').toString(); return !!~c.indexOf('Object'); }; },{}],17:[function(require,module,exports){ /** * Event * * A super lightweight * event emitter library. * * @version 0.1.4 * @author Wilson Page <[email protected]> */ /** * Locals */ var proto = Event.prototype; /** * Expose `Event` */ module.exports = Event; /** * Creates a new event emitter * instance, or if passed an * object, mixes the event logic * into it. * * @param {Object} obj * @return {Object} */ function Event(obj) { if (!(this instanceof Event)) return new Event(obj); if (obj) return mixin(obj, proto); } /** * Registers a callback * with an event name. * * @param {String} name * @param {Function} cb * @return {Event} */ proto.on = function(name, cb) { this._cbs = this._cbs || {}; (this._cbs[name] || (this._cbs[name] = [])).unshift(cb); return this; }; /** * Removes a single callback, * or all callbacks associated * with the passed event name. * * @param {String} name * @param {Function} cb * @return {Event} */ proto.off = function(name, cb) { this._cbs = this._cbs || {}; if (!name) return this._cbs = {}; if (!cb) return delete this._cbs[name]; var cbs = this._cbs[name] || []; var i; while (cbs && ~(i = cbs.indexOf(cb))) cbs.splice(i, 1); return this; }; /** * Fires an event. Which triggers * all callbacks registered on this * event name. * * @param {String} name * @return {Event} */ proto.fire = function(options) { this._cbs = this._cbs || {}; var name = options.name || options; var ctx = options.ctx || this; var cbs = this._cbs[name]; if (cbs) { var args = [].slice.call(arguments, 1); var l = cbs.length; while (l--) cbs[l].apply(ctx, args); } return this; }; /** * Util */ /** * Mixes in the properties * of the second object into * the first. * * @param {Object} a * @param {Object} b * @return {Object} */ function mixin(a, b) { for (var key in b) a[key] = b[key]; return a; } },{}],9:[function(require,module,exports){ var fruitmachine = require('../../../../lib/'); // Require these views so that // fruitmachine registers them var LayoutA = require('../layout-a'); var ModuleApple = require('../module-apple'); var ModuleOrange = require('../module-orange'); var ModuleBanana = require('../module-banana'); module.exports = function(data) { var layout = { module: 'layout-a', children: [ { id: 'slot_1', module: 'apple', model: { title: data.title } }, { id: 'slot_2', module: 'orange' }, { id: 'slot_3', module: 'banana' } ] }; return fruitmachine(layout); }; },{"../../../../lib/":2,"../layout-a":18,"../module-apple":19,"../module-orange":20,"../module-banana":21}],11:[function(require,module,exports){ var fruitmachine = require('../../../../lib/'); // Require these views so that // fruitmachine registers them var LayoutA = require('../layout-a'); var ModuleApple = require('../module-apple'); var ModuleOrange = require('../module-orange'); var ModuleBanana = require('../module-banana'); module.exports = function(data) { var layout = { module: 'layout-a', children: [ { id: 'slot_1', module: 'apple', model: { title: data.title } }, { id: 'slot_2', module: 'banana' }, { id: 'slot_3', module: 'orange' } ] }; return fruitmachine(layout); }; },{"../../../../lib/":2,"../layout-a":18,"../module-apple":19,"../module-orange":20,"../module-banana":21}],13:[function(require,module,exports){ var fruitmachine = require('../../../../lib/'); // Require these views so that // fruitmachine registers them var LayoutA = require('../layout-a'); var ModuleApple = require('../module-apple'); var ModuleOrange = require('../module-orange'); var ModuleBanana = require('../module-banana'); module.exports = function(data) { var layout = { module: 'layout-a', children: [ { id: 'slot_1', module: 'orange' }, { id: 'slot_2', module: 'apple', model: { title: data.title } }, { id: 'slot_3', module: 'banana' } ] }; return fruitmachine(layout); }; },{"../../../../lib/":2,"../layout-a":18,"../module-apple":19,"../module-orange":20,"../module-banana":21}],22:[function(require,module,exports){ 'use strict'; /** * Locals */ var has = {}.hasOwnProperty; /** * Exports */ module.exports = function(main) { var args = arguments; var l = args.length; var i = 0; var src; var key; while (++i < l) { src = args[i]; for (key in src) { if (has.call(src, key)) { main[key] = src[key]; } } } return main; }; },{}],6:[function(require,module,exports){ 'use strict'; /** * Module Dependencies */ var events = require('event'); var mixin = require('mixin'); /** * Exports */ module.exports = Model; /** * Locals */ var proto = Model.prototype; /** * Model constructor. * * @constructor * @param {Object} data * @api public */ function Model(data) { this._data = mixin({}, data); } /** * Gets a value by key * * If no key is given, the * whole model is returned. * * @param {String} key * @return {*} * @api public */ proto.get = function(key) { return key ? this._data[key] : this._data; }; /** * Sets data on the model. * * Accepts either a key and * value, or an object literal. * * @param {String|Object} key * @param {*|undefined} value */ proto.set = function(data, value) { // If a string key is passed // with a value. Set the value // on the key in the data store. if ('string' === typeof data && typeof value !== 'undefined') { this._data[data] = value; this.fire('change:' + data, value); } // Merge the object into the data store if ('object' === typeof data) { mixin(this._data, data); for (var prop in data) this.fire('change:' + prop, data[prop]); } // Always fire a // generic change event this.fire('change'); // Allow chaining return this; }; /** * CLears the data store. * * @return {Model} */ proto.clear = function() { this._data = {}; this.fire('change'); // Allow chaining return this; }; /** * Deletes the data store. * * @return {undefined} */ proto.destroy = function() { for (var key in this._data) this._data[key] = null; delete this._data; this.fire('destroy'); }; /** * Returns a shallow * clone of the data store. * * @return {Object} */ proto.toJSON = function() { return mixin({}, this._data); }; // Mixin events events(proto); },{"mixin":22,"event":17}],15:[function(require,module,exports){ /*jshint browser:true, node:true*/ 'use strict'; }()); }); require.define("/examples/express/client/routes/index.js",function(require,module,exports,__dirname,__filename,process,global){var page = require('../page-js'); var home = require('../page-home'); var about = require('../page-about'); var links = require('../page-links'); page('/', home); page('/about', about); * Exports */ page({ dispatch: false }); }); require.define("/examples/express/client/page-js/index.js",function(require,module,exports,__dirname,__filename,process,global){;(function(){ /** * Perform initial dispatch. /** * Module constructor * * Options: * * - `id {String}` a unique id to query by * - `model {Object|Model}` the data with which to associate this module * - `tag {String}` tagName to use for the root element * - `classes {Array}` list of classes to add to the root element * - `template {Function}` a template to use for rendering * - `helpers {Array}`a list of helper function to use on this module * - `children {Object|Array}` list of child modules * * @constructor * @param {Object} options * @api public */ function Module(options) { // Shallow clone the options options = mixin({}, options); // Various config steps this._configure(options); this._add(options.children); // Run initialize hooks if (this.initialize) this.initialize(options); // Fire initialize event hook this.fireStatic('initialize', options); } /** * Configures the new Module * with the options passed * to the constructor. * * @param {Object} options * @api private */ proto._configure = function(options) { // Setup static properties this._id = options.id || util.uniqueId('id-'); this._fmid = options.fmid || util.uniqueId('fmid'); this.tag = options.tag || this.tag || 'div'; this.classes = this.classes || options.classes || []; this.helpers = this.helpers || options.helpers || []; this.template = this._setTemplate(options.template || this.template); this.slot = options.slot; // Create id and module // lookup objects this.children = []; this._ids = {}; this._modules = {}; this.slots = {}; // Use the model passed in, // or create a model from // the data passed in. var model = options.model || options.data || {}; this.model = util.isPlainObject(model) ? new this.Model(model) : model; // Attach helpers // TODO: Fix this for non-ES5 environments this.helpers.forEach(this.attachHelper, this); // We fire and 'inflation' event here // so that helpers can make some changes // to the view before instantiation. if (options.fmid) { fm.fire('inflation', this, options); this.fireStatic('inflation', options); } }; /** * A private add method * that accepts a list of * children. * * @param {Object|Array} children * @api private */ proto._add = function(children) { if (!children) return; var isArray = util.isArray(children); var child; for (var key in children) { child = children[key]; if (!isArray) child.slot = key; this.add(child); } }, /** * Instantiates the given * helper on the Module. * * @param {Function} helper * @return {Module} * @api private */ proto.attachHelper = function(helper) { if (helper) helper(this); }, /** * Returns the template function * for the view. * * For template object like Hogan * templates with a `render` method * we need to bind the context * so they can be called without * a reciever. * * @return {Function} * @api private */ proto._setTemplate = function(fn) { return fn && fn.render ? util.bind(fn.render, fn) : fn; }; /** * Adds a child view(s) to another Module. * * Options: * * - `at` The child index at which to insert * - `inject` Injects the child's view element into the parent's * - `slot` The slot at which to insert the child * * @param {Module|Object} children * @param {Object|String|Number} options|slot */ proto.add = function(child, options) { if (!child) return this; // Options var at = options && options.at; var inject = options && options.inject; var slot = ('object' === typeof options) ? options.slot : options; // Remove this view first if it already has a parent if (child.parent) child.remove({ fromDOM: false }); // Assign a slot (prefering defined option) slot = child.slot = slot || child.slot; // Remove any module that already occupies this slot var resident = this.slots[slot]; if (resident) resident.remove({ fromDOM: false }); // If it's not a Module, make it one. if (!(child instanceof Module)) child = fm(child); util.insert(child, this.children, at); this._addLookup(child); // We append the child to the parent view if there is a view // element and the users hasn't flagged `append` false. if (inject) this._injectEl(child.el, options); // Allow chaining return this; }; /** * Removes a child view from * its current Module contexts * and also from the DOM unless * otherwise stated. * * Options: * * - `fromDOM` Whether the element should be removed from the DOM (default `true`) * * Example: * * // The following are equal * // apple is removed from the * // the view structure and DOM * layout.remove(apple); * apple.remove(); * * // Apple is removed from the * // view structure, but not the DOM * layout.remove(apple, { el: false }); * apple.remove({ el: false }); * * @return {FruitMachine} * @api public */ proto.remove = function(param1, param2) { // Don't do anything if the first arg is undefined if (arguments.length === 1 && !param1) return this; // Allow view.remove(child[, options]) // and view.remove([options]); if (param1 instanceof Module) { param1.remove(param2 || {}); return this; } // Options and aliases var options = param1 || {}; var fromDOM = options.fromDOM !== false; var parent = this.parent; var el = this.el; var parentNode = el && el.parentNode; var index; // Unless stated otherwise, // remove the view element // from its parent node. if (fromDOM && parentNode) { parentNode.removeChild(el); } if (parent) { // Remove reference from views array index = parent.children.indexOf(this); parent.children.splice(index, 1); // Remove references from the lookup parent._removeLookup(this); } return this; }; /** * Creates a lookup reference for * the child view passed. * * @param {Module} child * @api private */ proto._addLookup = function(child) { var module = child.module(); // Add a lookup for module (this._modules[module] = this._modules[module] || []).push(child); // Add a lookup for id this._ids[child.id()] = child; // Store a reference by slot if (child.slot) this.slots[child.slot] = child; child.parent = this; }; /** * Removes the lookup for the * the child view passed. * * @param {Module} child * @api private */ proto._removeLookup = function(child) { var module = child.module(); // Remove the module lookup var index = this._modules[module].indexOf(child); this._modules[module].splice(index, 1); // Remove the id and slot lookup delete this._ids[child._id]; delete this.slots[child.slot]; delete child.parent; }; /** * Injects an element into the * Module's root element. * * By default the element is appended. * * Options: * * - `at` The index at which to insert. * * @param {Element} el * @param {Object} options * @api private */ proto._injectEl = function(el, options) { var at = options && options.at; var parent = this.el; if (!el || !parent) return; if (typeof at !== 'undefined') { parent.insertBefore(el, parent.children[at]); } else { parent.appendChild(el); } }; /** * Returns a decendent module * by id, or if called with no * arguments, returns this view's id. * * Example: * * myModule.id(); * //=> 'my_view_id' * * myModule.id('my_other_views_id'); * //=> Module * * @param {String|undefined} id * @return {Module|String} * @api public */ proto.id = function(id) { if (!arguments.length) return this._id; var child = this._ids[id]; if (child) return child; return this.each(function(view) { return view.id(id); }); }; /** * Returns the first descendent * Module with the passed module type. * If called with no arguments the * Module's own module type is returned. * * Example: * * // Assuming 'myModule' has 3 descendent * // views with the module type 'apple' * * myModule.modules('apple'); * //=> Module * * @param {String} key * @return {Module} */ proto.module = function(key) { if (!arguments.length) return this._module || this.name; var view = this._modules[key]; if (view) return view[0]; return this.each(function(view) { return view.module(key); }); }; /** * Returns a list of descendent * Modules that match the module * type given (Similar to * Element.querySelectorAll();). * * Example: * * // Assuming 'myModule' has 3 descendent * // views with the module type 'apple' * * myModule.modules('apple'); * //=> [ Module, Module, Module ] * * @param {String} key * @return {Array} * @api public */ proto.modules = function(key) { var list = this._modules[key] || []; // Then loop each child and run the // same opperation, appending the result // onto the list. this.each(function(view) { list = list.concat(view.modules(key)); }); return list; }; /** * Calls the passed function * for each of the view's * children. * * Example: * * myModule.each(function(child) { * // Do stuff with each child view... * }); })(); }); require.define("/examples/express/client/page-home/index.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); var content = document.querySelector('.js-app_content'); var database = { title: 'This is the Home page' }; module.exports = function() { var view = new LayoutA(); view.child('apple') .data({ title: database.title }); view.render(); view.inject(content); }; }); require.define("/examples/express/client/layout-a/index.js",function(require,module,exports,__dirname,__filename,process,global){var FruitMachine = require('../../../../lib/fruitmachine'); var apple = require('../module-apple'); var template = require('./template'); * {{#children}} * {{{child}}} * {{/children}} * * @return {String} * @api public */ proto.toHTML = function() { var data = {}; }); }); require.define("/examples/express/client/module-apple/index.js",function(require,module,exports,__dirname,__filename,process,global){var FruitMachine = require('../../../../lib/fruitmachine.js'); var template = require('./template'); FruitMachine.templates({ apple: template }); }); require.define("/examples/express/client/module-apple/template.js",function(require,module,exports,__dirname,__filename,process,global){module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class=\"module-apple\" ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">");_.b("\n" + i);_.b(" <div class=\"module-apple_title\">");_.b(_.v(_.f("title",c,p,0)));_.b("</div>");_.b("\n" + i);_.b("</div>");return _.fl();;}); }); require.define("/examples/express/client/layout-a/template.js",function(require,module,exports,__dirname,__filename,process,global){module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class='layout-a' ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">");_.b("\n" + i);_.b(" <div class='layout-a_slot-1'>");_.b(_.t(_.f("my_apple",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" <div class='layout-a_region-1'>");_.b("\n" + i);_.b(" <div class='layout-a_slot-2'>");_.b(_.t(_.f("slot_2",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" <div class='layout-a_slot-3'>");_.b(_.t(_.f("slot_3",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" </div>");_.b("\n" + i);_.b("</div>");return _.fl();;}); }); require.define("/examples/express/client/page-about/index.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); var content = document.querySelector('.js-app_content'); var database = { title: 'This is the About page' }; module.exports = function() { var view = new LayoutA(); view.child('apple') .data({ title: database.title }); view.render(); view.inject(content); }; }); require.define("/examples/express/client/page-links/index.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); var content = document.querySelector('.js-app_content'); var database = { title: 'This is the Links page' }; module.exports = function() { var view = new LayoutA(); view.child('apple') .data({ title: database.title }); view.render(); view.inject(content); }; }); require.define("/examples/express/client/boot/index.js",function(require,module,exports,__dirname,__filename,process,global){Hogan = require('hogan.js/lib/template').Template; var FruitMachine = require('../../../lib/fruitmachine'); var routes = require('../routes'); * views. * * Setup will be aborted if no `view.el` }); require("/examples/express/client/boot/index.js"); })(); * * Options: * * - `shallow` Does not recurse when `true` (default `false`) * * @param {Object} options * @return {Module} */ proto.setup = function(options) { var shallow = options && options.shallow; // Attempt to fetch the view's // root element. Don't continue // if no route element is found. if (!this._getEl()) return this; // If this is already setup, call // `teardown` first so that we don't // duplicate event bindings and shizzle. if (this.isSetup) this.teardown({ shallow: true }); // Fire the `setup` event hook this.fireStatic('before setup'); if (this._setup) this._setup(); this.fireStatic('setup'); // Flag view as 'setup' this.isSetup = true; // Call 'setup' on all subviews // first (top down recursion) if (!shallow) { this.each(function(child) { child.setup(); }); } // For chaining return this; }; /** * Tearsdown a view and all descendent * views that have been setup. * * Your custom `teardown` method is * called and a `teardown` event is fired. * * Options: * * - `shallow` Does not recurse when `true` (default `false`) * * @param {Object} options * @return {Module} */ proto.teardown = function(options) { var shallow = options && options.shallow; // Call 'setup' on all subviews // first (bottom up recursion). if (!shallow) { this.each(function(child) { child.teardown(); }); } // Only teardown if this view // has been setup. Teardown // is supposed to undo all the // work setup does, and therefore // will likely run into undefined // variables if setup hasn't run. if (this.isSetup) { this.fireStatic('before teardown'); if (this._teardown) this._teardown(); this.fireStatic('teardown'); this.isSetup = false; } // For chaining return this; }; /** * Completely destroys a view. This means * a view is torn down, removed from it's * current layout context and removed * from the DOM. * * Your custom `destroy` method is * called and a `destroy` event is fired. * * NOTE: `.remove()` is only run on the view * that `.destroy()` is directly called on. * * Options: * * - `fromDOM` Whether the view should be removed from DOM (default `true`) * * @api public */ proto.destroy = function(options) { options = options || {}; var remove = options.remove !== false; var l = this.children.length; // Destroy each child view. // We don't waste time removing // the child elements as they will // get removed when the parent // element is removed. // // We can't use the standard Module#each() // as the array length gets altered // with each iteration, hense the // reverse while loop. while (l--) { this.children[l].destroy({ remove: false }); } // Don't continue if this view // has already been destroyed. if (this.destroyed) return this; // .remove() is only run on the view that // destroy() was called on. // // It is a waste of time to remove the // descendent views as well, as any // references to them will get wiped // within destroy and they will get // removed from the DOM with the main view. if (remove) this.remove(options); // Run teardown this.teardown({ shallow: true }); // Fire an event hook before the // custom destroy logic is run this.fireStatic('before destroy'); // If custom destroy logic has been // defined on the prototype then run it. if (this._destroy) this._destroy(); // Trigger a `destroy` event // for custom Modules to bind to. this.fireStatic('destroy'); // Unbind any old event listeners this.off(); // Set a flag to say this view // has been destroyed. This is // useful to check for after a // slow ajax call that might come // back after a view has been detroyed. this.destroyed = true; // Clear references this.el = this.model = this.parent = this._modules = this._ids = this._id = null; }; /** * Destroys all children. * * Is this needed? * * @return {Module} * @api public */ proto.empty = function() { var l = this.children.length; while (l--) this.children[l].destroy(); return this; }; /** * Fetches all descendant elements * from the given root element. * * @param {Element} root * @return {undefined} * @api private */ proto._fetchEls = function(root) { if (!root) return; this.each(function(child) { child.el = util.byId(child._fmid, root); child._fetchEls(child.el || root); }); }; /** * Returns the Module's root element. * * If a cache is present it is used, * else we search the DOM, else we * find the closest element and * perform a querySelector using * the view._fmid. * * @return {Element|undefined} * @api private */ proto._getEl = function() { if (!util.hasDom()) return; return this.el = this.el || document.getElementById(this._fmid); }; /** * Sets a root element on a view. * If the view already has a root * element, it is replaced. * * IMPORTANT: All descendent root * element caches are purged so that * the new correct elements are retrieved * next time Module#getElement is called. * * @param {Element} el * @return {Module} * @api private */ proto._setEl = function(el) { var existing = this.el; var parentNode = existing && existing.parentNode; // If the existing element has a context, replace it if (parentNode) parentNode.replaceChild(el, existing); // Update cache this.el = el; return this; }; /** * Empties the destination element * and appends the view into it. * * @param {Element} dest * @return {Module} * @api public */ proto.inject = function(dest) { if (dest) { dest.innerHTML = ''; this.appendTo(dest); this.fireStatic('inject'); } return this; }; /** * Appends the view element into * the destination element. * * @param {Element} dest * @return {Module} * @api public */ proto.appendTo = function(dest) { if (this.el && dest && dest.appendChild) { dest.appendChild(this.el); this.fireStatic('appendto'); } return this; }; /** * Returns a JSON represention of * a FruitMachine Module. This can * be generated serverside and * passed into new FruitMachine(json) * to inflate serverside rendered * views. * * @return {Object} * @api public */ proto.toJSON = function() { var json = {}; json.children = []; // Recurse this.each(function(child) { json.children.push(child.toJSON()); }); json.id = this.id(); json.fmid = this._fmid; json.module = this.module(); json.model = this.model.toJSON(); json.slot = this.slot; // Fire a hook to allow third // parties to alter the json output this.fireStatic('tojson', json); return json; }; // Events proto.on = events.on; proto.off = events.off; proto.fire = events.fire; proto.fireStatic = events.fireStatic; // Allow Modules to be extended Module.extend = extend(util.keys(proto)); // Adding proto.Model after // Module.extend means this // key can be overwritten. proto.Model = fm.Model; return Module; }; },{"./events":23,"utils":16,"extend":24}],18:[function(require,module,exports){ /** * Module Dependencies */ var fm = require('../../../../lib/'); var template = require('./template'); /** * Exports */ module.exports = fm.define({ module: 'layout-a', template: template }); },{"./template":25,"../../../../lib/":2}],19:[function(require,module,exports){ /** * Module Dependencies */ var fm = require('../../../../lib/'); var template = require('./template'); /** * Exports */ module.exports = fm.define({ module: 'apple', template: template }); },{"./template":26,"../../../../lib/":2}],20:[function(require,module,exports){ /** * Module Dependencies */ var fm = require('../../../../lib/'); var template = require('./template'); /** * Exports */ module.exports = fm.define({ module: 'orange', template: template }); },{"./template":27,"../../../../lib/":2}],21:[function(require,module,exports){ /** * Module Dependencies */ var fm = require('../../../../lib/'); var template = require('./template'); /** * Exports */ module.exports = fm.define({ module: 'banana', template: template }); },{"./template":28,"../../../../lib/":2}],25:[function(require,module,exports){ module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class='layout-a' ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">");_.b("\n" + i);_.b(" <div class='layout-a_slot-1'>");_.b(_.t(_.f("slot_1",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" <div class='layout-a_region-1'>");_.b("\n" + i);_.b(" <div class='layout-a_slot-2'>");_.b(_.t(_.f("slot_2",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" <div class='layout-a_slot-3'>");_.b(_.t(_.f("slot_3",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" </div>");_.b("\n" + i);_.b("</div>");return _.fl();;}); },{}],26:[function(require,module,exports){ module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class=\"module-apple\" ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">");_.b("\n" + i);_.b(" <div class=\"module-apple_title\">");_.b(_.v(_.f("title",c,p,0)));_.b("</div>");_.b("\n" + i);_.b("</div>");return _.fl();;}); },{}],27:[function(require,module,exports){ module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class='module-orange' ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">Module Orange</div>");return _.fl();;}); },{}],28:[function(require,module,exports){ module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class='module-banana' ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">Module Banana</div>");return _.fl();;}); },{}],23:[function(require,module,exports){ /** * Module Dependencies */ var events = require('event'); /** * Exports */ /** * Registers a event listener. * * @param {String} name * @param {String} module * @param {Function} cb * @return {View} */ exports.on = function(name, module, cb) { // cb can be passed as // the second or third argument if (arguments.length === 2) { cb = module; module = null; } // if a module is provided // pass in a special callback // function that checks the // module if (module) { events.prototype.on.call(this, name, function() { if (this.event.target.module() === module) { cb.apply(this, arguments); } }); } else { events.prototype.on.call(this, name, cb); } return this; }; /** * Fires an event on a view. * * @param {String} name * @return {View} */ exports.fire = function(name) { var parent = this.parent; var _event = this.event; var event = { target: this, propagate: true, stopPropagation: function(){ this.propagate = false; } }; propagate(this, arguments, event); // COMPLEX: // If an earlier event object was // cached, restore the the event // back onto the view. If there // wasn't an earlier event, make // sure the `event` key has been // deleted off the view. if (_event) this.event = _event; else delete this.event; // Allow chaining return this; }; function propagate(view, args, event) { if (!view || !event.propagate) return; view.event = event; events.prototype.fire.apply(view, args); propagate(view.parent, args, event); } exports.fireStatic = events.prototype.fire; exports.off = events.prototype.off; },{"event":17}],24:[function(require,module,exports){ /*jshint browser:true, node:true*/ 'use strict'; /** * Module Dependencies */ var mixin = require('utils').mixin; /** * Exports */ module.exports = function(keys) { return function(proto) { var parent = this; var child = function(){ return parent.apply(this, arguments); }; // Mixin static properties // eg. View.extend. mixin(child, parent); // Make sure there are no // keys conflicting with // the prototype. if (keys) protect(keys, proto); // Set the prototype chain to // inherit from `parent`, without // calling `parent`'s constructor function. function C() { this.constructor = child; } C.prototype = parent.prototype; child.prototype = new C(); // Add prototype properties mixin(child.prototype, proto); // Set a convenience property // in case the parent's prototype // is needed later. child.__super__ = parent.prototype; return child; }; }; /** * Makes sure no properties * or methods can be overwritten * on the core View.prototype. * * If conflicting keys are found, * we create a new key prifixed with * a '_' and delete the original key. * * @param {Array} keys * @param {Object} ob * @return {[type]} */ function protect(keys, ob) { for (var key in ob) { if (ob.hasOwnProperty(key) && ~keys.indexOf(key)) { ob['_' + key] = ob[key]; delete ob[key]; } } } },{"utils":16}]},{},[1]) ; <MSG> Merged server and client dirs to form 'lib' <DFF> @@ -1326,10 +1326,10 @@ require.define("/lib/fruitmachine.js",function(require,module,exports,__dirname, }()); }); -require.define("/examples/express/client/routes/index.js",function(require,module,exports,__dirname,__filename,process,global){var page = require('../page-js'); -var home = require('../page-home'); -var about = require('../page-about'); -var links = require('../page-links'); +require.define("/examples/express/lib/routes/index.js",function(require,module,exports,__dirname,__filename,process,global){var page = require('../pagejs'); +var home = require('../page-home/client'); +var about = require('../page-about/client'); +var links = require('../page-links/client'); page('/', home); page('/about', about); @@ -1338,7 +1338,7 @@ page('/links', links); page({ dispatch: false }); }); -require.define("/examples/express/client/page-js/index.js",function(require,module,exports,__dirname,__filename,process,global){;(function(){ +require.define("/examples/express/lib/pagejs/index.js",function(require,module,exports,__dirname,__filename,process,global){;(function(){ /** * Perform initial dispatch. @@ -1754,25 +1754,33 @@ require.define("/examples/express/client/page-js/index.js",function(require,modu })(); }); -require.define("/examples/express/client/page-home/index.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); -var content = document.querySelector('.js-app_content'); +require.define("/examples/express/lib/page-home/client.js",function(require,module,exports,__dirname,__filename,process,global){var content = document.querySelector('.js-app_content'); +var View = require('./view'); var database = { title: 'This is the Home page' }; module.exports = function() { + var view = View(database); + view.render(); + view.inject(content); +}; +}); + +require.define("/examples/express/lib/page-home/view.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); + +module.exports = function(data) { var view = new LayoutA(); view.child('apple') - .data({ title: database.title }); + .data({ title: data.title }); - view.render(); - view.inject(content); + return view; }; }); -require.define("/examples/express/client/layout-a/index.js",function(require,module,exports,__dirname,__filename,process,global){var FruitMachine = require('../../../../lib/fruitmachine'); +require.define("/examples/express/lib/layout-a/index.js",function(require,module,exports,__dirname,__filename,process,global){var FruitMachine = require('../../../../lib/fruitmachine'); var apple = require('../module-apple'); var template = require('./template'); @@ -1788,54 +1796,70 @@ module.exports = FruitMachine.module('layout-a', { }); }); -require.define("/examples/express/client/module-apple/index.js",function(require,module,exports,__dirname,__filename,process,global){var FruitMachine = require('../../../../lib/fruitmachine.js'); +require.define("/examples/express/lib/module-apple/index.js",function(require,module,exports,__dirname,__filename,process,global){var FruitMachine = require('../../../../lib/fruitmachine.js'); var template = require('./template'); FruitMachine.templates({ apple: template }); }); -require.define("/examples/express/client/module-apple/template.js",function(require,module,exports,__dirname,__filename,process,global){module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class=\"module-apple\" ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">");_.b("\n" + i);_.b(" <div class=\"module-apple_title\">");_.b(_.v(_.f("title",c,p,0)));_.b("</div>");_.b("\n" + i);_.b("</div>");return _.fl();;}); +require.define("/examples/express/lib/module-apple/template.js",function(require,module,exports,__dirname,__filename,process,global){module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class=\"module-apple\" ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">");_.b("\n" + i);_.b(" <div class=\"module-apple_title\">");_.b(_.v(_.f("title",c,p,0)));_.b("</div>");_.b("\n" + i);_.b("</div>");return _.fl();;}); }); -require.define("/examples/express/client/layout-a/template.js",function(require,module,exports,__dirname,__filename,process,global){module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class='layout-a' ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">");_.b("\n" + i);_.b(" <div class='layout-a_slot-1'>");_.b(_.t(_.f("my_apple",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" <div class='layout-a_region-1'>");_.b("\n" + i);_.b(" <div class='layout-a_slot-2'>");_.b(_.t(_.f("slot_2",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" <div class='layout-a_slot-3'>");_.b(_.t(_.f("slot_3",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" </div>");_.b("\n" + i);_.b("</div>");return _.fl();;}); +require.define("/examples/express/lib/layout-a/template.js",function(require,module,exports,__dirname,__filename,process,global){module.exports = new Hogan(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class='layout-a' ");_.b(_.t(_.f("fm_attrs",c,p,0)));_.b(">");_.b("\n" + i);_.b(" <div class='layout-a_slot-1'>");_.b(_.t(_.f("my_apple",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" <div class='layout-a_region-1'>");_.b("\n" + i);_.b(" <div class='layout-a_slot-2'>");_.b(_.t(_.f("slot_2",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" <div class='layout-a_slot-3'>");_.b(_.t(_.f("slot_3",c,p,0)));_.b("</div>");_.b("\n" + i);_.b(" </div>");_.b("\n" + i);_.b("</div>");return _.fl();;}); }); -require.define("/examples/express/client/page-about/index.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); -var content = document.querySelector('.js-app_content'); +require.define("/examples/express/lib/page-about/client.js",function(require,module,exports,__dirname,__filename,process,global){var content = document.querySelector('.js-app_content'); +var View = require('./view'); var database = { title: 'This is the About page' }; module.exports = function() { + var view = View(database); + view.render(); + view.inject(content); +}; +}); + +require.define("/examples/express/lib/page-about/view.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); + +module.exports = function(data) { var view = new LayoutA(); view.child('apple') - .data({ title: database.title }); + .data({ title: data.title }); - view.render(); - view.inject(content); + return view; }; }); -require.define("/examples/express/client/page-links/index.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); -var content = document.querySelector('.js-app_content'); +require.define("/examples/express/lib/page-links/client.js",function(require,module,exports,__dirname,__filename,process,global){var content = document.querySelector('.js-app_content'); +var View = require('./view'); var database = { title: 'This is the Links page' }; module.exports = function() { + var view = View(database); + view.render(); + view.inject(content); +}; +}); + +require.define("/examples/express/lib/page-links/view.js",function(require,module,exports,__dirname,__filename,process,global){var LayoutA = require('../layout-a'); + +module.exports = function(data) { var view = new LayoutA(); view.child('apple') - .data({ title: database.title }); + .data({ title: data.title }); - view.render(); - view.inject(content); + return view; }; }); -require.define("/examples/express/client/boot/index.js",function(require,module,exports,__dirname,__filename,process,global){Hogan = require('hogan.js/lib/template').Template; +require.define("/examples/express/lib/boot/index.js",function(require,module,exports,__dirname,__filename,process,global){Hogan = require('hogan.js/lib/template').Template; var FruitMachine = require('../../../lib/fruitmachine'); var routes = require('../routes'); @@ -1845,5 +1869,5 @@ view = new FruitMachine(window.layout); }); -require("/examples/express/client/boot/index.js"); +require("/examples/express/lib/boot/index.js"); })();
50
Merged server and client dirs to form 'lib'
26
.js
js
mit
ftlabs/fruitmachine
10067091
<NME> README.md <BEF> # FruitMachine [![Build Status](https://api.travis-ci.com/ftlabs/fruitmachine.svg)](https://travis-ci.com/ftlabs/fruitmachine) [![Coverage Status](https://coveralls.io/repos/ftlabs/fruitmachine/badge.png)](https://coveralls.io/r/ftlabs/fruitmachine) A lightweight component layout engine for client and server. FruitMachine is designed to build rich interactive layouts from modular, reusable components. It's light and unopinionated so that it can be applied to almost any layout problem. FruitMachine is currently powering the [FT Web App](http://apps.ft.com/ftwebapp/). ```js // Define a module ### create(); <p>Creates a new FruitMachine view<br />using the options passed.</p> ### View#trigger(); <p>Proxies the standard Event.trigger<br />method so that we can add bubble<br />functionality.</p> ### View#id(); <p>Returns a decendent module<br />by id, or if called with no<br />arguments, returns this view's id.</p> ### View#child(); <p>Returns the first child<br />view that matches the query.</p> ### View#children(); <p>Allows three ways to return<br />a view's children and direct<br />children, depending on arguments<br />passed.</p> ### View#each(); <p>Calls the passed function<br />for each of the view's<br />children.</p> ### View#remove(); <p>Removes the View's element<br />from the DOM.</p> ### View#empty(); [built]: http://wzrd.in/standalone/fruitmachine@latest ### View#closestElement(); <p>Returns the closest root view<br />element, walking up the chain<br />until it finds one.</p> ### View#getElement(); ### View#setElement(); <p>Sets a root element on a view.<br />If the view already has a root<br />element, it is replaced.</p> ### View#purgeElementCaches(); <p>Recursively purges the<br />element cache.</p> ### View#data(); <p>A single method for getting<br />and setting view data.</p> ### View#inDOM(); <p>Detects whether a view is in<br />the DOM (useful for debugging).</p> ### View#toNode(); <p>Templates the whole view and turns<br />it into a real node.</p> ### View#inject(); <p>Empties the destination element<br />and appends the view into it.</p> ### View#appendTo(); <p>Appends the view element into<br />the destination element.</p> ### View#toJSON(); <p>Returns a JSON represention of<br />a FruitMachine View. This can<br />be generated serverside and<br />passed into new FruitMachine(json)<br />to inflate serverside rendered<br />views.</p> ### Model#get(); ### module(); <p>Creates and registers a<br />FruitMachine view constructor.</p> ### clear(); <p>Removes a module<br />from the module store.</p> ### helper(); Licensed under the MIT license. ### clear(); <p>Clears one or all<br />registered helpers.</p> ### templates(); <p>Registers templates, or overwrites<br />the <code>getTemplate</code> method with a<br />custom template getter function.</p> ### getTemplate(); <p>The default get template method<br />if FruitMachine.template is passed<br />a function, this gets overwritten<br />by that.</p> ### clear(); <p>Clear reference to a module's<br />template, or clear all template<br />references and resets the template<br />getter method.</p> ### FruitMachine(); <p>The main library namespace doubling<br />as a convenient alias for creating<br />new views.</p> ## License <MSG> Remove line breaks from summary <DFF> @@ -9,31 +9,31 @@ Assembles dynamic views on the client and server. ### create(); -<p>Creates a new FruitMachine view<br />using the options passed.</p> +<p>Creates a new FruitMachine view using the options passed.</p> ### View#trigger(); -<p>Proxies the standard Event.trigger<br />method so that we can add bubble<br />functionality.</p> +<p>Proxies the standard Event.trigger method so that we can add bubble functionality.</p> ### View#id(); -<p>Returns a decendent module<br />by id, or if called with no<br />arguments, returns this view's id.</p> +<p>Returns a decendent module by id, or if called with no arguments, returns this view's id.</p> ### View#child(); -<p>Returns the first child<br />view that matches the query.</p> +<p>Returns the first child view that matches the query.</p> ### View#children(); -<p>Allows three ways to return<br />a view's children and direct<br />children, depending on arguments<br />passed.</p> +<p>Allows three ways to return a view's children and direct children, depending on arguments passed.</p> ### View#each(); -<p>Calls the passed function<br />for each of the view's<br />children.</p> +<p>Calls the passed function for each of the view's children.</p> ### View#remove(); -<p>Removes the View's element<br />from the DOM.</p> +<p>Removes the View's element from the DOM.</p> ### View#empty(); @@ -41,7 +41,7 @@ Assembles dynamic views on the client and server. ### View#closestElement(); -<p>Returns the closest root view<br />element, walking up the chain<br />until it finds one.</p> +<p>Returns the closest root view element, walking up the chain until it finds one.</p> ### View#getElement(); @@ -49,35 +49,35 @@ Assembles dynamic views on the client and server. ### View#setElement(); -<p>Sets a root element on a view.<br />If the view already has a root<br />element, it is replaced.</p> +<p>Sets a root element on a view. If the view already has a root element, it is replaced.</p> ### View#purgeElementCaches(); -<p>Recursively purges the<br />element cache.</p> +<p>Recursively purges the element cache.</p> ### View#data(); -<p>A single method for getting<br />and setting view data.</p> +<p>A single method for getting and setting view data.</p> ### View#inDOM(); -<p>Detects whether a view is in<br />the DOM (useful for debugging).</p> +<p>Detects whether a view is in the DOM (useful for debugging).</p> ### View#toNode(); -<p>Templates the whole view and turns<br />it into a real node.</p> +<p>Templates the whole view and turns it into a real node.</p> ### View#inject(); -<p>Empties the destination element<br />and appends the view into it.</p> +<p>Empties the destination element and appends the view into it.</p> ### View#appendTo(); -<p>Appends the view element into<br />the destination element.</p> +<p>Appends the view element into the destination element.</p> ### View#toJSON(); -<p>Returns a JSON represention of<br />a FruitMachine View. This can<br />be generated serverside and<br />passed into new FruitMachine(json)<br />to inflate serverside rendered<br />views.</p> +<p>Returns a JSON represention of a FruitMachine View. This can be generated serverside and passed into new FruitMachine(json) to inflate serverside rendered views.</p> ### Model#get(); @@ -85,11 +85,11 @@ Assembles dynamic views on the client and server. ### module(); -<p>Creates and registers a<br />FruitMachine view constructor.</p> +<p>Creates and registers a FruitMachine view constructor.</p> ### clear(); -<p>Removes a module<br />from the module store.</p> +<p>Removes a module from the module store.</p> ### helper(); @@ -97,23 +97,23 @@ Assembles dynamic views on the client and server. ### clear(); -<p>Clears one or all<br />registered helpers.</p> +<p>Clears one or all registered helpers.</p> ### templates(); -<p>Registers templates, or overwrites<br />the <code>getTemplate</code> method with a<br />custom template getter function.</p> +<p>Registers templates, or overwrites the <code>getTemplate</code> method with a custom template getter function.</p> ### getTemplate(); -<p>The default get template method<br />if FruitMachine.template is passed<br />a function, this gets overwritten<br />by that.</p> +<p>The default get template method if FruitMachine.template is passed a function, this gets overwritten by that.</p> ### clear(); -<p>Clear reference to a module's<br />template, or clear all template<br />references and resets the template<br />getter method.</p> +<p>Clear reference to a module's template, or clear all template references and resets the template getter method.</p> ### FruitMachine(); -<p>The main library namespace doubling<br />as a convenient alias for creating<br />new views.</p> +<p>The main library namespace doubling as a convenient alias for creating new views.</p> ## License
23
Remove line breaks from summary
23
.md
md
mit
ftlabs/fruitmachine
10067092
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067093
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067094
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067095
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067096
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067097
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067098
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067099
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067100
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067101
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067102
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067103
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067104
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067105
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067106
<NME> AvaloniaEdit.props <BEF> ADDFILE <MSG> Put language version in props file. <DFF> @@ -0,0 +1,5 @@ +ο»Ώ<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LangVersion>7.1</LangVersion> + </PropertyGroup> +</Project> \ No newline at end of file
5
Put language version in props file.
0
.props
props
mit
AvaloniaUI/AvaloniaEdit
10067107
<NME> README.md <BEF> # LoadJS <img src="https://www.muicss.com/static/images/loadjs.svg" width="250px"> LoadJS is a tiny async loader for modern browsers (590 bytes). [![Build Status](https://travis-ci.org/muicss/loadjs.svg?branch=master)](https://travis-ci.org/muicss/loadjs) [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs#info=devDependencies) ## Introduction LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript, CSS and image files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code of [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) in your &lt;html&gt; (possibly in the &lt;head&gt; tag) and then use the `loadjs` global to manage JavaScript dependencies after pageload. LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 899 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle and execute code when it loads loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); </script> ``` You can also use more advanced syntax for more options: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle with advanced options loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: function(path, scriptEl) { /* execute code before fetch */ }, async: true, // load files synchronously or asynchronously (default: true) numRetries: 3 // see caveats about using numRetries with async:false (default: 0), returnPromise: false // return Promise object (default: false) }); loadjs.ready('foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(depsNotFound) { /* foobar bundle load failed */ }, }); </script> ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js) (for development) * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js) (for production) It's also available from these public CDNs: * UNPKG * [https://unpkg.com/[email protected]/dist/loadjs.js](https://unpkg.com/[email protected]/dist/loadjs.js) (for development) * [https://unpkg.com/[email protected]/dist/loadjs.min.js](https://unpkg.com/[email protected]/dist/loadjs.min.js) (for production) * CDNJS * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js) (for development) * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js) (for production) You can also use it as a CJS or AMD module: ```bash $ npm install --save loadjs ``` ```javascript var loadjs = require('loadjs'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` ## Browser Support * IE9+ (`async: false` support only works in IE10+) * Opera 12+ * Safari 5+ * Chrome * Firefox * iOS 6+ * Android 4.4+ LoadJS also detects script load failures from AdBlock Plus and Ghostery in: * Safari * Chrome Note: LoadJS treats empty CSS files as load failures in IE9-11 and uses `rel="preload"` to load CSS files in Edge (to get around lack of support for onerror events on `<link rel="stylesheet">` tags) ## Documentation 1. Load a single file ```javascript loadjs('/path/to/foo.js', function() { /* foo.js loaded */ }); ``` 1. Fetch files in parallel and load them asynchronously ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() { }); ``` ## Development Dependencies * nodejs (http://nodejs.org/) * npm (https://www.npmjs.org/) ## Directory structure <pre> ```javascript loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() { /* foo.css, bar.png and thunk.js loaded */ }); ``` 1. Force treat file as CSS stylesheet ```javascript loadjs(['css!/path/to/cssfile.custom'], function() { /* cssfile.custom loaded as stylesheet */ | └── loadjs.js β”œβ”€β”€ test/ </pre> }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Use Promises to register callbacks ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true}) .then(function() { /* foo.js & bar.js loaded */ }) .catch(function(pathsNotFound) { /* at least one didn't load */ }); ``` 1. Check if bundle has already been defined ```javascript if (!loadjs.isDefined('foobar')) { loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() { /* foo.js and bar.js loaded in series */ }, async: false }); ``` 1. Add an error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ } }); ``` 1. Retry files before calling the error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ }, numRetries: 3 }); // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries ``` 1. Execute a callback before script tags are embedded ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { /* called for each script node before being embedded */ if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; } }); ``` 1. Bypass LoadJS default DOM insertion mechanism (DOM `<head>`) ```javascript loadjs(['/path/to/foo.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { document.body.appendChild(scriptEl); /* return `false` to bypass default DOM insertion mechanism */ return false; } }); ``` 1. Use bundle ids in error callback ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs(['/path/to/thunkor.js', '/path/to/thunky.js'], 'thunk'); // wait for multiple depdendencies loadjs.ready(['foo', 'bar', 'thunk'], { success: function() { // foo.js & bar.js & thunkor.js & thunky.js loaded }, error: function(depsNotFound) { if (depsNotFound.indexOf('foo') > -1) {}; // foo failed if (depsNotFound.indexOf('bar') > -1) {}; // bar failed if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed } }); ``` 1. Use .done() for more control ```javascript loadjs.ready(['dependency1', 'dependency2'], function() { /* run code after dependencies have been met */ }); function fn1() { loadjs.done('dependency1'); } function fn2() { loadjs.done('dependency2'); } ``` 1. Reset dependency trackers ```javascript loadjs.reset(); ``` 1. Implement a require-like dependency manager ```javascript var bundles = { 'bundleA': ['/file1.js', '/file2.js'], 'bundleB': ['/file3.js', '/file4.js'] }; function require(bundleIds, callbackFn) { bundleIds.forEach(function(bundleId) { if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId); }); loadjs.ready(bundleIds, callbackFn); } require(['bundleA'], function() { /* bundleA loaded */ }); require(['bundleB'], function() { /* bundleB loaded */ }); require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ }); ``` ## Directory structure <pre> loadjs/ β”œβ”€β”€ dist β”‚Β Β  β”œβ”€β”€ loadjs.js β”‚Β Β  β”œβ”€β”€ loadjs.min.js β”‚Β Β  └── loadjs.umd.js β”œβ”€β”€ examples β”œβ”€β”€ gulpfile.js β”œβ”€β”€ LICENSE.txt β”œβ”€β”€ package.json β”œβ”€β”€ README.md β”œβ”€β”€ src β”‚Β Β  └── loadjs.js β”œβ”€β”€ test └── umd-templates </pre> ## Development Quickstart 1. Install dependencies * [nodejs](http://nodejs.org/) * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository ```bash $ git clone [email protected]:muicss/loadjs.git $ cd loadjs ``` 1. Install node dependencies using npm ```bash $ npm install ``` 1. Build examples ```bash $ npm run build-examples ``` To view the examples you can use any static file server. To use the `nodejs` http-server module: ```bash $ npm install http-server $ npm run http-server -- -p 3000 ``` Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files ```bash $ npm run build-dist ``` The files will be located in the `dist` directory. 1. Run tests To run the browser tests first build the `loadjs` library: ```bash $ npm run build-tests ``` Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files ```bash $ npm run build-all ``` <MSG> Merge branch 'master' of github.com:muicss/loadjs <DFF> @@ -4,7 +4,6 @@ LoadJS is a tiny async loader for modern browsers (590 bytes). -[![Build Status](https://travis-ci.org/muicss/loadjs.svg?branch=master)](https://travis-ci.org/muicss/loadjs) [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs#info=devDependencies) @@ -111,11 +110,6 @@ loadjs.ready('jquery', function() { }); ``` -## Development Dependencies - - * nodejs (http://nodejs.org/) - * npm (https://www.npmjs.org/) - ## Directory structure <pre> @@ -133,3 +127,49 @@ loadjs/ | └── loadjs.js β”œβ”€β”€ test/ </pre> + +## Development Quickstart + +1. Install dependencies + + * nodejs (http://nodejs.org/) + * npm (https://www.npmjs.org/) + * http-server (via npm) + +1. Clone repository + + ```bash + $ git clone [email protected]:muicss/loadjs.git + $ cd loadjs + ``` + +1. Install node dependencies using npm + + ```bash + $ npm install + ``` + +1. Build examples + + ```bash + $ ./node_modules/.bin/gulp build-examples + ``` + + To view the examples you can use any static file server. To use the `nodejs` http-server module: + + ```bash + $ npm install http-server + $ ./node_modules/.bin/http-server -p 3000 + ``` + + Then visit http://localhost:3000/examples + +## Run tests + +To run the browser tests first build the `loadjs` library: + +```bash +$ ./node_modules/.bin/gulp build-test +``` + +Then visit http://localhost:3000/test
46
Merge branch 'master' of github.com:muicss/loadjs
6
.md
md
mit
muicss/loadjs
10067108
<NME> README.md <BEF> # LoadJS <img src="https://www.muicss.com/static/images/loadjs.svg" width="250px"> LoadJS is a tiny async loader for modern browsers (590 bytes). [![Build Status](https://travis-ci.org/muicss/loadjs.svg?branch=master)](https://travis-ci.org/muicss/loadjs) [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs#info=devDependencies) ## Introduction LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript, CSS and image files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code of [loadjs.js](https://raw.githubusercontent.com/muicss/loadjs/master/dist/loadjs.min.js) in your &lt;html&gt; (possibly in the &lt;head&gt; tag) and then use the `loadjs` global to manage JavaScript dependencies after pageload. LoadJS is based on the excellent [$script](https://github.com/ded/script.js) library by [Dustin Diaz](https://github.com/ded). We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 899 bytes (minified + gzipped). Here's an example of what you can do with LoadJS: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle and execute code when it loads loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); </script> ``` You can also use more advanced syntax for more options: ```html <script src="//unpkg.com/loadjs@latest/dist/loadjs.min.js"></script> <script> // define a dependency bundle with advanced options loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: function(path, scriptEl) { /* execute code before fetch */ }, async: true, // load files synchronously or asynchronously (default: true) numRetries: 3 // see caveats about using numRetries with async:false (default: 0), returnPromise: false // return Promise object (default: false) }); loadjs.ready('foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(depsNotFound) { /* foobar bundle load failed */ }, }); </script> ``` The latest version of LoadJS can be found in the `dist/` directory in this repository: * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.js) (for development) * [https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js](https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js) (for production) It's also available from these public CDNs: * UNPKG * [https://unpkg.com/[email protected]/dist/loadjs.js](https://unpkg.com/[email protected]/dist/loadjs.js) (for development) * [https://unpkg.com/[email protected]/dist/loadjs.min.js](https://unpkg.com/[email protected]/dist/loadjs.min.js) (for production) * CDNJS * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.js) (for development) * [https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js](https://cdnjs.cloudflare.com/ajax/libs/loadjs/4.2.0/loadjs.min.js) (for production) You can also use it as a CJS or AMD module: ```bash $ npm install --save loadjs ``` ```javascript var loadjs = require('loadjs'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); loadjs.ready('foobar', function() { /* foo.js & bar.js loaded */ }); ``` ## Browser Support * IE9+ (`async: false` support only works in IE10+) * Opera 12+ * Safari 5+ * Chrome * Firefox * iOS 6+ * Android 4.4+ LoadJS also detects script load failures from AdBlock Plus and Ghostery in: * Safari * Chrome Note: LoadJS treats empty CSS files as load failures in IE9-11 and uses `rel="preload"` to load CSS files in Edge (to get around lack of support for onerror events on `<link rel="stylesheet">` tags) ## Documentation 1. Load a single file ```javascript loadjs('/path/to/foo.js', function() { /* foo.js loaded */ }); ``` 1. Fetch files in parallel and load them asynchronously ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], function() { }); ``` ## Development Dependencies * nodejs (http://nodejs.org/) * npm (https://www.npmjs.org/) ## Directory structure <pre> ```javascript loadjs(['/path/to/foo.css', '/path/to/bar.png', 'path/to/thunk.js'], function() { /* foo.css, bar.png and thunk.js loaded */ }); ``` 1. Force treat file as CSS stylesheet ```javascript loadjs(['css!/path/to/cssfile.custom'], function() { /* cssfile.custom loaded as stylesheet */ | └── loadjs.js β”œβ”€β”€ test/ </pre> }) .ready('bar', function() { /* bar.js loaded */ }); ``` 1. Use Promises to register callbacks ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], {returnPromise: true}) .then(function() { /* foo.js & bar.js loaded */ }) .catch(function(pathsNotFound) { /* at least one didn't load */ }); ``` 1. Check if bundle has already been defined ```javascript if (!loadjs.isDefined('foobar')) { loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', function() { /* foo.js & bar.js loaded */ }); } ``` 1. Fetch files in parallel and load them in series ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() { /* foo.js and bar.js loaded in series */ }, async: false }); ``` 1. Add an error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ } }); ``` 1. Retry files before calling the error callback ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { success: function() { /* foo.js & bar.js loaded */ }, error: function(pathsNotFound) { /* at least one path didn't load */ }, numRetries: 3 }); // NOTE: Using `numRetries` with `async: false` can cause files to load out-of-sync on retries ``` 1. Execute a callback before script tags are embedded ```javascript loadjs(['/path/to/foo.js', '/path/to/bar.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { /* called for each script node before being embedded */ if (path === '/path/to/foo.js') scriptEl.crossOrigin = true; } }); ``` 1. Bypass LoadJS default DOM insertion mechanism (DOM `<head>`) ```javascript loadjs(['/path/to/foo.js'], { success: function() {}, error: function(pathsNotFound) {}, before: function(path, scriptEl) { document.body.appendChild(scriptEl); /* return `false` to bypass default DOM insertion mechanism */ return false; } }); ``` 1. Use bundle ids in error callback ```javascript loadjs('/path/to/foo.js', 'foo'); loadjs('/path/to/bar.js', 'bar'); loadjs(['/path/to/thunkor.js', '/path/to/thunky.js'], 'thunk'); // wait for multiple depdendencies loadjs.ready(['foo', 'bar', 'thunk'], { success: function() { // foo.js & bar.js & thunkor.js & thunky.js loaded }, error: function(depsNotFound) { if (depsNotFound.indexOf('foo') > -1) {}; // foo failed if (depsNotFound.indexOf('bar') > -1) {}; // bar failed if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed } }); ``` 1. Use .done() for more control ```javascript loadjs.ready(['dependency1', 'dependency2'], function() { /* run code after dependencies have been met */ }); function fn1() { loadjs.done('dependency1'); } function fn2() { loadjs.done('dependency2'); } ``` 1. Reset dependency trackers ```javascript loadjs.reset(); ``` 1. Implement a require-like dependency manager ```javascript var bundles = { 'bundleA': ['/file1.js', '/file2.js'], 'bundleB': ['/file3.js', '/file4.js'] }; function require(bundleIds, callbackFn) { bundleIds.forEach(function(bundleId) { if (!loadjs.isDefined(bundleId)) loadjs(bundles[bundleId], bundleId); }); loadjs.ready(bundleIds, callbackFn); } require(['bundleA'], function() { /* bundleA loaded */ }); require(['bundleB'], function() { /* bundleB loaded */ }); require(['bundleA', 'bundleB'], function() { /* bundleA and bundleB loaded */ }); ``` ## Directory structure <pre> loadjs/ β”œβ”€β”€ dist β”‚Β Β  β”œβ”€β”€ loadjs.js β”‚Β Β  β”œβ”€β”€ loadjs.min.js β”‚Β Β  └── loadjs.umd.js β”œβ”€β”€ examples β”œβ”€β”€ gulpfile.js β”œβ”€β”€ LICENSE.txt β”œβ”€β”€ package.json β”œβ”€β”€ README.md β”œβ”€β”€ src β”‚Β Β  └── loadjs.js β”œβ”€β”€ test └── umd-templates </pre> ## Development Quickstart 1. Install dependencies * [nodejs](http://nodejs.org/) * [npm](https://www.npmjs.org/) * http-server (via npm) 1. Clone repository ```bash $ git clone [email protected]:muicss/loadjs.git $ cd loadjs ``` 1. Install node dependencies using npm ```bash $ npm install ``` 1. Build examples ```bash $ npm run build-examples ``` To view the examples you can use any static file server. To use the `nodejs` http-server module: ```bash $ npm install http-server $ npm run http-server -- -p 3000 ``` Then visit [http://localhost:3000/examples](http://localhost:3000/examples) 1. Build distribution files ```bash $ npm run build-dist ``` The files will be located in the `dist` directory. 1. Run tests To run the browser tests first build the `loadjs` library: ```bash $ npm run build-tests ``` Then visit [http://localhost:3000/test](http://localhost:3000/test) 1. Build all files ```bash $ npm run build-all ``` <MSG> Merge branch 'master' of github.com:muicss/loadjs <DFF> @@ -4,7 +4,6 @@ LoadJS is a tiny async loader for modern browsers (590 bytes). -[![Build Status](https://travis-ci.org/muicss/loadjs.svg?branch=master)](https://travis-ci.org/muicss/loadjs) [![Dependency Status](https://david-dm.org/muicss/loadjs.svg)](https://david-dm.org/muicss/loadjs) [![devDependency Status](https://david-dm.org/muicss/loadjs/dev-status.svg)](https://david-dm.org/muicss/loadjs#info=devDependencies) @@ -111,11 +110,6 @@ loadjs.ready('jquery', function() { }); ``` -## Development Dependencies - - * nodejs (http://nodejs.org/) - * npm (https://www.npmjs.org/) - ## Directory structure <pre> @@ -133,3 +127,49 @@ loadjs/ | └── loadjs.js β”œβ”€β”€ test/ </pre> + +## Development Quickstart + +1. Install dependencies + + * nodejs (http://nodejs.org/) + * npm (https://www.npmjs.org/) + * http-server (via npm) + +1. Clone repository + + ```bash + $ git clone [email protected]:muicss/loadjs.git + $ cd loadjs + ``` + +1. Install node dependencies using npm + + ```bash + $ npm install + ``` + +1. Build examples + + ```bash + $ ./node_modules/.bin/gulp build-examples + ``` + + To view the examples you can use any static file server. To use the `nodejs` http-server module: + + ```bash + $ npm install http-server + $ ./node_modules/.bin/http-server -p 3000 + ``` + + Then visit http://localhost:3000/examples + +## Run tests + +To run the browser tests first build the `loadjs` library: + +```bash +$ ./node_modules/.bin/gulp build-test +``` + +Then visit http://localhost:3000/test
46
Merge branch 'master' of github.com:muicss/loadjs
6
.md
md
mit
muicss/loadjs
10067109
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067110
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067111
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067112
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067113
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067114
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067115
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067116
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067117
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067118
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067119
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067120
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067121
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067122
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067123
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Style Selector="search|SearchPanel Button"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Width="16" Focusable="False" IsOpen="False"> <ContentPresenter Name="PART_MessageContent" /> </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> Width="150" Height="24" Margin="3,3,3,0" Text="{TemplateBinding SearchPattern}" /> <Button Margin="3" Height="24" Width="24" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindNextText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindNext.png?assembly=AvaloniaEdit" /> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" IsVisible="{TemplateBinding IsReplaceMode}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{TemplateBinding ReplacePattern}" /> <Button Margin="3" Height="24" Width="24" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchReplaceNext}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.ReplaceNext.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> Merge branch 'master' into fix-scroll <DFF> @@ -37,8 +37,17 @@ VerticalAlignment="Top" TextBlock.FontFamily="Segoi UI" TextBlock.FontSize="10"> <Grid ColumnDefinitions="Auto,Auto,Auto" RowDefinitions="Auto,Auto"> + <Popup Name="PART_MessageView" + Classes="ToolTip" + PlacementMode="Bottom" + StaysOpen="True" + Focusable="False" + IsOpen="False" + ObeyScreenEdges="True"> + <ContentPresenter Name="PART_MessageContent" /> + </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" - IsChecked="{TemplateBinding IsReplaceMode, Mode=TwoWay}" + IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" @@ -57,7 +66,7 @@ Width="150" Height="24" Margin="3,3,3,0" - Text="{TemplateBinding SearchPattern}" /> + Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -101,13 +110,13 @@ Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" - IsVisible="{TemplateBinding IsReplaceMode}" + IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" - Text="{TemplateBinding ReplacePattern}" /> + Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" @@ -134,7 +143,7 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + <ToggleButton IsChecked="{Binding MatchCase, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -142,7 +151,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" @@ -150,7 +159,7 @@ Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> - <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16"
16
Merge branch 'master' into fix-scroll
7
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067124
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067125
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067126
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067127
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067128
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067129
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067130
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067131
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067132
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067133
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067134
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067135
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067136
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067137
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067138
<NME> Directory.Build.props <BEF> <Project> <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> </PropertyGroup> </Project> <VersionSuffix>beta</VersionSuffix> </PropertyGroup> </Project> <MSG> update avalonia <DFF> @@ -2,6 +2,6 @@ <PropertyGroup> <LangVersion>7.1</LangVersion> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <AvaloniaVersion>0.9.0-preview7</AvaloniaVersion> + <AvaloniaVersion>0.9.0-preview9</AvaloniaVersion> </PropertyGroup> </Project> \ No newline at end of file
1
update avalonia
1
.props
Build
mit
AvaloniaUI/AvaloniaEdit
10067139
<NME> module.render.js <BEF> describe('View#render()', function() { var viewToTest; beforeEach(function() { viewToTest = helpers.createView(); assert.defined(this.view.el); }, "Data should be present in the generated markup.": function() { var text = 'some orange text'; var orange = new Orange({ test("Data should be present in the generated markup.", function() { var text = 'some orange text'; var orange = new Orange({ model: { text: text } }); orange .render() .inject(sandbox); expect(orange.el.innerHTML).toEqual(text); }); test("Should be able to use Backbone models", function() { var orange = new Orange({ model: { text: 'orange text' } }); orange.render(); expect(orange.el.innerHTML).toEqual('orange text'); }); test("Child html should be present in the parent.", function() { var layout = new Layout(); var apple = new Apple(); layout .add(apple, 1) .render(); firstChild = layout.el.firstElementChild; expect(firstChild.classList.contains('apple')).toBe(true); }); test("Should be of the tag specified", function() { var apple = new Apple({ tag: 'ul' }); apple.render(); expect('UL').toEqual(apple.el.tagName); }); test("Should have classes on the element", function() { var apple = new Apple({ classes: ['foo', 'bar'] }); apple.render(); expect('apple foo bar').toEqual(apple.el.className); }); test("Should have an id attribute with the value of `fmid`", function() { var apple = new Apple({ classes: ['foo', 'bar'] }); apple.render(); expect(apple._fmid).toEqual(apple.el.id); }); test("Should have populated all child module.el properties", function() { var layout = new Layout({ children: { 1: { module: 'apple', children: { 1: { module: 'apple', children: { 1: { module: 'apple' } } }, "tearDown": helpers.destroyView }); }); var apple1 = layout.module('apple'); var apple2 = apple1.module('apple'); var apple3 = apple2.module('apple'); layout.render(); expect(apple1.el).toBeTruthy(); expect(apple2.el).toBeTruthy(); expect(apple3.el).toBeTruthy(); }); test("The outer DOM node should be recycled between #renders", function() { var layout = new Layout({ children: { 1: { module: 'apple' } } }); layout.render(); layout.el.setAttribute('data-test', 'should-not-be-blown-away'); layout.module('apple').el.setAttribute('data-test', 'should-be-blown-away'); layout.render(); // The DOM node of the FM module that render is called on should be recycled expect(layout.el.getAttribute('data-test')).toEqual('should-not-be-blown-away'); // The DOM node of a child FM module to the one render is called on should not be recycled expect(layout.module('apple').el.getAttribute('data-test')).not.toEqual('should-be-blown-away'); }); test("Classes should be updated on render", function() { var layout = new Layout(); layout.render(); layout.classes = ['should-be-added']; layout.render(); expect(layout.el.className).toEqual('layout should-be-added'); }); test("Classes added through the DOM should persist between renders", function() { var layout = new Layout(); layout.render(); layout.el.classList.add('should-persist'); layout.render(); expect(layout.el.className).toEqual('layout should-persist'); }); test("Should fire unmount on children when rerendering", function() { var appleSpy = jest.fn(); var orangeSpy = jest.fn(); var pearSpy = jest.fn(); viewToTest.module('apple').on('unmount', appleSpy); viewToTest.module('orange').on('unmount', orangeSpy); viewToTest.module('pear').on('unmount', pearSpy); viewToTest.render(); expect(appleSpy).not.toHaveBeenCalled(); expect(orangeSpy).not.toHaveBeenCalled(); expect(pearSpy).not.toHaveBeenCalled(); viewToTest.render(); expect(appleSpy).toHaveBeenCalled(); expect(orangeSpy).toHaveBeenCalled(); expect(pearSpy).toHaveBeenCalled(); }); afterEach(function() { helpers.destroyView(); viewToTest = null; }); }); <MSG> Add event <DFF> @@ -7,6 +7,16 @@ buster.testCase('View#render()', { assert.defined(this.view.el); }, + "before render and render events should be fired": function() { + var beforeRenderSpy = this.spy(); + var renderSpy = this.spy(); + this.view.on('before render', beforeRenderSpy); + this.view.on('render', renderSpy); + + this.view.render(); + assert.callOrder(beforeRenderSpy, renderSpy); + }, + "Data should be present in the generated markup.": function() { var text = 'some orange text'; var orange = new Orange({ @@ -91,4 +101,4 @@ buster.testCase('View#render()', { }, "tearDown": helpers.destroyView -}); \ No newline at end of file +});
11
Add event
1
.js
render
mit
ftlabs/fruitmachine
10067140
<NME> module.appendTo.js <BEF> describe('View#appendTo()', function() { var viewToTest; beforeEach(function() { viewToTest = helpers.createView(); }); test("Should return the view for a fluent interface.", function() { var sandbox = document.createElement('div'), sandbox2 = document.createElement('div'), existing = document.createElement('div'); sandbox2.appendChild(existing); expect(viewToTest.render().appendTo(sandbox)).toBe(viewToTest); expect(viewToTest.render().insertBefore(sandbox2, existing)).toBe(viewToTest); }); test("Should append the view element as a child of the given element.", function() { var sandbox = document.createElement('div'); viewToTest .render() .appendTo(sandbox); expect(viewToTest.el).toBe(sandbox.firstElementChild); }); test("Should not destroy existing element contents.", function() { var sandbox = document.createElement('div'), existing = document.createElement('div'); sandbox.appendChild(existing); this.view .render() .appendTo(sandbox, existing2); assert.equals(existing1, sandbox.firstElementChild); assert.equals(this.view.el, existing1.nextSibling); test("Should insert before specified element.", function() { var sandbox = document.createElement('div'), existing1 = document.createElement('div'), existing2 = document.createElement('div'); sandbox.appendChild(existing1); sandbox.appendChild(existing2); viewToTest .render() .insertBefore(sandbox, existing2); expect(existing1).toBe(sandbox.firstElementChild); expect(viewToTest.el).toBe(existing1.nextSibling); expect(existing2).toBe(viewToTest.el.nextSibling); }); afterEach(function() { helpers.emptySandbox(); helpers.destroyView(); viewToTest = null; }); }); <MSG> Better API on advice of @rowanbeentje <DFF> @@ -36,7 +36,7 @@ buster.testCase('View#appendTo()', { this.view .render() - .appendTo(sandbox, existing2); + .insertBefore(sandbox, existing2); assert.equals(existing1, sandbox.firstElementChild); assert.equals(this.view.el, existing1.nextSibling);
1
Better API on advice of @rowanbeentje
1
.js
appendTo
mit
ftlabs/fruitmachine
10067141
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067142
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067143
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067144
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067145
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067146
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067147
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067148
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit
10067149
<NME> SearchPanel.xaml <BEF> ο»Ώ<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ae="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit" xmlns:search="clr-namespace:AvaloniaEdit.Search;assembly=AvaloniaEdit"> <Style Selector="search|SearchPanel ToggleButton.ExpanderToggle"> <Setter Property="Template"> <ControlTemplate> <Path Fill="{DynamicResource ThemeForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 0 2 L 4 6 L 0 10 Z" /> </ControlTemplate> </Setter> </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> <Setter Property="RenderTransform"> <RotateTransform Angle="90" /> </Setter> </Style> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style Selector="search|SearchPanel Button:pointerover"> <Setter Property="Background" Value="{DynamicResource ThemeControlMidBrush}"/> </Style> <Style Selector="search|SearchPanel"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLowBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeControlLowBrush}" /> <Setter Property="Focusable" Value="True" /> <Setter Property="Template"> <ControlTemplate> <Border Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" HorizontalAlignment="Right" <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" </Popup> <ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0" Width="16" Margin="2"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0"> <TextBox Watermark="{x:Static ae:SR.SearchLabel}" Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" Width="150" Height="24" Margin="3,3,3,0" Text="{Binding SearchPattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindPrevious}"> <ToolTip.Tip> <TextBlock Text="{x:Static ae:SR.SearchFindPreviousText}" /> </ToolTip.Tip> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.FindPrevious.png?assembly=AvaloniaEdit" /> </Button> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.FindNext}"> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> </Button> <Button Height="16" Background="Transparent" BorderThickness="0" Width="16" HorizontalAlignment="Right" VerticalAlignment="Top" Command="{x:Static search:SearchCommands.CloseSearchPanel}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Focusable="True"> <Path Data="M 0,0 L 8,8 M 8,0 L 0,8" Stroke="{DynamicResource ThemeForegroundBrush}" StrokeThickness="1" /> </Button> </StackPanel> <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> <TextBox Name="ReplaceBox" Watermark="{x:Static ae:SR.ReplaceLabel}" IsVisible="{Binding IsReplaceMode, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1" Grid.Row="1" Width="150" Height="24" Margin="3 3 3 0" Text="{Binding ReplacePattern, RelativeSource={RelativeSource TemplatedParent}}" /> <Button Margin="3" Height="24" Width="24" Command="{x:Static search:SearchCommands.ReplaceNext}"> </Button> </StackPanel> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{TemplateBinding MatchCase}" Content="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding WholeWords}" Content="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" /> <CheckBox IsChecked="{TemplateBinding UseRegex}" Content="{x:Static ae:SR.SearchUseRegexText}" Margin="3" /> </StackPanel> </StackPanel> </Grid> <ToggleButton IsChecked="{Binding WholeWords, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> </ToggleButton> <ToggleButton IsChecked="{Binding UseRegex, RelativeSource={RelativeSource TemplatedParent}}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" Height="24" Width="24"> <Image Width="16" Height="16" Stretch="Fill" Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> </ToggleButton> </StackPanel> </StackPanel> </Grid> </Border> </ControlTemplate> </Setter> </Style> </Styles> <MSG> use icons for match options <DFF> @@ -15,9 +15,9 @@ </Style> <Style Selector="ToggleButton.ExpanderToggle:checked /template/ Path"> - + <Setter Property="RenderTransform"> - <RotateTransform Angle="90" /> + <RotateTransform Angle="90" /> </Setter> </Style> @@ -47,10 +47,10 @@ <TextBlock Text="{x:Static ae:SR.SearchToggleReplace}" /> </ToolTip.Tip> </ToggleButton> - <StackPanel Grid.Column="1"> + <StackPanel Grid.Column="1"> <StackPanel Orientation="Horizontal" Grid.Column="2" - Grid.Row="0"> + Grid.Row="0"> <TextBox Name="PART_searchTextBox" Grid.Column="1" Grid.Row="0" @@ -96,7 +96,7 @@ </Button> </StackPanel> - <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" + <StackPanel Name="ReplaceButtons" IsVisible="{Binding #Expander.IsChecked}" Orientation="Horizontal" Grid.Column="2" Grid.Row="1"> @@ -134,15 +134,30 @@ </Button> </StackPanel> <StackPanel Orientation="Horizontal"> - <CheckBox IsChecked="{TemplateBinding MatchCase}" - Content="{x:Static ae:SR.SearchMatchCaseText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding WholeWords}" - Content="{x:Static ae:SR.SearchMatchWholeWordsText}" - Margin="3" /> - <CheckBox IsChecked="{TemplateBinding UseRegex}" - Content="{x:Static ae:SR.SearchUseRegexText}" - Margin="3" /> + <ToggleButton IsChecked="{TemplateBinding MatchCase}" ToolTip.Tip="{x:Static ae:SR.SearchMatchCaseText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CaseSensitive.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding WholeWords}" ToolTip.Tip="{x:Static ae:SR.SearchMatchWholeWordsText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.CompleteWord.png?assembly=AvaloniaEdit" /> + </ToggleButton> + <ToggleButton IsChecked="{TemplateBinding UseRegex}" ToolTip.Tip="{x:Static ae:SR.SearchUseRegexText}" Margin="3" + Height="24" + Width="24"> + <Image Width="16" + Height="16" + Stretch="Fill" + Source="resm:AvaloniaEdit.Search.Assets.RegularExpression.png?assembly=AvaloniaEdit" /> + </ToggleButton> </StackPanel> </StackPanel> </Grid>
29
use icons for match options
14
.xaml
xaml
mit
AvaloniaUI/AvaloniaEdit