diff --git a/src/Controller/ProfilesController.php b/src/Controller/ProfilesController.php index 673cada..fd5a16a 100644 --- a/src/Controller/ProfilesController.php +++ b/src/Controller/ProfilesController.php @@ -3,6 +3,7 @@ namespace App\Controller; +use Cake\Core\Configure; use Cake\Event\EventInterface; use Cake\Http\Exception\NotFoundException; use Cake\ORM\TableRegistry; @@ -330,9 +331,9 @@ public function reorderChildren($id = null) */ public function autocomplete() { - $term = $this->getRequest()->getQuery('q'); - if ($this->getRequest()->is(['ajax', 'get']) && $term) { - $ret = ''; + $term = $this->getRequest()->getQuery('term'); + if ((Configure::read('debug') || $this->getRequest()->is(['ajax', 'get'])) && $term) { + $ret = []; // fire autocomplete with at least 2 characters if (strlen($term) > 1) { @@ -343,11 +344,11 @@ public function autocomplete() ->all(); foreach ($profiles as $p) { - //$ret[] = ['label' => $p->d_n, 'value' => $p->id]; - $ret .= $p->id . '|' . h($p->d_n) . chr(10); + $ret[] = ['label' => $p->d_n, 'value' => $p->id]; + //$ret .= $p->id . '|' . h($p->d_n) . chr(10); } } - $this->response = $this->response->withStringBody($ret); + $this->response = $this->response->withStringBody(json_encode($ret)); return $this->response; } else { diff --git a/templates/Attachments/view.php b/templates/Attachments/view.php index 1a9f903..87ed18d 100644 --- a/templates/Attachments/view.php +++ b/templates/Attachments/view.php @@ -121,11 +121,12 @@ echo ''; echo $this->Form->end(); - echo $this->Html->script('jquery.imgareaselect-0.8.min'); + echo $this->Html->script('jquery.imgareaselect.js'); echo $this->Html->script('jquery.imgnotes-0.2'); - echo $this->Html->script('ui.core'); - echo $this->Html->script('ui.autocomplete'); + //echo $this->Html->script('ui.core'); + //echo $this->Html->script('ui.autocomplete'); + echo $this->Html->script('jquery-ui-personalized.min'); echo $this->Html->css('imgnotes'); echo $this->Html->css('ui.all'); ?> @@ -147,7 +148,7 @@ $(document).ready(function() { $('#ImgnoteNote').autocomplete({ - url: 'Url->build(['controller' => 'Profiles', 'action' => 'autocomplete']) ?>', + source: 'Url->build(['controller' => 'Profiles', 'action' => 'autocomplete']) ?>', dataType: "text", width: "240px", formatResult: function(row) { @@ -178,7 +179,7 @@ $('#NoteForm').hide(); }); - $('#AddNoteLink').click(function() { + $('#AddNoteLink').click(function(e) { getImageSize('large'); @@ -191,17 +192,20 @@ $y1 = round($large_sizes['height'] / 2 - $h / 2); $y2 = $y1 + $h; - printf('var frame = {onSelectChange: ShowAddNote, handles: true, x1:%1$s, x2:%2$s, y1:%3$s, y2:%4$s, width:%5$s, height:%6$s};', $x1, $x2, $y1, $y2, $w, $h).PHP_EOL; + printf('var frame = {onSelectChange: ShowAddNote, handles: true, x1:%1$s, x2:%2$s, y1:%3$s, y2:%4$s, width:%5$s, height:%6$s};', $x1, $x2, $y1, $y2, $w, $h) . PHP_EOL; ?> + ShowAddNote('#AttachmentImage', frame); $('#NoteForm').show(); - $('#AttachmentImage').imgAreaSelect(frame); + $("#AttachmentImage").imgAreaSelect(frame); + e.preventDefault(); + return false; }); diff --git a/templates/Profiles/reorder_children.php b/templates/Profiles/reorder_children.php index 5bae015..59e431c 100644 --- a/templates/Profiles/reorder_children.php +++ b/templates/Profiles/reorder_children.php @@ -3,7 +3,7 @@ ?>

Html->script('jquery-ui-personalized-1.6rc6.min'); + echo $this->Html->script('jquery-ui-personalized.min'); ?> ").appendTo(o)),n.opacity&&(this.helper.css("opacity")&&(this._storedOpacity=this.helper.css("opacity")),this.helper.css("opacity",n.opacity)),n.zIndex&&(this.helper.css("zIndex")&&(this._storedZIndex=this.helper.css("zIndex")),this.helper.css("zIndex",n.zIndex)),this.scrollParent[0]!==this.document[0]&&"HTML"!==this.scrollParent[0].tagName&&(this.overflowOffset=this.scrollParent.offset()),this._trigger("start",t,this._uiHash()),this._preserveHelperProportions||this._cacheHelperProportions(),!i)for(s=this.containers.length-1;0<=s;s--)this.containers[s]._trigger("activate",t,this._uiHash(this));return x.ui.ddmanager&&(x.ui.ddmanager.current=this),x.ui.ddmanager&&!n.dropBehaviour&&x.ui.ddmanager.prepareOffsets(this,t),this.dragging=!0,this._addClass(this.helper,"ui-sortable-helper"),this._mouseDrag(t),!0},_mouseDrag:function(t){var e,i,s,o,n=this.options,r=!1;for(this.position=this._generatePosition(t),this.positionAbs=this._convertPositionTo("absolute"),this.lastPositionAbs||(this.lastPositionAbs=this.positionAbs),this.options.scroll&&(this.scrollParent[0]!==this.document[0]&&"HTML"!==this.scrollParent[0].tagName?(this.overflowOffset.top+this.scrollParent[0].offsetHeight-t.pageYt[this.floating?"width":"height"]?h&&c:n",i.document[0]);return i._addClass(e,"ui-sortable-placeholder",s||i.currentItem[0].className)._removeClass(e,"ui-sortable-helper"),"tbody"===t?i._createTrPlaceholder(i.currentItem.find("tr").eq(0),x("",i.document[0]).appendTo(e)):"tr"===t?i._createTrPlaceholder(i.currentItem,e):"img"===t&&e.attr("src",i.currentItem.attr("src")),s||e.css("visibility","hidden"),e},update:function(t,e){s&&!o.forcePlaceholderSize||(e.height()||e.height(i.currentItem.innerHeight()-parseInt(i.currentItem.css("paddingTop")||0,10)-parseInt(i.currentItem.css("paddingBottom")||0,10)),e.width())||e.width(i.currentItem.innerWidth()-parseInt(i.currentItem.css("paddingLeft")||0,10)-parseInt(i.currentItem.css("paddingRight")||0,10))}}),i.placeholder=x(o.placeholder.element.call(i.element,i.currentItem)),i.currentItem.after(i.placeholder),o.placeholder.update(i,i.placeholder)},_createTrPlaceholder:function(t,e){var i=this;t.children().each(function(){x(" ",i.document[0]).attr("colspan",x(this).attr("colspan")||1).appendTo(e)})},_contactContainers:function(t){for(var e,i,s,o,n,r,a,l,h,c=null,u=null,p=this.containers.length-1;0<=p;p--)x.contains(this.currentItem[0],this.containers[p].element[0])||(this._intersectsWith(this.containers[p].containerCache)?c&&x.contains(this.containers[p].element[0],c.element[0])||(c=this.containers[p],u=p):this.containers[p].containerCache.over&&(this.containers[p]._trigger("out",t,this._uiHash(this)),this.containers[p].containerCache.over=0));if(c)if(1===this.containers.length)this.containers[u].containerCache.over||(this.containers[u]._trigger("over",t,this._uiHash(this)),this.containers[u].containerCache.over=1);else{for(i=1e4,s=null,o=(l=c.floating||this._isFloating(this.currentItem))?"left":"top",n=l?"width":"height",h=l?"pageX":"pageY",e=this.items.length-1;0<=e;e--)x.contains(this.containers[u].element[0],this.items[e].item[0])&&this.items[e].item[0]!==this.currentItem[0]&&(r=this.items[e].item.offset()[o],a=!1,t[h]-r>this.items[e][n]/2&&(a=!0),Math.abs(t[h]-r)this.containment[2]&&(i=this.containment[2]+this.offset.click.left),t.pageY-this.offset.click.top>this.containment[3])&&(s=this.containment[3]+this.offset.click.top),e.grid)&&(t=this.originalPageY+Math.round((s-this.originalPageY)/e.grid[1])*e.grid[1],s=!this.containment||t-this.offset.click.top>=this.containment[1]&&t-this.offset.click.top<=this.containment[3]?t:t-this.offset.click.top>=this.containment[1]?t-e.grid[1]:t+e.grid[1],t=this.originalPageX+Math.round((i-this.originalPageX)/e.grid[0])*e.grid[0],i=!this.containment||t-this.offset.click.left>=this.containment[0]&&t-this.offset.click.left<=this.containment[2]?t:t-this.offset.click.left>=this.containment[0]?t-e.grid[0]:t+e.grid[0]),{top:s-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.scrollParent.scrollTop():n?0:o.scrollTop()),left:i-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():n?0:o.scrollLeft())}},_rearrange:function(t,e,i,s){i?i[0].appendChild(this.placeholder[0]):e.item[0].parentNode.insertBefore(this.placeholder[0],"down"===this.direction?e.item[0]:e.item[0].nextSibling),this.counter=this.counter?++this.counter:1;var o=this.counter;this._delay(function(){o===this.counter&&this.refreshPositions(!s)})},_clear:function(t,e){this.reverting=!1;var i,s=[];if(!this._noFinalSort&&this.currentItem.parent().length&&this.placeholder.before(this.currentItem),this._noFinalSort=null,this.helper[0]===this.currentItem[0]){for(i in this._storedCSS)"auto"!==this._storedCSS[i]&&"static"!==this._storedCSS[i]||(this._storedCSS[i]="");this.currentItem.css(this._storedCSS),this._removeClass(this.currentItem,"ui-sortable-helper")}else this.currentItem.show();function o(e,i,s){return function(t){s._trigger(e,t,i._uiHash(i))}}for(this.fromOutside&&!e&&s.push(function(t){this._trigger("receive",t,this._uiHash(this.fromOutside))}),!this.fromOutside&&this.domPosition.prev===this.currentItem.prev().not(".ui-sortable-helper")[0]&&this.domPosition.parent===this.currentItem.parent()[0]||e||s.push(function(t){this._trigger("update",t,this._uiHash())}),this===this.currentContainer||e||(s.push(function(t){this._trigger("remove",t,this._uiHash())}),s.push(function(e){return function(t){e._trigger("receive",t,this._uiHash(this))}}.call(this,this.currentContainer)),s.push(function(e){return function(t){e._trigger("update",t,this._uiHash(this))}}.call(this,this.currentContainer))),i=this.containers.length-1;0<=i;i--)e||s.push(o("deactivate",this,this.containers[i])),this.containers[i].containerCache.over&&(s.push(o("out",this,this.containers[i])),this.containers[i].containerCache.over=0);if(this.storedCursor&&(this.document.find("body").css("cursor",this.storedCursor),this.storedStylesheet.remove()),this._storedOpacity&&this.helper.css("opacity",this._storedOpacity),this._storedZIndex&&this.helper.css("zIndex","auto"===this._storedZIndex?"":this._storedZIndex),this.dragging=!1,e||this._trigger("beforeStop",t,this._uiHash()),this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.cancelHelperRemoval||(this.helper[0]!==this.currentItem[0]&&this.helper.remove(),this.helper=null),!e){for(i=0;i",delay:300,options:{icons:{submenu:"ui-icon-caret-1-e"},items:"> *",menus:"ul",position:{my:"left top",at:"right top"},role:"menu",blur:null,focus:null,select:null},_create:function(){this.activeMenu=this.element,this.mouseHandled=!1,this.element.uniqueId().attr({role:this.options.role,tabIndex:0}),this._addClass("ui-menu","ui-widget ui-widget-content"),this._on({"mousedown .ui-menu-item":function(t){t.preventDefault()},"click .ui-menu-item":function(t){var e=x(t.target),i=x(x.ui.safeActiveElement(this.document[0]));!this.mouseHandled&&e.not(".ui-state-disabled").length&&(this.select(t),t.isPropagationStopped()||(this.mouseHandled=!0),e.has(".ui-menu").length?this.expand(t):!this.element.is(":focus")&&i.closest(".ui-menu").length&&(this.element.trigger("focus",[!0]),this.active)&&1===this.active.parents(".ui-menu").length&&clearTimeout(this.timer))},"mouseenter .ui-menu-item":function(t){var e,i;this.previousFilter||(e=x(t.target).closest(".ui-menu-item"),i=x(t.currentTarget),e[0]===i[0]&&(this._removeClass(i.siblings().children(".ui-state-active"),null,"ui-state-active"),this.focus(t,i)))},mouseleave:"collapseAll","mouseleave .ui-menu":"collapseAll",focus:function(t,e){var i=this.active||this.element.find(this.options.items).eq(0);e||this.focus(t,i)},blur:function(t){this._delay(function(){x.contains(this.element[0],x.ui.safeActiveElement(this.document[0]))||this.collapseAll(t)})},keydown:"_keydown"}),this.refresh(),this._on(this.document,{click:function(t){this._closeOnDocumentClick(t)&&this.collapseAll(t),this.mouseHandled=!1}})},_destroy:function(){var t=this.element.find(".ui-menu-item").removeAttr("role aria-disabled").children(".ui-menu-item-wrapper").removeUniqueId().removeAttr("tabIndex role aria-haspopup");this.element.removeAttr("aria-activedescendant").find(".ui-menu").addBack().removeAttr("role aria-labelledby aria-expanded aria-hidden aria-disabled tabIndex").removeUniqueId().show(),t.children().each(function(){var t=x(this);t.data("ui-menu-submenu-caret")&&t.remove()})},_keydown:function(t){var e,i,s,o=!0;switch(t.keyCode){case x.ui.keyCode.PAGE_UP:this.previousPage(t);break;case x.ui.keyCode.PAGE_DOWN:this.nextPage(t);break;case x.ui.keyCode.HOME:this._move("first","first",t);break;case x.ui.keyCode.END:this._move("last","last",t);break;case x.ui.keyCode.UP:this.previous(t);break;case x.ui.keyCode.DOWN:this.next(t);break;case x.ui.keyCode.LEFT:this.collapse(t);break;case x.ui.keyCode.RIGHT:this.active&&!this.active.is(".ui-state-disabled")&&this.expand(t);break;case x.ui.keyCode.ENTER:case x.ui.keyCode.SPACE:this._activate(t);break;case x.ui.keyCode.ESCAPE:this.collapse(t);break;default:e=this.previousFilter||"",s=o=!1,i=96<=t.keyCode&&t.keyCode<=105?(t.keyCode-96).toString():String.fromCharCode(t.keyCode),clearTimeout(this.filterTimer),i===e?s=!0:i=e+i,e=this._filterMenuItems(i),(e=s&&-1!==e.index(this.active.next())?this.active.nextAll(".ui-menu-item"):e).length||(i=String.fromCharCode(t.keyCode),e=this._filterMenuItems(i)),e.length?(this.focus(t,e),this.previousFilter=i,this.filterTimer=this._delay(function(){delete this.previousFilter},1e3)):delete this.previousFilter}o&&t.preventDefault()},_activate:function(t){this.active&&!this.active.is(".ui-state-disabled")&&(this.active.children("[aria-haspopup='true']").length?this.expand(t):this.select(t))},refresh:function(){var t,e,s=this,o=this.options.icons.submenu,i=this.element.find(this.options.menus);this._toggleClass("ui-menu-icons",null,!!this.element.find(".ui-icon").length),t=i.filter(":not(.ui-menu)").hide().attr({role:this.options.role,"aria-hidden":"true","aria-expanded":"false"}).each(function(){var t=x(this),e=t.prev(),i=x("").data("ui-menu-submenu-caret",!0);s._addClass(i,"ui-menu-icon","ui-icon "+o),e.attr("aria-haspopup","true").prepend(i),t.attr("aria-labelledby",e.attr("id"))}),this._addClass(t,"ui-menu","ui-widget ui-widget-content ui-front"),(t=i.add(this.element).find(this.options.items)).not(".ui-menu-item").each(function(){var t=x(this);s._isDivider(t)&&s._addClass(t,"ui-menu-divider","ui-widget-content")}),e=(i=t.not(".ui-menu-item, .ui-menu-divider")).children().not(".ui-menu").uniqueId().attr({tabIndex:-1,role:this._itemRole()}),this._addClass(i,"ui-menu-item")._addClass(e,"ui-menu-item-wrapper"),t.filter(".ui-state-disabled").attr("aria-disabled","true"),this.active&&!x.contains(this.element[0],this.active[0])&&this.blur()},_itemRole:function(){return{menu:"menuitem",listbox:"option"}[this.options.role]},_setOption:function(t,e){var i;"icons"===t&&(i=this.element.find(".ui-menu-icon"),this._removeClass(i,null,this.options.icons.submenu)._addClass(i,null,e.submenu)),this._super(t,e)},_setOptionDisabled:function(t){this._super(t),this.element.attr("aria-disabled",String(t)),this._toggleClass(null,"ui-state-disabled",!!t)},focus:function(t,e){var i;this.blur(t,t&&"focus"===t.type),this._scrollIntoView(e),this.active=e.first(),i=this.active.children(".ui-menu-item-wrapper"),this._addClass(i,null,"ui-state-active"),this.options.role&&this.element.attr("aria-activedescendant",i.attr("id")),i=this.active.parent().closest(".ui-menu-item").children(".ui-menu-item-wrapper"),this._addClass(i,null,"ui-state-active"),t&&"keydown"===t.type?this._close():this.timer=this._delay(function(){this._close()},this.delay),(i=e.children(".ui-menu")).length&&t&&/^mouse/.test(t.type)&&this._startOpening(i),this.activeMenu=e.parent(),this._trigger("focus",t,{item:e})},_scrollIntoView:function(t){var e,i,s;this._hasScroll()&&(e=parseFloat(x.css(this.activeMenu[0],"borderTopWidth"))||0,i=parseFloat(x.css(this.activeMenu[0],"paddingTop"))||0,e=t.offset().top-this.activeMenu.offset().top-e-i,i=this.activeMenu.scrollTop(),s=this.activeMenu.height(),t=t.outerHeight(),e<0?this.activeMenu.scrollTop(i+e):s",options:{appendTo:null,autoFocus:!1,delay:300,minLength:1,position:{my:"left top",at:"left bottom",collision:"none"},source:null,change:null,close:null,focus:null,open:null,response:null,search:null,select:null},requestIndex:0,pending:0,_create:function(){var i,s,o,t=this.element[0].nodeName.toLowerCase(),e="textarea"===t,t="input"===t;this.isMultiLine=e||!t&&this._isContentEditable(this.element),this.valueMethod=this.element[e||t?"val":"text"],this.isNewMenu=!0,this._addClass("ui-autocomplete-input"),this.element.attr("autocomplete","off"),this._on(this.element,{keydown:function(t){if(this.element.prop("readOnly"))s=o=i=!0;else{s=o=i=!1;var e=x.ui.keyCode;switch(t.keyCode){case e.PAGE_UP:i=!0,this._move("previousPage",t);break;case e.PAGE_DOWN:i=!0,this._move("nextPage",t);break;case e.UP:i=!0,this._keyEvent("previous",t);break;case e.DOWN:i=!0,this._keyEvent("next",t);break;case e.ENTER:this.menu.active&&(i=!0,t.preventDefault(),this.menu.select(t));break;case e.TAB:this.menu.active&&this.menu.select(t);break;case e.ESCAPE:this.menu.element.is(":visible")&&(this.isMultiLine||this._value(this.term),this.close(t),t.preventDefault());break;default:s=!0,this._searchTimeout(t)}}},keypress:function(t){if(i)i=!1,this.isMultiLine&&!this.menu.element.is(":visible")||t.preventDefault();else if(!s){var e=x.ui.keyCode;switch(t.keyCode){case e.PAGE_UP:this._move("previousPage",t);break;case e.PAGE_DOWN:this._move("nextPage",t);break;case e.UP:this._keyEvent("previous",t);break;case e.DOWN:this._keyEvent("next",t)}}},input:function(t){o?(o=!1,t.preventDefault()):this._searchTimeout(t)},focus:function(){this.selectedItem=null,this.previous=this._value()},blur:function(t){this.cancelBlur?delete this.cancelBlur:(clearTimeout(this.searching),this.close(t),this._change(t))}}),this._initSource(),this.menu=x("
    ").appendTo(this._appendTo()).menu({role:null}).hide().menu("instance"),this._addClass(this.menu.element,"ui-autocomplete","ui-front"),this._on(this.menu.element,{mousedown:function(t){t.preventDefault(),this.cancelBlur=!0,this._delay(function(){delete this.cancelBlur,this.element[0]!==x.ui.safeActiveElement(this.document[0])&&this.element.trigger("focus")})},menufocus:function(t,e){var i;this.isNewMenu&&(this.isNewMenu=!1,t.originalEvent)&&/^mouse/.test(t.originalEvent.type)?(this.menu.blur(),this.document.one("mousemove",function(){x(t.target).trigger(t.originalEvent)})):(i=e.item.data("ui-autocomplete-item"),!1!==this._trigger("focus",t,{item:i})&&t.originalEvent&&/^key/.test(t.originalEvent.type)&&this._value(i.value),(e=e.item.attr("aria-label")||i.value)&&x.trim(e).length&&(this.liveRegion.children().hide(),x("
    ").text(e).appendTo(this.liveRegion)))},menuselect:function(t,e){var i=e.item.data("ui-autocomplete-item"),s=this.previous;this.element[0]!==x.ui.safeActiveElement(this.document[0])&&(this.element.trigger("focus"),this.previous=s,this._delay(function(){this.previous=s,this.selectedItem=i})),!1!==this._trigger("select",t,{item:i})&&this._value(i.value),this.term=this._value(),this.close(t),this.selectedItem=i}}),this.liveRegion=x("
    ",{role:"status","aria-live":"assertive","aria-relevant":"additions"}).appendTo(this.document[0].body),this._addClass(this.liveRegion,null,"ui-helper-hidden-accessible"),this._on(this.window,{beforeunload:function(){this.element.removeAttr("autocomplete")}})},_destroy:function(){clearTimeout(this.searching),this.element.removeAttr("autocomplete"),this.menu.element.remove(),this.liveRegion.remove()},_setOption:function(t,e){this._super(t,e),"source"===t&&this._initSource(),"appendTo"===t&&this.menu.element.appendTo(this._appendTo()),"disabled"===t&&e&&this.xhr&&this.xhr.abort()},_isEventTargetInWidget:function(t){var e=this.menu.element[0];return t.target===this.element[0]||t.target===e||x.contains(e,t.target)},_closeOnClickOutside:function(t){this._isEventTargetInWidget(t)||this.close()},_appendTo:function(){var t=this.options.appendTo;return t=(t=(t=t&&(t.jquery||t.nodeType?x(t):this.document.find(t).eq(0)))&&t[0]?t:this.element.closest(".ui-front, dialog")).length?t:this.document[0].body},_initSource:function(){var i,s,o=this;x.isArray(this.options.source)?(i=this.options.source,this.source=function(t,e){e(x.ui.autocomplete.filter(i,t.term))}):"string"==typeof this.options.source?(s=this.options.source,this.source=function(t,e){o.xhr&&o.xhr.abort(),o.xhr=x.ajax({url:s,data:t,dataType:"json",success:function(t){e(t)},error:function(){e([])}})}):this.source=this.options.source},_searchTimeout:function(s){clearTimeout(this.searching),this.searching=this._delay(function(){var t=this.term===this._value(),e=this.menu.element.is(":visible"),i=s.altKey||s.ctrlKey||s.metaKey||s.shiftKey;t&&(e||i)||(this.selectedItem=null,this.search(null,s))},this.options.delay)},search:function(t,e){return t=null!=t?t:this._value(),this.term=this._value(),t.length").append(x("
    ").text(e.label)).appendTo(t)},_move:function(t,e){this.menu.element.is(":visible")?this.menu.isFirstItem()&&/^previous/.test(t)||this.menu.isLastItem()&&/^next/.test(t)?(this.isMultiLine||this._value(this.term),this.menu.blur()):this.menu[t](e):this.search(null,e)},widget:function(){return this.menu.element},_value:function(){return this.valueMethod.apply(this.element,arguments)},_keyEvent:function(t,e){this.isMultiLine&&!this.menu.element.is(":visible")||(this._move(t,e),e.preventDefault())},_isContentEditable:function(t){var e;return!!t.length&&("inherit"===(e=t.prop("contentEditable"))?this._isContentEditable(t.parent()):"true"===e)}}),x.extend(x.ui.autocomplete,{escapeRegex:function(t){return t.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")},filter:function(t,e){var i=new RegExp(x.ui.autocomplete.escapeRegex(e),"i");return x.grep(t,function(t){return i.test(t.label||t.value||t)})}}),x.widget("ui.autocomplete",x.ui.autocomplete,{options:{messages:{noResults:"No search results.",results:function(t){return t+(1").text(t).appendTo(this.liveRegion))}}),x.ui.autocomplete;var d,m,g,F,R,v,_,b,y,w,T,B,z,q,j,U,X,Y,$,G,H,S="ui-effects-",W="ui-effects-style",E="ui-effects-animated",K=x;function A(t,e,i){var s=b[e.type]||{};return null==t?i||!e.def?null:e.def:(t=s.floor?~~t:parseFloat(t),isNaN(t)?e.def:s.mod?(t+s.mod)%s.mod:t<0?0:s.max")[0],T=d.each,w.style.cssText="background-color:rgba(1,1,1,.5)",y.rgba=-1
    ").addClass("ui-effects-wrapper").css({fontSize:"100%",background:"transparent",border:"none",margin:0,padding:0}),e={width:i.width(),height:i.height()},o=document.activeElement;try{o.id}catch(t){o=document.body}return i.wrap(t),i[0]!==o&&!x.contains(i[0],o)||x(o).trigger("focus"),t=i.parent(),"static"===i.css("position")?(t.css({position:"relative"}),i.css({position:"relative"})):(x.extend(s,{position:i.css("position"),zIndex:i.css("z-index")}),x.each(["top","left","bottom","right"],function(t,e){s[e]=i.css(e),isNaN(parseInt(s[e],10))&&(s[e]="auto")}),i.css({position:"relative",top:0,left:0,right:"auto",bottom:"auto"})),i.css(e),t.css(s).show()},removeWrapper:function(t){var e=document.activeElement;return t.parent().is(".ui-effects-wrapper")&&(t.parent().replaceWith(t),t[0]!==e&&!x.contains(t[0],e)||x(e).trigger("focus")),t}}),x.extend(x.effects,{version:"1.12.1",define:function(t,e,i){return i||(i=e,e="effect"),x.effects.effect[t]=i,x.effects.effect[t].mode=e,i},scaledDimensions:function(t,e,i){var s;return 0===e?{height:0,width:0,outerHeight:0,outerWidth:0}:(s="horizontal"!==i?(e||100)/100:1,i="vertical"!==i?(e||100)/100:1,{height:t.height()*i,width:t.width()*s,outerHeight:t.outerHeight()*i,outerWidth:t.outerWidth()*s})},clipToBox:function(t){return{width:t.clip.right-t.clip.left,height:t.clip.bottom-t.clip.top,left:t.clip.left,top:t.clip.top}},unshift:function(t,e,i){var s=t.queue();1").insertAfter(t).css({display:/^(inline|ruby)/.test(t.css("display"))?"inline-block":"block",visibility:"hidden",marginTop:t.css("marginTop"),marginBottom:t.css("marginBottom"),marginLeft:t.css("marginLeft"),marginRight:t.css("marginRight"),float:t.css("float")}).outerWidth(t.outerWidth()).outerHeight(t.outerHeight()).addClass("ui-effects-placeholder"),t.data(S+"placeholder",e)),t.css({position:i,left:s.left,top:s.top}),e},removePlaceholder:function(t){var e=S+"placeholder",i=t.data(e);i&&(i.remove(),t.removeData(e))},cleanUp:function(t){x.effects.restoreStyle(t),x.effects.removePlaceholder(t)},setTransition:function(s,t,o,n){return n=n||{},x.each(t,function(t,e){var i=s.cssUnit(e);0
    ").appendTo("body").addClass(t.className).css({top:s.top-r,left:s.left-n,height:i.innerHeight(),width:i.innerWidth(),position:o?"fixed":"absolute"}).animate(a,t.duration,t.easing,function(){l.remove(),x.isFunction(e)&&e()})}}),x.fx.step.clip=function(t){t.clipInit||(t.start=x(t.elem).cssClip(),"string"==typeof t.end&&(t.end=Z(t.end,t.elem)),t.clipInit=!0),x(t.elem).cssClip({top:t.pos*(t.end.top-t.start.top)+t.start.top,right:t.pos*(t.end.right-t.start.right)+t.start.right,bottom:t.pos*(t.end.bottom-t.start.bottom)+t.start.bottom,left:t.pos*(t.end.left-t.start.left)+t.start.left})},H={},x.each(["Quad","Cubic","Quart","Quint","Expo"],function(e,t){H[t]=function(t){return Math.pow(t,e+2)}}),x.extend(H,{Sine:function(t){return 1-Math.cos(t*Math.PI/2)},Circ:function(t){return 1-Math.sqrt(1-t*t)},Elastic:function(t){return 0===t||1===t?t:-Math.pow(2,8*(t-1))*Math.sin((80*(t-1)-7.5)*Math.PI/15)},Back:function(t){return t*t*(3*t-2)},Bounce:function(t){for(var e,i=4;t<((e=Math.pow(2,--i))-1)/11;);return 1/Math.pow(4,3-i)-7.5625*Math.pow((3*e-2)/22-t,2)}}),x.each(H,function(t,e){x.easing["easeIn"+t]=e,x.easing["easeOut"+t]=function(t){return 1-e(1-t)},x.easing["easeInOut"+t]=function(t){return t<.5?e(2*t)/2:1-e(-2*t+2)/2}});x.effects,x.effects.define("highlight","show",function(t,e){var i=x(this),s={backgroundColor:i.css("backgroundColor")};"hide"===t.mode&&(s.opacity=0),x.effects.saveStyle(i),i.css({backgroundImage:"none",backgroundColor:t.color||"#ffff99"}).animate(s,{queue:!1,duration:t.duration,easing:t.easing,complete:e})}),x.effects.define("size",function(s,e){var o,i=x(this),t=["fontSize"],n=["borderTopWidth","borderBottomWidth","paddingTop","paddingBottom"],r=["borderLeftWidth","borderRightWidth","paddingLeft","paddingRight"],a=s.mode,l="effect"!==a,h=s.scale||"both",c=s.origin||["middle","center"],u=i.css("position"),p=i.position(),f=x.effects.scaledDimensions(i),d=s.from||f,m=s.to||x.effects.scaledDimensions(i,0);x.effects.createPlaceholder(i),"show"===a&&(a=d,d=m,m=a),o={from:{y:d.height/f.height,x:d.width/f.width},to:{y:m.height/f.height,x:m.width/f.width}},"box"!==h&&"both"!==h||(o.from.y!==o.to.y&&(d=x.effects.setTransition(i,n,o.from.y,d),m=x.effects.setTransition(i,n,o.to.y,m)),o.from.x!==o.to.x&&(d=x.effects.setTransition(i,r,o.from.x,d),m=x.effects.setTransition(i,r,o.to.x,m))),"content"!==h&&"both"!==h||o.from.y!==o.to.y&&(d=x.effects.setTransition(i,t,o.from.y,d),m=x.effects.setTransition(i,t,o.to.y,m)),c&&(a=x.effects.getBaseline(c,f),d.top=(f.outerHeight-d.outerHeight)*a.y+p.top,d.left=(f.outerWidth-d.outerWidth)*a.x+p.left,m.top=(f.outerHeight-m.outerHeight)*a.y+p.top,m.left=(f.outerWidth-m.outerWidth)*a.x+p.left),i.css(d),"content"!==h&&"both"!==h||(n=n.concat(["marginTop","marginBottom"]).concat(t),r=r.concat(["marginLeft","marginRight"]),i.find("*[width]").each(function(){var t=x(this),e=x.effects.scaledDimensions(t),i={height:e.height*o.from.y,width:e.width*o.from.x,outerHeight:e.outerHeight*o.from.y,outerWidth:e.outerWidth*o.from.x},e={height:e.height*o.to.y,width:e.width*o.to.x,outerHeight:e.height*o.to.y,outerWidth:e.width*o.to.x};o.from.y!==o.to.y&&(i=x.effects.setTransition(t,n,o.from.y,i),e=x.effects.setTransition(t,n,o.to.y,e)),o.from.x!==o.to.x&&(i=x.effects.setTransition(t,r,o.from.x,i),e=x.effects.setTransition(t,r,o.to.x,e)),l&&x.effects.saveStyle(t),t.css(i),t.animate(e,s.duration,s.easing,function(){l&&x.effects.restoreStyle(t)})})),i.animate(m,{queue:!1,duration:s.duration,easing:s.easing,complete:function(){var t=i.offset();0===m.opacity&&i.css("opacity",d.opacity),l||(i.css("position","static"===u?"relative":u).offset(t),x.effects.saveStyle(i)),e()}})}),x.effects.define("slide","show",function(t,e){var i,s,o=x(this),n={up:["bottom","top"],down:["top","bottom"],left:["right","left"],right:["left","right"]},r=t.mode,a=t.direction||"left",l="up"===a||"down"===a?"top":"left",h="up"===a||"left"===a,c=t.distance||o["top"==l?"outerHeight":"outerWidth"](!0),u={};x.effects.createPlaceholder(o),i=o.cssClip(),s=o.position()[l],u[l]=(h?-1:1)*c+s,u.clip=o.cssClip(),u.clip[n[a][1]]=u.clip[n[a][0]],"show"===r&&(o.cssClip(u.clip),o.css(l,u[l]),u.clip=i,u[l]=s),o.animate(u,{queue:!1,duration:t.duration,easing:t.easing,complete:e})})}); \ No newline at end of file diff --git a/webroot/js/jquery.imgareaselect-0.8.js b/webroot/js/jquery.imgareaselect-0.8.js deleted file mode 100644 index f925f62..0000000 --- a/webroot/js/jquery.imgareaselect-0.8.js +++ /dev/null @@ -1,635 +0,0 @@ -/* - * imgAreaSelect jQuery plugin - * version 0.8 - * - * Copyright (c) 2008-2009 Michal Wojciechowski (odyniec.net) - * - * Dual licensed under the MIT (MIT-LICENSE.txt) - * and GPL (GPL-LICENSE.txt) licenses. - * - * http://odyniec.net/projects/imgareaselect/ - * - */ - -(function($) { - -$.imgAreaSelect = { onKeyPress: null }; - -$.imgAreaSelect.init = function (img, options) { - var $img = $(img), imgLoaded, $box = $('
    '), $area = $('
    '), - $border1 = $('
    '), $border2 = $('
    '), $areaOpera, - $outLeft = $('
    '), $outTop = $('
    '), - $outRight = $('
    '), $outBottom = $('
    '), - $handles = $([]), handleWidth, handles = [ ], left, top, M = Math, - imgOfs, imgWidth, imgHeight, $parent, parOfs, - zIndex = 0, position = 'absolute', $p, startX, startY, - scaleX = 1, scaleY = 1, resizeMargin = 10, resize = [ ], V = 0, H = 1, - d, aspectRatio, x1, x2, y1, y2, x, y, adjusted, shown, i, - selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 }; - - var $o = $outLeft.add($outTop).add($outRight).add($outBottom); - - function viewX(x) - { - return x + imgOfs.left - parOfs.left; - } - - function viewY(y) - { - return y + imgOfs.top - parOfs.top; - } - - function selX(x) - { - return x - imgOfs.left + parOfs.left; - } - - function selY(y) - { - return y - imgOfs.top + parOfs.top; - } - - function evX(event) - { - return event.pageX - parOfs.left; - } - - function evY(event) - { - return event.pageY - parOfs.top; - } - - function trueSelection() - { - return { x1: M.round(selection.x1 * scaleX), - y1: M.round(selection.y1 * scaleY), - x2: M.round(selection.x2 * scaleX), - y2: M.round(selection.y2 * scaleY), - width: M.round(selection.x2 * scaleX) - M.round(selection.x1 * scaleX), - height: M.round(selection.y2 * scaleY) - M.round(selection.y1 * scaleY) }; - } - - function getZIndex() - { - $p = $img; - - while ($p.length && !$p.is('body')) { - if (!isNaN($p.css('z-index')) && $p.css('z-index') > zIndex) - zIndex = $p.css('z-index'); - if ($p.css('position') == 'fixed') - position = 'fixed'; - - $p = $p.parent(); - } - - if (!isNaN(options.zIndex)) - zIndex = options.zIndex; - } - - function adjust() - { - imgOfs = { left: M.round($img.offset().left), top: M.round($img.offset().top) }; - imgWidth = $img.width(); - imgHeight = $img.height(); - - if ($().jquery == '1.3.2' && $.browser.safari && position == 'fixed') { - imgOfs.top += M.max(document.documentElement.scrollTop, $('body').scrollTop()); - imgOfs.left += M.max(document.documentElement.scrollLeft, $('body').scrollLeft()); - } - - parOfs = $.inArray($parent.css('position'), ['absolute', 'relative']) != -1 ? - { left: M.round($parent.offset().left) - $parent.scrollLeft(), - top: M.round($parent.offset().top) - $parent.scrollTop() } : - position == 'fixed' ? - { left: $(document).scrollLeft(), top: $(document).scrollTop() } : - { left: 0, top: 0 }; - - left = viewX(0); - top = viewY(0); - } - - function update(resetKeyPress) - { - if (!shown) return; - - $box.css({ - left: viewX(selection.x1) + 'px', top: viewY(selection.y1) + 'px', - width: selection.width + 'px', height: selection.height + 'px' - }); - $area.add($border1).add($border2).css({ - left: '0px', top: '0px', - width: M.max(selection.width - options.borderWidth * 2, 0) + 'px', - height: M.max(selection.height - options.borderWidth * 2, 0) + 'px' - }); - $border1.css({ borderStyle: 'solid', borderColor: options.borderColor1 }); - $border2.css({ borderStyle: 'dashed', borderColor: options.borderColor2 }); - $border1.add($border2).css({ opacity: options.borderOpacity }); - $outLeft.css({ left: left + 'px', top: top + 'px', - width: selection.x1 + 'px', height: imgHeight + 'px' }); - $outTop.css({ left: left + selection.x1 + 'px', top: top + 'px', - width: selection.width + 'px', height: selection.y1 + 'px' }); - $outRight.css({ left: left + selection.x2 + 'px', top: top + 'px', - width: imgWidth - selection.x2 + 'px', height: imgHeight + 'px' }); - $outBottom.css({ left: left + selection.x1 + 'px', top: top + selection.y2 + 'px', - width: selection.width + 'px', height: imgHeight - selection.y2 + 'px' }); - - if (handles.length) { - handles[1].css({ left: selection.width - handleWidth + 'px' }); - handles[2].css({ left: selection.width - handleWidth + 'px', - top: selection.height - handleWidth + 'px' }); - handles[3].css({ top: selection.height - handleWidth + 'px' }); - - if (handles.length == 8) { - handles[4].css({ left: (selection.width - handleWidth) / 2 + 'px' }); - handles[5].css({ left: selection.width - handleWidth + 'px', - top: (selection.height - handleWidth) / 2 + 'px' }); - handles[6].css({ left: (selection.width - handleWidth) / 2 + 'px', - top: selection.height - handleWidth + 'px' }); - handles[7].css({ top: (selection.height - handleWidth) / 2 + 'px' }); - } - } - - if (resetKeyPress !== false) { - if ($.imgAreaSelect.keyPress != docKeyPress) - $(document).unbind($.imgAreaSelect.keyPress, - $.imgAreaSelect.onKeyPress); - - if (options.keys) - $(document).bind($.imgAreaSelect.keyPress, - $.imgAreaSelect.onKeyPress = docKeyPress); - } - - if ($.browser.msie && options.borderWidth == 1 && options.borderOpacity < 1) { - $border1.add($border2).css('margin', '0'); - setTimeout(function () { $border1.add($border2).css('margin', 'auto'); }, 0); - } - } - - function areaMouseMove(event) - { - if (!adjusted) { - adjust(); - adjusted = true; - - $box.one('mouseout', function () { adjusted = false; }); - } - - x = selX(evX(event)) - selection.x1; - y = selY(evY(event)) - selection.y1; - - resize = [ ]; - - if (options.resizable) { - if (y <= resizeMargin) - resize[V] = 'n'; - else if (y >= selection.height - resizeMargin) - resize[V] = 's'; - if (x <= resizeMargin) - resize[H] = 'w'; - else if (x >= selection.width - resizeMargin) - resize[H] = 'e'; - } - - $box.css('cursor', resize.length ? resize.join('') + '-resize' : - options.movable ? 'move' : ''); - if ($areaOpera) - $areaOpera.toggle(); - } - - function docMouseUp(event) - { - resize = [ ]; - - $('body').css('cursor', ''); - - if (options.autoHide || selection.width * selection.height == 0) - $box.add($o).hide(); - - options.onSelectEnd(img, trueSelection()); - - $(document).unbind('mousemove', selectingMouseMove); - $box.mousemove(areaMouseMove); - } - - function areaMouseDown(event) - { - if (event.which != 1) return false; - - adjust(); - - if (options.resizable && resize.length > 0) { - $('body').css('cursor', resize.join('') + '-resize'); - - x1 = viewX(selection[resize[H] == 'w' ? 'x2' : 'x1']); - y1 = viewY(selection[resize[V] == 'n' ? 'y2' : 'y1']); - - $(document).mousemove(selectingMouseMove) - .one('mouseup', docMouseUp); - $box.unbind('mousemove', areaMouseMove); - } - else if (options.movable) { - startX = left + selection.x1 - evX(event); - startY = top + selection.y1 - evY(event); - - $box.unbind('mousemove', areaMouseMove); - - $(document).mousemove(movingMouseMove) - .one('mouseup', function () { - options.onSelectEnd(img, trueSelection()); - - $(document).unbind('mousemove', movingMouseMove); - $box.mousemove(areaMouseMove); - }); - } - else - $img.mousedown(event); - - return false; - } - - function aspectRatioXY() - { - x2 = M.max(left, M.min(left + imgWidth, - x1 + M.abs(y2 - y1) * aspectRatio * (x2 < x1 ? -1 : 1))); - y2 = M.round(M.max(top, M.min(top + imgHeight, - y1 + M.abs(x2 - x1) / aspectRatio * (y2 < y1 ? -1 : 1)))); - x2 = M.round(x2); - } - - function aspectRatioYX() - { - y2 = M.max(top, M.min(top + imgHeight, - y1 + M.abs(x2 - x1) / aspectRatio * (y2 < y1 ? -1 : 1))); - x2 = M.round(M.max(left, M.min(left + imgWidth, - x1 + M.abs(y2 - y1) * aspectRatio * (x2 < x1 ? -1 : 1)))); - y2 = M.round(y2); - } - - function doResize() - { - if (options.minWidth && M.abs(x2 - x1) < options.minWidth) { - x2 = x1 - options.minWidth * (x2 < x1 ? 1 : -1); - - if (x2 < left) - x1 = left + options.minWidth; - else if (x2 > left + imgWidth) - x1 = left + imgWidth - options.minWidth; - } - - if (options.minHeight && M.abs(y2 - y1) < options.minHeight) { - y2 = y1 - options.minHeight * (y2 < y1 ? 1 : -1); - - if (y2 < top) - y1 = top + options.minHeight; - else if (y2 > top + imgHeight) - y1 = top + imgHeight - options.minHeight; - } - - x2 = M.max(left, M.min(x2, left + imgWidth)); - y2 = M.max(top, M.min(y2, top + imgHeight)); - - if (aspectRatio) - if (M.abs(x2 - x1) / aspectRatio > M.abs(y2 - y1)) - aspectRatioYX(); - else - aspectRatioXY(); - - if (options.maxWidth && M.abs(x2 - x1) > options.maxWidth) { - x2 = x1 - options.maxWidth * (x2 < x1 ? 1 : -1); - if (aspectRatio) aspectRatioYX(); - } - - if (options.maxHeight && M.abs(y2 - y1) > options.maxHeight) { - y2 = y1 - options.maxHeight * (y2 < y1 ? 1 : -1); - if (aspectRatio) aspectRatioXY(); - } - - selection = { x1: selX(M.min(x1, x2)), x2: selX(M.max(x1, x2)), - y1: selY(M.min(y1, y2)), y2: selY(M.max(y1, y2)), - width: M.abs(x2 - x1), height: M.abs(y2 - y1) }; - - update(); - - options.onSelectChange(img, trueSelection()); - } - - function selectingMouseMove(event) - { - x2 = !resize.length || resize[H] || aspectRatio ? evX(event) : viewX(selection.x2); - y2 = !resize.length || resize[V] || aspectRatio ? evY(event) : viewY(selection.y2); - - doResize(); - - return false; - } - - function doMove(newX1, newY1) - { - x2 = (x1 = newX1) + selection.width; - y2 = (y1 = newY1) + selection.height; - - selection = $.extend(selection, { x1: selX(x1), y1: selY(y1), - x2: selX(x2), y2: selY(y2) }); - - update(); - - options.onSelectChange(img, trueSelection()); - } - - function movingMouseMove(event) - { - x1 = M.max(left, M.min(startX + evX(event), left + imgWidth - selection.width)); - y1 = M.max(top, M.min(startY + evY(event), top + imgHeight - selection.height)); - - doMove(x1, y1); - - event.preventDefault(); - return false; - } - - function startSelection(event) - { - adjust(); - - x2 = x1; - y2 = y1; - doResize(); - - resize = [ ]; - - $box.add($o.is(':visible') ? null : $o).show(); - shown = true; - - $(document).unbind('mouseup', cancelSelection) - .mousemove(selectingMouseMove).one('mouseup', docMouseUp); - $box.unbind('mousemove', areaMouseMove); - - options.onSelectStart(img, trueSelection()); - } - - function cancelSelection() - { - $(document).unbind('mousemove', startSelection); - $box.add($o).hide(); - - selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 }; - - options.onSelectChange(img, selection); - options.onSelectEnd(img, selection); - } - - function imgMouseDown(event) - { - if (event.which != 1) return false; - - adjust(); - startX = x1 = evX(event); - startY = y1 = evY(event); - - $(document).one('mousemove', startSelection) - .one('mouseup', cancelSelection); - - return false; - } - - function parentScroll() - { - adjust(); - update(false); - x1 = viewX(selection.x1); y1 = viewY(selection.y1); - x2 = viewX(selection.x2); y2 = viewY(selection.y2); - } - - function imgLoad() - { - imgLoaded = true; - - if (options.show) { - shown = true; - adjust(); - update(); - $box.add($o).show(); - } - - $box.add($o).css({ visibility: '' }); - } - - var docKeyPress = function(event) { - var k = options.keys, d, t, key = event.keyCode || event.which; - - d = !isNaN(k.alt) && (event.altKey || event.originalEvent.altKey) ? k.alt : - !isNaN(k.ctrl) && event.ctrlKey ? k.ctrl : - !isNaN(k.shift) && event.shiftKey ? k.shift : - !isNaN(k.arrows) ? k.arrows : 10; - - if (k.arrows == 'resize' || (k.shift == 'resize' && event.shiftKey) || - (k.ctrl == 'resize' && event.ctrlKey) || - (k.alt == 'resize' && (event.altKey || event.originalEvent.altKey))) - { - switch (key) { - case 37: - d = -d; - case 39: - t = M.max(x1, x2); - x1 = M.min(x1, x2); - x2 = M.max(t + d, x1); - if (aspectRatio) aspectRatioYX(); - break; - case 38: - d = -d; - case 40: - t = M.max(y1, y2); - y1 = M.min(y1, y2); - y2 = M.max(t + d, y1); - if (aspectRatio) aspectRatioXY(); - break; - default: - return; - } - - doResize(); - } - else { - x1 = M.min(x1, x2); - y1 = M.min(y1, y2); - - switch (key) { - case 37: - doMove(M.max(x1 - d, left), y1); - break; - case 38: - doMove(x1, M.max(y1 - d, top)); - break; - case 39: - doMove(x1 + M.min(d, imgWidth - selX(x2)), y1); - break; - case 40: - doMove(x1, y1 + M.min(d, imgHeight - selY(y2))); - break; - default: - return; - } - } - - return false; - }; - - this.setOptions = function(newOptions) - { - if (newOptions.parent) - ($parent = $(newOptions.parent)).append($box.add($o)); - - adjust(); - getZIndex(); - - if (newOptions.x1 != null) { - selection = { x1: newOptions.x1, y1: newOptions.y1, - x2: newOptions.x2, y2: newOptions.y2 }; - newOptions.show = !newOptions.hide; - - x1 = viewX(selection.x1); y1 = viewY(selection.y1); - x2 = viewX(selection.x2); y2 = viewY(selection.y2); - selection.width = x2 - x1; - selection.height = y2 - y1; - } - - if (newOptions.handles != null) { - $handles.remove(); - $handles = $(handles = [ ]); - - i = newOptions.handles ? newOptions.handles == 'corners' ? 4 : 8 : 0; - - while (i--) - $handles = $handles.add(handles[i] = $('
    ')); - - handleWidth = 4 + options.borderWidth; - - $handles.css({ position: 'absolute', borderWidth: options.borderWidth + 'px', - borderStyle: 'solid', borderColor: options.borderColor1, - opacity: options.borderOpacity, backgroundColor: options.borderColor2, - width: handleWidth + 'px', height: handleWidth + 'px', - fontSize: '0px', zIndex: zIndex > 0 ? zIndex + 1 : '1' }) - .addClass(options.classPrefix + '-handle'); - - handleWidth += options.borderWidth * 2; - } - - update(); - - options = $.extend(options, newOptions); - - if (options.imageWidth || options.imageHeight) { - scaleX = (parseInt(options.imageWidth) || imgWidth) / imgWidth; - scaleY = (parseInt(options.imageHeight) || imgHeight) / imgHeight; - } - - if (newOptions.keys) - options.keys = $.extend({ shift: 1, ctrl: 'resize' }, - newOptions.keys === true ? { } : newOptions.keys); - - $o.addClass(options.classPrefix + '-outer'); - $area.addClass(options.classPrefix + '-selection'); - $border1.addClass(options.classPrefix + '-border1'); - $border2.addClass(options.classPrefix + '-border2'); - - $box.add($area).add($border1).add($border2).css({ borderWidth: options.borderWidth + 'px' }); - $area.css({ backgroundColor: options.selectionColor, opacity: options.selectionOpacity }); - $border1.css({ borderStyle: 'solid', borderColor: options.borderColor1 }); - $border2.css({ borderStyle: 'dashed', borderColor: options.borderColor2 }); - $border1.add($border2).css({ opacity: options.borderOpacity }); - $o.css({ opacity: options.outerOpacity, backgroundColor: options.outerColor }); - - $box.append($area.add($border1).add($border2).add($handles).add($areaOpera)); - - if (newOptions.hide) - $box.add($o).hide(); - else if (newOptions.show && imgLoaded) { - shown = true; - update(); - $box.add($o).show(); - } - - aspectRatio = options.aspectRatio && (d = options.aspectRatio.split(/:/)) ? - d[0] / d[1] : null; - - if (aspectRatio) - if (options.minWidth) - options.minHeight = parseInt(options.minWidth / aspectRatio); - else if (options.minHeight) - options.minWidth = parseInt(options.minHeight * aspectRatio); - - if (options.disable || options.enable === false) { - $box.unbind('mousemove', areaMouseMove).unbind('mousedown', areaMouseDown); - $img.add($o).unbind('mousedown', imgMouseDown); - $(window).unbind('resize', parentScroll); - $img.add($img.parents()).unbind('scroll', parentScroll); - } - else if (options.enable || options.disable === false) { - if (options.resizable || options.movable) - $box.mousemove(areaMouseMove).mousedown(areaMouseDown); - - if (!options.persistent) - $img.add($o).mousedown(imgMouseDown); - $(window).resize(parentScroll); - $img.add($img.parents()).scroll(parentScroll); - } - - options.enable = options.disable = undefined; - }; - - if ($.browser.msie) - $img.attr('unselectable', 'on'); - - $.imgAreaSelect.keyPress = $.browser.msie || - $.browser.safari ? 'keydown' : 'keypress'; - - if ($.browser.opera) - ($areaOpera = $('
    ')) - .css({ zIndex: zIndex > 0 ? zIndex + 2 : '2' }); - - this.setOptions(options = $.extend({ - borderColor1: '#000', - borderColor2: '#fff', - borderWidth: 1, - borderOpacity: .5, - classPrefix: 'imgareaselect', - movable: true, - resizable: true, - selectionColor: '#fff', - selectionOpacity: 0, - outerColor: '#000', - outerOpacity: .4, - parent: 'body', - onSelectStart: function () {}, - onSelectChange: function () {}, - onSelectEnd: function () {} - }, options)); - - $box.add($o).css({ visibility: 'hidden', position: position, - overflow: 'hidden', zIndex: zIndex > 0 ? zIndex : '0' }); - $area.css({ borderStyle: 'solid' }); - $box.css({ position: position, zIndex: zIndex > 0 ? zIndex + 2 : '2' }); - $area.add($border1).add($border2).css({ position: 'absolute' }); - - img.complete || img.readyState == 'complete' || !$img.is('img') ? - imgLoad() : $img.one('load', imgLoad); -}; - -$.fn.imgAreaSelect = function (options) { - options = options || {}; - - this.each(function () { - if ($(this).data('imgAreaSelect')) - $(this).data('imgAreaSelect').setOptions(options); - else { - if (options.enable === undefined && options.disable === undefined) - options.enable = true; - - $(this).data('imgAreaSelect', new $.imgAreaSelect.init(this, options)); - } - }); - - return this; -}; - -})(jQuery); \ No newline at end of file diff --git a/webroot/js/jquery.imgareaselect.js b/webroot/js/jquery.imgareaselect.js new file mode 100644 index 0000000..9280b1d --- /dev/null +++ b/webroot/js/jquery.imgareaselect.js @@ -0,0 +1,1234 @@ +/* + * imgAreaSelect jQuery plugin + * version 1.0.0-rc.1 + * + * Copyright (c) 2008-2013 Michal Wojciechowski (odyniec.net) + * + * Dual licensed under the MIT (http://opensource.org/licenses/MIT) + * and GPL (http://opensource.org/licenses/GPL-2.0) licenses. + * + * http://odyniec.net/projects/imgareaselect/ + * + */ + +(function($) { + + /* + * Math functions will be used extensively, so it's convenient to make a few + * shortcuts + */ + var abs = Math.abs, + max = Math.max, + min = Math.min, + round = Math.round; + + /** + * Create a new HTML div element + * + * @return A jQuery object representing the new element + */ + function div() { + return $('
    '); + } + + /** + * imgAreaSelect initialization + * + * @param img + * A HTML image element to attach the plugin to + * @param options + * An options object + */ + $.imgAreaSelect = function (img, options) { + var + /* jQuery object representing the image */ + $img = $(img), + + /* Has the image finished loading? */ + imgLoaded, + + /* Plugin elements */ + + /* Container box */ + $box = div(), + /* Selection area */ + $area = div(), + /* Border (four divs) */ + $border = div().add(div()).add(div()).add(div()), + /* Outer area */ + $outer = div(), + /* Handles (empty by default, initialized in setOptions()) */ + $handles = $([]), + + /* Image position (relative to viewport) */ + left, top, + + /* Image offset (as returned by .offset()) */ + imgOfs = { left: 0, top: 0 }, + + /* Image dimensions (as returned by .width() and .height()) */ + imgWidth, imgHeight, + + /* + * jQuery object representing the parent element that the plugin + * elements are appended to + */ + $parent, + + /* Parent element offset (as returned by .offset()) */ + parOfs = { left: 0, top: 0 }, + + /* Base z-index for plugin elements */ + zIndex = 0, + + /* Plugin elements position */ + position = 'absolute', + + /* X/Y coordinates of the starting point for move/resize operations */ + startX, startY, + + /* + * Distance between the mouse cursor (or touch point) and selection area + * edges (when resizing) + */ + edgeX, edgeY, + + /* Horizontal and vertical scaling factors */ + scaleX, scaleY, + + /* Current resize mode ("nw", "se", etc.) */ + resize, + + /* Selection area constraints */ + minWidth, minHeight, maxWidth, maxHeight, + + /* Aspect ratio to maintain (floating point number) */ + aspectRatio, + + /* Are the plugin elements currently displayed? */ + shown, + + /* Current selection (relative to parent element) */ + x1, y1, x2, y2, + + /* Current selection (relative to scaled image) */ + selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 }, + + /* User agent */ + ua = navigator.userAgent, + + /* Is the user performing a touch action? */ + touch, + + /* Various helper variables used throughout the code */ + $p, d, i, o, w, h, adjusted; + + /* + * Translate selection coordinates (relative to scaled image) to viewport + * coordinates (relative to parent element) + */ + + /** + * Translate selection X to viewport X + * + * @param x + * Selection X + * @return Viewport X + */ + function viewX(x) { + return x + imgOfs.left - parOfs.left; + } + + /** + * Translate selection Y to viewport Y + * + * @param y + * Selection Y + * @return Viewport Y + */ + function viewY(y) { + return y + imgOfs.top - parOfs.top; + } + + /* + * Translate viewport coordinates to selection coordinates + */ + + /** + * Translate viewport X to selection X + * + * @param x + * Viewport X + * @return Selection X + */ + function selX(x) { + return x - imgOfs.left + parOfs.left; + } + + /** + * Translate viewport Y to selection Y + * + * @param y + * Viewport Y + * @return Selection Y + */ + function selY(y) { + return y - imgOfs.top + parOfs.top; + } + + /* + * Translate event coordinates (relative to document) to viewport + * coordinates + */ + + /** + * Get event X and translate it to viewport X + * + * @param event + * The event object + * @return Viewport X + */ + function evX(event) { + var coords = touchCoords(event) || event, x; + + if (x = parseInt(coords.pageX)) + return x - parOfs.left; + } + + /** + * Get event Y and translate it to viewport Y + * + * @param event + * The event object + * @return Viewport Y + */ + function evY(event) { + var coords = touchCoords(event) || event, y; + + if (y = parseInt(coords.pageY)) + return y - parOfs.top; + } + + /** + * Get the first touch object in an event + * + * @param event + * The event object + * @return The first touch object found in the event object, or false if + * none are found + */ + function touchCoords(event) { + var oev = event.originalEvent || {}; + + return oev.touches && oev.touches.length ? oev.touches[0] : false; + } + + /** + * Get the current selection + * + * @param noScale + * If set to true, scaling is not applied to the + * returned selection + * @return Selection object + */ + function getSelection(noScale) { + var sx = noScale || scaleX, sy = noScale || scaleY; + + return { x1: round(selection.x1 * sx), + y1: round(selection.y1 * sy), + x2: round(selection.x2 * sx) - 1, + y2: round(selection.y2 * sy) - 1, + width: round(selection.x2 * sx) - round(selection.x1 * sx), + height: round(selection.y2 * sy) - round(selection.y1 * sy) }; + } + + /** + * Set the current selection + * + * @param x1 + * X coordinate of the upper left corner of the selection area + * @param y1 + * Y coordinate of the upper left corner of the selection area + * @param x2 + * X coordinate of the lower right corner of the selection area + * @param y2 + * Y coordinate of the lower right corner of the selection area + * @param noScale + * If set to true, scaling is not applied to the + * new selection + */ + function setSelection(x1, y1, x2, y2, noScale) { + var sx = noScale || scaleX, sy = noScale || scaleY; + + selection = { + x1: round(x1 / sx || 0), + y1: round(y1 / sy || 0), + x2: round(++x2 / sx || 0), + y2: round(++y2 / sy || 0) + }; + + selection.width = selection.x2 - selection.x1; + selection.height = selection.y2 - selection.y1; + } + + /** + * Recalculate image and parent offsets + */ + function adjust() { + /* + * Do not adjust if image has not yet loaded or if width is not a + * positive number. The latter might happen when imgAreaSelect is put + * on a parent element which is then hidden. + */ + if (!imgLoaded || !$img.width()) + return; + + /* + * Get image offset. The .offset() method returns float values, so they + * need to be rounded. + */ + imgOfs = { left: round($img.offset().left), top: round($img.offset().top) }; + + /* Get image dimensions */ + imgWidth = $img.innerWidth(); + imgHeight = $img.innerHeight(); + + imgOfs.top += ($img.outerHeight() - imgHeight) >> 1; + imgOfs.left += ($img.outerWidth() - imgWidth) >> 1; + + /* Set minimum and maximum selection area dimensions */ + minWidth = round(options.minWidth / scaleX) || 0; + minHeight = round(options.minHeight / scaleY) || 0; + maxWidth = round(min(options.maxWidth / scaleX || 1<<24, imgWidth)); + maxHeight = round(min(options.maxHeight / scaleY || 1<<24, imgHeight)); + + /* Determine parent element offset */ + parOfs = position == 'fixed' ? + /* Plugin elements position set to fixed */ + { left: $(document).scrollLeft(), top: $(document).scrollTop() } : + /* Check parent element position */ + /static|^$/.test($parent.css('position')) ? + /* Static */ + { left: 0, top: 0 } : + /* Absolute or relative */ + { left: round($parent.offset().left) - $parent.scrollLeft(), + top: round($parent.offset().top) - $parent.scrollTop() }; + + left = viewX(0); + top = viewY(0); + + /* + * Check if selection area is within image boundaries, adjust if + * necessary + */ + if (selection.x2 > imgWidth || selection.y2 > imgHeight) + fixAreaCoords(); + } + + /** + * Update plugin elements + * + * @param resetKeyPress + * If set to false, this instance's keypress + * event handler is not activated + */ + function update(resetKeyPress) { + /* If plugin elements are hidden, do nothing */ + if (!shown) return; + + /* + * Set the position and size of the container box and the selection area + * inside it + */ + $box.css({ left: viewX(selection.x1), top: viewY(selection.y1) }) + .add($area).width(w = selection.width).height(h = selection.height); + + /* + * Reset the position of selection area, borders, and handles (IE6/IE7 + * position them incorrectly if we don't do this) + */ + $area.add($border).add($handles).css({ left: 0, top: 0 }); + + /* Set border dimensions */ + $border.add($outer) + .width(max(w - $border.outerWidth() + $border.innerWidth(), 0)) + .height(max(h - $border.outerHeight() + $border.innerHeight(), 0)); + + /* Set the dimensions and border styles of the outer area */ + $outer.css({ + left: left, + top: top, + width: w, + height: h, + borderStyle: 'solid', + borderWidth: selection.y1 + 'px ' + + (imgWidth - selection.x2) + 'px ' + (imgHeight - selection.y2) + + 'px ' + selection.x1 + 'px' + }); + + w -= $handles.outerWidth(); + h -= $handles.outerHeight(); + + /* Arrange handles */ + switch ($handles.length) { + case 8: + $($handles[4]).css({ left: w >> 1 }); + $($handles[5]).css({ left: w, top: h >> 1 }); + $($handles[6]).css({ left: w >> 1, top: h }); + $($handles[7]).css({ top: h >> 1 }); + case 4: + $handles.slice(1,3).css({ left: w }); + $handles.slice(2,4).css({ top: h }); + } + + if (resetKeyPress !== false) { + /* + * Need to reset the document keypress event handler -- unbind the + * current handler + */ + if ($.imgAreaSelect.keyPress != docKeyPress) + $(document).unbind($.imgAreaSelect.keyPress, + $.imgAreaSelect.onKeyPress); + + if (options.keys) + /* + * Set the document keypress event handler to this instance's + * docKeyPress() function + */ + $(document)[$.imgAreaSelect.keyPress]( + $.imgAreaSelect.onKeyPress = docKeyPress); + } + } + + /** + * Do the complete update sequence: recalculate offsets, update the + * elements, and set the correct values of x1, y1, x2, and y2. + * + * @param resetKeyPress + * If set to false, this instance's keypress + * event handler is not activated + */ + function doUpdate(resetKeyPress) { + adjust(); + update(resetKeyPress); + x1 = viewX(selection.x1); y1 = viewY(selection.y1); + x2 = viewX(selection.x2); y2 = viewY(selection.y2); + } + + /** + * Hide or fade out an element (or multiple elements) + * + * @param $elem + * A jQuery object containing the element(s) to hide/fade out + * @param fn + * Callback function to be called when fadeOut() completes + */ + function hide($elem, fn) { + options.fadeDuration ? $elem.fadeOut(options.fadeDuration, fn) : $elem.hide(); + } + + /** + * Check if a touch event is expected and if the passed event object really + * is a touch event + * + * @param event + * The event object + * @return True if the event handler should be interrupted + */ + function breakWhenNoTouch(event) { + return touch && !/^touch/.test(event.type); + } + + /** + * Check event coordinates to determine if the selection area should be + * resized or moved + * + * @param event + * The event object + */ + function checkResize(event) { + var x = selX(evX(event)) - selection.x1, + y = selY(evY(event)) - selection.y1; + + /* Clear the resize mode */ + resize = ''; + + if (options.resizable) { + /* + * Check if the mouse pointer is over the resize margin area and set + * the resize mode accordingly + */ + if (y <= options.resizeMargin) + resize = 'n'; + else if (y >= selection.height - options.resizeMargin) + resize = 's'; + if (x <= options.resizeMargin) + resize += 'w'; + else if (x >= selection.width - options.resizeMargin) + resize += 'e'; + } + + $box.css('cursor', resize ? resize + '-resize' : + options.movable ? 'move' : ''); + } + + /** + * Selection area mousemove event handler + * + * @param event + * The event object + */ + function areaMouseMove(event) { + if (breakWhenNoTouch(event)) + return; + + if (!adjusted) { + adjust(); + adjusted = true; + + $box.one('mouseout', function () { adjusted = false; }); + } + + checkResize(event); + } + + /** + * Document mouseup event handler + * + * @param event + * The event object + */ + function docMouseUp(event) { + /* Reset touch action flag */ + touch = false; + /* Set back the default cursor */ + $('body').css('cursor', ''); + /* + * If autoHide is enabled, or if the selection has zero width/height, + * hide the selection and the outer area + */ + if (options.autoHide || selection.width * selection.height == 0) + hide($box.add($outer), function () { $(this).hide(); }); + + $(document).off('mousemove touchmove', selectingMouseMove); + $box.on('mousemove touchmove', areaMouseMove); + + /* + * If docMouseUp() is called by areaMouseDown() to work around the issue + * with Android Chrome, there is no event object, and we don't want to + * run the onSelectEnd callback function. + */ + if (event) + options.onSelectEnd(img, getSelection()); + } + + /** + * Selection area mousedown event handler + * + * @param event + * The event object + * @return false + */ + function areaMouseDown(event) { + if (event.type == 'mousedown' && event.which != 1) return false; + + if (event.type == 'touchstart') { + /* + * Android Chrome often does not produce a touchend event + * (https://code.google.com/p/chromium/issues/detail?id=152913), so + * if it appears that the touch flag is still set, we call the + * mouseup/touchend event handler to clean up after the previous + * touch action. + */ + if (touch) + docMouseUp(); + + /* This is a start of a touch action */ + touch = true; + + /* + * Normally, checkResize() is called by the mousemove event handler + * triggered just before mousedown, but with a touch action there + * is no mousemove, so we need to call it explicitly. + */ + checkResize(event); + } + else + adjust(); + + if (resize) { + /* Resize mode is in effect */ + + /* + * Set (x1, y1) to the fixed corner of the selection area, and (x2, + * y2) to the corner that's being moved. + */ + x1 = viewX(selection['x' + (1 + /w/.test(resize))]); + y1 = viewY(selection['y' + (1 + /n/.test(resize))]); + x2 = viewX(selection['x' + (1 + !/w/.test(resize))]); + y2 = viewY(selection['y' + (1 + !/n/.test(resize))]); + + edgeX = x2 - evX(event); + edgeY = y2 - evY(event); + + $(document).on('mousemove touchmove', selectingMouseMove) + .one('mouseup touchend', docMouseUp); + $box.off('mousemove touchmove', areaMouseMove); + } + else if (options.movable) { + startX = left + selection.x1 - evX(event); + startY = top + selection.y1 - evY(event); + + $box.off('mousemove touchmove', areaMouseMove); + + $(document).on('mousemove touchmove', movingMouseMove) + .one('mouseup touchend', function () { + touch = false; + options.onSelectEnd(img, getSelection()); + + $(document).off('mousemove touchmove', movingMouseMove); + $box.on('mousemove touchmove', areaMouseMove); + }); + } + else + $img.mousedown(event); + + return false; + } + + /** + * Adjust the x2/y2 coordinates to maintain aspect ratio (if defined) + * + * @param xFirst + * If set to true, calculate x2 first. Otherwise, + * calculate y2 first. + */ + function fixAspectRatio(xFirst) { + if (aspectRatio) + if (xFirst) { + x2 = max(left, min(left + imgWidth, + x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1))); + y2 = round(max(top, min(top + imgHeight, + y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1)))); + x2 = round(x2); + } + else { + y2 = max(top, min(top + imgHeight, + y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1))); + x2 = round(max(left, min(left + imgWidth, + x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1)))); + y2 = round(y2); + } + } + + /** + * Check if the coordinates of the selection area are within the required + * limits and conform to the aspect ratio; adjust if necessary + */ + function fixAreaCoords() { + /* + * Make sure the top left corner of the selection area stays within + * image boundaries (it might not if the image source was dynamically + * changed). + */ + x1 = min(x1, left + imgWidth); + y1 = min(y1, top + imgHeight); + + if (abs(x2 - x1) < minWidth) { + /* Selection width is smaller than minWidth */ + x2 = x1 - minWidth * (x2 < x1 || -1); + + if (x2 < left) + x1 = left + minWidth; + else if (x2 > left + imgWidth) + x1 = left + imgWidth - minWidth; + } + + if (abs(y2 - y1) < minHeight) { + /* Selection height is smaller than minHeight */ + y2 = y1 - minHeight * (y2 < y1 || -1); + + if (y2 < top) + y1 = top + minHeight; + else if (y2 > top + imgHeight) + y1 = top + imgHeight - minHeight; + } + + x2 = max(left, min(x2, left + imgWidth)); + y2 = max(top, min(y2, top + imgHeight)); + + fixAspectRatio(abs(x2 - x1) < abs(y2 - y1) * aspectRatio); + + if (abs(x2 - x1) > maxWidth) { + /* Selection width is greater than maxWidth */ + x2 = x1 - maxWidth * (x2 < x1 || -1); + fixAspectRatio(); + } + + if (abs(y2 - y1) > maxHeight) { + /* Selection height is greater than maxHeight */ + y2 = y1 - maxHeight * (y2 < y1 || -1); + fixAspectRatio(true); + } + + selection = { x1: selX(min(x1, x2)), x2: selX(max(x1, x2)), + y1: selY(min(y1, y2)), y2: selY(max(y1, y2)), + width: abs(x2 - x1), height: abs(y2 - y1) }; + } + + /** + * Resize the selection area respecting the minimum/maximum dimensions and + * aspect ratio + */ + function doResize() { + fixAreaCoords(); + + update(); + + options.onSelectChange(img, getSelection()); + } + + /** + * Mousemove event handler triggered when the user is selecting an area + * + * @param event + * The event object + * @return false + */ + function selectingMouseMove(event) { + if (breakWhenNoTouch(event)) + return; + + fixAreaCoords(); + + x2 = /w|e|^$/.test(resize) || aspectRatio ? evX(event) + edgeX : viewX(selection.x2); + y2 = /n|s|^$/.test(resize) || aspectRatio ? evY(event) + edgeY : viewY(selection.y2); + + doResize(); + + return false; + } + + /** + * Move the selection area + * + * @param newX1 + * New viewport X1 + * @param newY1 + * New viewport Y1 + */ + function doMove(newX1, newY1) { + x2 = (x1 = newX1) + selection.width; + y2 = (y1 = newY1) + selection.height; + + $.extend(selection, { x1: selX(x1), y1: selY(y1), x2: selX(x2), + y2: selY(y2) }); + + update(); + + options.onSelectChange(img, getSelection()); + } + + /** + * Mousemove event handler triggered when the selection area is being moved + * + * @param event + * The event object + * @return false + */ + function movingMouseMove(event) { + if (breakWhenNoTouch(event)) + return; + + x1 = max(left, min(startX + evX(event), left + imgWidth - selection.width)); + y1 = max(top, min(startY + evY(event), top + imgHeight - selection.height)); + + doMove(x1, y1); + + event.preventDefault(); + return false; + } + + /** + * Start selection + */ + function startSelection() { + $(document).off('mousemove touchmove', startSelection); + adjust(); + + x2 = x1; + y2 = y1; + doResize(); + + resize = ''; + + if (!$outer.is(':visible')) + /* Show the plugin elements */ + $box.add($outer).hide().fadeIn(options.fadeDuration||0) + + shown = true; + + $(document).off('mouseup touchend', cancelSelection) + .on('mousemove touchmove', selectingMouseMove) + .one('mouseup touchend', docMouseUp); + $box.off('mousemove touchmove', areaMouseMove); + + options.onSelectStart(img, getSelection()); + } + + /** + * Cancel selection + */ + function cancelSelection() { + $(document).off('mousemove touchmove', startSelection) + .off('mouseup touchend', cancelSelection); + hide($box.add($outer)); + + setSelection(selX(x1), selY(y1), selX(x1), selY(y1)); + + /* If this is an API call, callback functions should not be triggered */ + if (!(this instanceof $.imgAreaSelect)) { + options.onSelectChange(img, getSelection()); + options.onSelectEnd(img, getSelection()); + } + } + + /** + * Image mousedown event handler + * + * @param event + * The event object + * @return false + */ + function imgMouseDown(event) { + /* Ignore the event if animation is in progress */ + if (event.type == 'mousedown' && event.which != 1 || + $outer.is(':animated')) + return false; + + /* If it's a touch action, set the touch flag */ + touch = event.type == 'touchstart'; + + adjust(); + startX = x1 = evX(event); + startY = y1 = evY(event); + edgeX = edgeY = 0; + + /* Selection will start when the mouse is moved */ + $(document).on({ 'mousemove touchmove': startSelection, + 'mouseup touchend': cancelSelection }); + + return false; + } + + /** + * Window resize event handler + */ + function windowResize() { + doUpdate(false); + } + + /** + * Image load event handler. This is the final part of the initialization + * process. + */ + function imgLoad() { + imgLoaded = true; + + /* Set options */ + setOptions(options = $.extend({ + classPrefix: 'imgareaselect', + movable: true, + parent: 'body', + resizable: true, + resizeMargin: 10, + onInit: function () {}, + onSelectStart: function () {}, + onSelectChange: function () {}, + onSelectEnd: function () {} + }, options)); + + if (options.show) { + shown = true; + adjust(); + update(); + $box.add($outer).hide().fadeIn(options.fadeDuration||0) + } + + /* + * Call the onInit callback. The setTimeout() call is used to ensure + * that the plugin has been fully initialized and the object instance is + * available (so that it can be obtained in the callback). + */ + setTimeout(function () { options.onInit(img, getSelection()); }, 0); + } + + /** + * Document keypress event handler + * + * @param event + * The event object + * @return false + */ + var docKeyPress = function(event) { + var k = options.keys, d, t, key = event.keyCode; + + d = !isNaN(k.alt) && (event.altKey || event.originalEvent.altKey) ? k.alt : + !isNaN(k.ctrl) && event.ctrlKey ? k.ctrl : + !isNaN(k.shift) && event.shiftKey ? k.shift : + !isNaN(k.arrows) ? k.arrows : 10; + + if (k.arrows == 'resize' || (k.shift == 'resize' && event.shiftKey) || + (k.ctrl == 'resize' && event.ctrlKey) || + (k.alt == 'resize' && (event.altKey || event.originalEvent.altKey))) + { + /* Resize selection */ + + switch (key) { + case 37: + /* Left */ + d = -d; + case 39: + /* Right */ + t = max(x1, x2); + x1 = min(x1, x2); + x2 = max(t + d, x1); + fixAspectRatio(); + break; + case 38: + /* Up */ + d = -d; + case 40: + /* Down */ + t = max(y1, y2); + y1 = min(y1, y2); + y2 = max(t + d, y1); + fixAspectRatio(true); + break; + default: + return; + } + + doResize(); + } + else { + /* Move selection */ + + x1 = min(x1, x2); + y1 = min(y1, y2); + + switch (key) { + case 37: + /* Left */ + doMove(max(x1 - d, left), y1); + break; + case 38: + /* Up */ + doMove(x1, max(y1 - d, top)); + break; + case 39: + /* Right */ + doMove(x1 + min(d, imgWidth - selX(x2)), y1); + break; + case 40: + /* Down */ + doMove(x1, y1 + min(d, imgHeight - selY(y2))); + break; + default: + return; + } + } + + return false; + }; + + /** + * Set plugin options + * + * @param newOptions + * The new options object + */ + function setOptions(newOptions) { + if (newOptions.parent) + ($parent = $(newOptions.parent)).append($box).append($outer); + + /* Merge the new options with the existing ones */ + $.extend(options, newOptions); + + adjust(); + + if (newOptions.handles != null) { + /* Recreate selection area handles */ + $handles.remove(); + $handles = $([]); + + i = newOptions.handles ? newOptions.handles == 'corners' ? 4 : 8 : 0; + + while (i--) + $handles = $handles.add(div()); + + /* Add a class to handles and set the CSS properties */ + $handles.addClass(options.classPrefix + '-handle').css({ + position: 'absolute', + /* + * The font-size property needs to be set to zero, otherwise + * Internet Explorer makes the handles too large + */ + fontSize: 0, + zIndex: zIndex + 1 || 1 + }); + + /* + * If handle width/height has not been set with CSS rules, set the + * default 5px + */ + if (!parseInt($handles.css('width')) >= 0) + $handles.width(5).height(5); + } + + /* Calculate scale factors */ + scaleX = options.imageWidth / imgWidth || 1; + scaleY = options.imageHeight / imgHeight || 1; + + /* Set selection */ + if (newOptions.x1 != null) { + setSelection(newOptions.x1, newOptions.y1, newOptions.x2, + newOptions.y2); + newOptions.show = !newOptions.hide; + } + + if (newOptions.keys) + /* Enable keyboard support */ + options.keys = $.extend({ shift: 1, ctrl: 'resize' }, + newOptions.keys); + + /* Add classes to plugin elements */ + $outer.addClass(options.classPrefix + '-outer'); + $outer.css('opacity', '0.8'); + $area.addClass(options.classPrefix + '-selection'); + for (i = 0; i++ < 4;) + $($border[i-1]).addClass(options.classPrefix + '-border' + i); + + /* Append all the selection area elements to the container box */ + $box.append($area.add($border)).append($handles); + + if (msie) { + if (o = ($outer.css('filter')||'').match(/opacity=(\d+)/)) + $outer.css('opacity', o[1]/100); + if (o = ($border.css('filter')||'').match(/opacity=(\d+)/)) + $border.css('opacity', o[1]/100); + } + + if (newOptions.hide) + hide($box.add($outer)); + else if (newOptions.show && imgLoaded) { + shown = true; + $box.add($outer).fadeIn(options.fadeDuration||0) + doUpdate(); + } + + /* Calculate the aspect ratio factor */ + aspectRatio = (d = (options.aspectRatio || '').split(/:/))[0] / d[1]; + + $img.add($outer).off('mousedown touchstart', imgMouseDown); + + if (options.disable || options.enable === false) { + /* Disable the plugin */ + $box.off({ 'mousemove touchmove': areaMouseMove, + 'mousedown touchstart': areaMouseDown }); + $(window).off('resize', windowResize); + } + else { + if (options.enable || options.disable === false) { + /* Enable the plugin */ + if (options.resizable || options.movable) + $box.on({ 'mousemove touchmove': areaMouseMove, + 'mousedown touchstart': areaMouseDown }); + + $(window).resize(windowResize); + } + + if (!options.persistent) + $img.add($outer).on('mousedown touchstart', imgMouseDown); + } + + options.enable = options.disable = undefined; + } + + /** + * Remove plugin completely + */ + this.remove = function () { + /* + * Call setOptions with { disable: true } to unbind the event handlers + */ + setOptions({ disable: true }); + $box.add($outer).remove(); + }; + + /* + * Public API + */ + + /** + * Get current options + * + * @return An object containing the set of options currently in use + */ + this.getOptions = function () { return options; }; + + /** + * Set plugin options + * + * @param newOptions + * The new options object + */ + this.setOptions = setOptions; + + /** + * Get the current selection + * + * @param noScale + * If set to true, scaling is not applied to the + * returned selection + * @return Selection object + */ + this.getSelection = getSelection; + + /** + * Set the current selection + * + * @param x1 + * X coordinate of the upper left corner of the selection area + * @param y1 + * Y coordinate of the upper left corner of the selection area + * @param x2 + * X coordinate of the lower right corner of the selection area + * @param y2 + * Y coordinate of the lower right corner of the selection area + * @param noScale + * If set to true, scaling is not applied to the + * new selection + */ + this.setSelection = setSelection; + + /** + * Cancel selection + */ + this.cancelSelection = cancelSelection; + + /** + * Update plugin elements + * + * @param resetKeyPress + * If set to false, this instance's keypress + * event handler is not activated + */ + this.update = doUpdate; + + /* Do the dreaded browser detection */ + var msie = (/msie ([\w.]+)/i.exec(ua)||[])[1], + safari = /webkit/i.test(ua) && !/chrome/i.test(ua); + + /* + * Traverse the image's parent elements (up to ) and find the + * highest z-index + */ + $p = $img; + + while ($p.length) { + zIndex = max(zIndex, + !isNaN($p.css('z-index')) ? $p.css('z-index') : zIndex); + /* + * If the parent element is not set explicitly, check if any of the + * ancestor elements has fixed position + */ + if (!options.parent && $p.css('position') == 'fixed') + position = 'fixed'; + + $p = $p.parent(':not(body)'); + } + + /* + * If z-index is given as an option, it overrides the one found by the + * above loop + */ + zIndex = options.zIndex || zIndex; + + /* + * In MSIE and WebKit, we need to use the keydown event instead of keypress + */ + $.imgAreaSelect.keyPress = msie || safari ? 'keydown' : 'keypress'; + + $box.add($outer).hide().css({ position: position, overflow: 'hidden', + zIndex: zIndex || '0' }); + $box.css({ zIndex: zIndex + 2 || 2 }); + $area.add($border).css({ position: 'absolute', fontSize: 0 }); + + /* + * If the image has been fully loaded, or if it is not really an image (eg. + * a div), call imgLoad() immediately; otherwise, bind it to be called once + * on image load event. + */ + img.complete || img.readyState == 'complete' || !$img.is('img') ? + imgLoad() : $img.one('load', imgLoad); + + /* + * MSIE 9.0 doesn't always fire the image load event -- resetting the src + * attribute seems to trigger it. The check is for version 7 and above to + * accommodate for MSIE 9 running in compatibility mode. + */ + if (!imgLoaded && msie && msie >= 7) + img.src = img.src; + }; + + /** + * Invoke imgAreaSelect on a jQuery object containing the image(s) + * + * @param options + * Options object + * @return The jQuery object or a reference to imgAreaSelect instance (if the + * instance option was specified) + */ + $.fn.imgAreaSelect = function (options) { + options = options || {}; + + this.each(function () { + /* Is there already an imgAreaSelect instance bound to this element? */ + if ($(this).data('imgAreaSelect')) { + /* Yes there is -- is it supposed to be removed? */ + if (options.remove) { + /* Remove the plugin */ + $(this).data('imgAreaSelect').remove(); + $(this).removeData('imgAreaSelect'); + } + else + /* Reset options */ + $(this).data('imgAreaSelect').setOptions(options); + } + else if (!options.remove) { + /* No exising instance -- create a new one */ + + /* + * If neither the "enable" nor the "disable" option is present, add + * "enable" as the default + */ + if (options.enable === undefined && options.disable === undefined) + options.enable = true; + + $(this).data('imgAreaSelect', new $.imgAreaSelect(this, options)); + } + }); + + if (options.instance) + /* + * Return the imgAreaSelect instance bound to the first element in the + * set + */ + return $(this).data('imgAreaSelect'); + + return this; + }; + + })(jQuery); + \ No newline at end of file diff --git a/webroot/js/jquery.imgnotes-0.2.js b/webroot/js/jquery.imgnotes-0.2.js index 477b75e..854f2ac 100644 --- a/webroot/js/jquery.imgnotes-0.2.js +++ b/webroot/js/jquery.imgnotes-0.2.js @@ -23,8 +23,6 @@ $.extend(options, o); } - console.log(options); - if(typeof options.notes != "undefined"){ notes = options.notes; }