Caret.js-0.3.1/ 0000775 0000000 0000000 00000000000 12664257734 0013204 5 ustar 00root root 0000000 0000000 Caret.js-0.3.1/.gitignore 0000664 0000000 0000000 00000000121 12664257734 0015166 0 ustar 00root root 0000000 0000000 node_modules/ build/ bower_components/ _SpecRunner.html .grunt/ *.map components/ Caret.js-0.3.1/CHANGELOG.md 0000664 0000000 0000000 00000002113 12664257734 0015012 0 ustar 00root root 0000000 0000000 ### v0.2.1 * f66a1eb - can get offset at the benginning of a line * 4885ddd - fix wrong position of textarea ### v0.2.0 * 12119d2 - calculating in iframe's coordinate * 959436d - implement `position` api for contentEditable * d051ffc - fix html escaping while mirroring caret ### v0.1.0 * b1f8f53 - fix Mirror div does not reset its CSS * e88e40e - fix Bad positioning in long words * 37d4c5e - disable auto decovery iframe ### v0.0.7 * cf94271 - Added suport for .caret(pos, 0) - Nicolas Donna * 2de2b0f - Fixed error when checking the pos arg when setting the position - Nicolas Donna * 34ac7fa - catch error thrown in cross-domain iframe - jiyinyiyong * 01f1fa1 - add minified file in dist. ### v0.0.6 * 287b5d8 working in iframe ### v0.0.5 * aef0aa4 fix IE input position error * 4a4f7f7 fix contenteditable null value bug ### v0.0.4 * fix scrolling problem ### v0.0.2 * support `contentEditable` mode * fix ie bugs, and support IE > 6 to all mode ### 2013-08-07 * fix bug: error position at beginning of textarea * Bower * jasmine test ### 2013-03-31 * support IE browsers. Caret.js-0.3.1/Gruntfile.coffee 0000664 0000000 0000000 00000004016 12664257734 0016315 0 ustar 00root root 0000000 0000000 module.exports = (grunt) -> grunt.initConfig pkg: grunt.file.readJSON 'package.json' bower_path: 'bower_components' jasmine: src: 'src/*.js' options: vendor: [ '<%= bower_path %>/jquery/dist/jquery.min.js', '<%= bower_path %>/jasmine-jquery/lib/jasmine-jquery.js' ] specs: 'spec/javascripts/*.js' # keepRunner: true uglify: options: banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' build: files: 'dist/<%= pkg.name %>.min.js': ['src/<%= pkg.name %>.js'] coffee: withMaps: options: bare: true sourceMap: true files: 'src/<%= pkg.name %>.js': 'src/<%= pkg.name %>.coffee' withoutMaps: options: bare: true sourceMap: false files: 'dist/<%= pkg.name %>.js': 'src/<%= pkg.name %>.coffee' watch: scripts: files: ['src/*.coffee'] tasks: ['coffee', 'umd'] umd: options: template: 'umd' deps: 'default': ['$'] amd: ['jquery'] cjs: ['jquery'] global: items: ['jQuery'] prefix: '' src: src: 'src/<%= pkg.name %>.js' dist: src: 'dist/<%= pkg.name %>.js' 'json-replace': options: space: " ", replace: version: "<%= pkg.version %>" 'update-version': files:[{ 'bower.json': 'bower.json', 'component.json': 'component.json' }] grunt.loadNpmTasks 'grunt-contrib-coffee' grunt.loadNpmTasks 'grunt-contrib-uglify' grunt.loadNpmTasks 'grunt-contrib-jasmine' grunt.loadNpmTasks 'grunt-json-replace' grunt.loadNpmTasks 'grunt-contrib-watch' grunt.loadNpmTasks 'grunt-umd' grunt.registerTask 'update-version', 'json-replace' grunt.registerTask 'default', ['coffee', 'umd', 'jasmine','update-version', 'uglify', 'watch'] grunt.registerTask 'test', ['coffee', 'umd', 'jasmine'] Caret.js-0.3.1/LICENSE-MIT 0000664 0000000 0000000 00000002047 12664257734 0014643 0 ustar 00root root 0000000 0000000 Copyright (c) 2013 chord.luo@gmail.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Caret.js-0.3.1/README.md 0000664 0000000 0000000 00000002442 12664257734 0014465 0 ustar 00root root 0000000 0000000 Caret.js ======== Get caret position or offset from inputor This is the core function that working in [At.js](http://ichord.github.com/At.js). Now, It just become an simple jquery plugin so that everybody can use it. And, of course, **At.js** is using this plugin too. * support iframe context Live Demo ========= http://ichord.github.com/Caret.js/ Usage ===== ```javascript // Get caret position $('#inputor').caret('position'); // => {left: 15, top: 30, height: 20} // Get caret offset $('#inputor').caret('offset'); // => {left: 300, top: 400, height: 20} var fixPos = 20 // Get position of the 20th char in the inputor. // not working in `contentEditable` mode $('#inputor').caret('position', fixPos); // Get offset of the 20th char. // not working in `contentEditable` mode $('#inputor').caret('offset', fixPos); // more // Get caret position from the first char in the inputor. $('#inputor').caret('pos'); // => 15 // Set caret position in the inputor $('#inputor').caret('pos', 15); // set iframe context // NOTE: Related to the iframe's cooridinate. // You might want to get the iframe's offset/position on your own $('#inputor').caret('offset', {iframe: theIframe}); $('#inputor').caret('position', {iframe: theIframe}); $('#inputor').caret('pos', 15, {iframe: theIframe}); ``` Caret.js-0.3.1/bower.json 0000664 0000000 0000000 00000000475 12664257734 0015223 0 ustar 00root root 0000000 0000000 { "name": "Caret.js", "version": "0.3.1", "main": "src/jquery.caret.js", "ignore": [ "**/.*", "node_modules", "bower_components", "test", "tests", "spec", "index.html" ], "dependencies": { "jquery": ">=1.7.0" }, "devDependencies": { "jasmine-jquery": "~1.5.8" } } Caret.js-0.3.1/component.json 0000664 0000000 0000000 00000000631 12664257734 0016101 0 ustar 00root root 0000000 0000000 { "name": "Caret.js", "repo": "ichord/Caret.js", "description": "Add Github like mentions autocomplete to your application.", "version": "0.3.1", "keywords": [ "At.js", "caret", "ui" ], "dependencies": { "component/jquery": "*" }, "demo": "http://ichord.github.com/Caret.js", "main": "src/jquery.caret.js", "scripts": [ "src/jquery.caret.js" ], "license": "MIT" } Caret.js-0.3.1/index.html 0000664 0000000 0000000 00000014151 12664257734 0015203 0 ustar 00root root 0000000 0000000
We will get the rect of @icho
" # mirror.create(html).rect() class Mirror css_attr: [ "borderBottomWidth", "borderLeftWidth", "borderRightWidth", "borderTopStyle", "borderRightStyle", "borderBottomStyle", "borderLeftStyle", "borderTopWidth", "boxSizing", "fontFamily", "fontSize", "fontWeight", "height", "letterSpacing", "lineHeight", "marginBottom", "marginLeft", "marginRight", "marginTop", "outlineWidth", "overflow", "overflowX", "overflowY", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop", "textAlign", "textOverflow", "textTransform", "whiteSpace", "wordBreak", "wordWrap", ] constructor: (@$inputor) -> mirrorCss: -> css = position: 'absolute' left: -9999 top: 0 zIndex: -20000 if @$inputor.prop( 'tagName' ) == 'TEXTAREA' @css_attr.push( 'width' ) $.each @css_attr, (i,p) => css[p] = @$inputor.css p css create: (html) -> @$mirror = $('') @$mirror.css this.mirrorCss() @$mirror.html(html) @$inputor.after(@$mirror) this # 获得标记的位置 # # @return [Object] 标记的坐标 # {left: 0, top: 0, bottom: 0} rect: -> $flag = @$mirror.find "#caret" pos = $flag.position() rect = {left: pos.left, top: pos.top, height: $flag.height() } @$mirror.remove() rect Utils = contentEditable: ($inputor)-> !!($inputor[0].contentEditable && $inputor[0].contentEditable == 'true') methods = pos: (pos) -> if pos or pos == 0 this.setPos pos else this.getPos() position: (pos) -> if oDocument.selection then this.getIEPosition pos else this.getPosition pos offset: (pos) -> offset = this.getOffset(pos) offset oDocument = null oWindow = null oFrame = null setContextBy = (settings) -> if iframe = settings?.iframe oFrame = iframe oWindow = iframe.contentWindow oDocument = iframe.contentDocument || oWindow.document else oFrame = undefined oWindow = window oDocument = document discoveryIframeOf = ($dom) -> oDocument = $dom[0].ownerDocument oWindow = oDocument.defaultView || oDocument.parentWindow try oFrame = oWindow.frameElement catch error # throws error in cross-domain iframes $.fn.caret = (method, value, settings) -> # http://stackoverflow.com/questions/16010204/get-reference-of-window-object-from-a-dom-element if methods[method] if $.isPlainObject(value) setContextBy value value = undefined else setContextBy settings caret = if Utils.contentEditable(this) then new EditableCaret(this) else new InputCaret(this) methods[method].apply caret, [value] else $.error "Method #{method} does not exist on jQuery.caret" $.fn.caret.EditableCaret = EditableCaret $.fn.caret.InputCaret = InputCaret $.fn.caret.Utils = Utils $.fn.caret.apis = methods